fix(pipreqs): Walk through all sys.path instead of only get_python_lib()

This commit is contained in:
Vadim Kravcenko 2015-05-11 23:05:47 +02:00
parent f3011d6487
commit f3ec4d5d2a

View File

@ -88,18 +88,20 @@ def get_imports_info(imports):
def get_locally_installed_packages(): def get_locally_installed_packages():
packages = {} packages = {}
for root, dirs, files in os.walk(get_python_lib()): ignore = ["tests", "_tests", "egg", "EGG", "info"]
for item in files: for path in sys.path:
if "top_level" in item: for root, dirs, files in os.walk(path):
with open(os.path.join(root, item), "r") as f: for item in files:
package = root.split("/")[-1].split("-") if "top_level" in item:
package_import = f.read().strip().split("\n") with open(os.path.join(root, item), "r") as f:
for item in package_import: package = root.split("/")[-1].split("-")
if item not in ["tests", "_tests"]: package_import = f.read().strip().split("\n")
packages[item] = { for item in package_import:
'version': package[1].replace(".dist", ""), if item not in ignore and package[0] not in ignore:
'name': package[0] packages[item] = {
} 'version': package[1].replace(".dist", ""),
'name': package[0]
}
return packages return packages