Created
July 31, 2019 06:30
-
-
Save EtsuNDmA/b4884278a445ca0e5408d7ee20af38fd to your computer and use it in GitHub Desktop.
Find all package directories in given paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_package_dirs(paths): | |
"""Find all package directories in given paths""" | |
dirs = [] | |
for importer, modname, ispkg in pkgutil.iter_modules(paths): | |
module_loader = importer.find_module(modname) | |
if ispkg: | |
yield module_loader.filename | |
# tmpdir is pytest fixture | |
def test_find_package_dirs(tmpdir): | |
tmpdir.mkdir('foo_package').join('__init__.py').write('', mode='w') | |
paths_for_search = [str(tmpdir)] | |
dirs = find_package_dirs(paths_for_search) | |
assert len(dirs) == 1 | |
assert py.path.local(dirs[0]).basename == 'foo_package' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment