I think the function 'collect_submodules' from PyInstaller.hooks.hookutils could do this trick for you or be helpful for you.