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,14 +88,16 @@ 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 path in sys.path:
for root, dirs, files in os.walk(path):
for item in files: for item in files:
if "top_level" in item: if "top_level" in item:
with open(os.path.join(root, item), "r") as f: with open(os.path.join(root, item), "r") as f:
package = root.split("/")[-1].split("-") package = root.split("/")[-1].split("-")
package_import = f.read().strip().split("\n") package_import = f.read().strip().split("\n")
for item in package_import: for item in package_import:
if item not in ["tests", "_tests"]: if item not in ignore and package[0] not in ignore:
packages[item] = { packages[item] = {
'version': package[1].replace(".dist", ""), 'version': package[1].replace(".dist", ""),
'name': package[0] 'name': package[0]