mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +00:00
Merge c11c2188d49c06a391f33a6cdbb553bcdefb237f into e5493d922e7d4a204c92d13d621dbaba084555db
This commit is contained in:
commit
9f5124379d
@ -194,10 +194,10 @@ def get_imports_info(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_locally_installed_packages(encoding=None):
|
def get_locally_installed_packages(search_path, encoding=None):
|
||||||
packages = {}
|
packages = {}
|
||||||
ignore = ["tests", "_tests", "egg", "EGG", "info"]
|
ignore = ["tests", "_tests", "egg", "EGG", "info"]
|
||||||
for path in sys.path:
|
for path in search_path:
|
||||||
for root, dirs, files in os.walk(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:
|
||||||
@ -224,8 +224,8 @@ def get_locally_installed_packages(encoding=None):
|
|||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|
||||||
def get_import_local(imports, encoding=None):
|
def get_import_local(search_path, imports, encoding=None):
|
||||||
local = get_locally_installed_packages()
|
local = get_locally_installed_packages(search_path)
|
||||||
result = []
|
result = []
|
||||||
for item in imports:
|
for item in imports:
|
||||||
if item.lower() in local:
|
if item.lower() in local:
|
||||||
@ -408,6 +408,11 @@ def init(args):
|
|||||||
input_path = args['<path>']
|
input_path = args['<path>']
|
||||||
if input_path is None:
|
if input_path is None:
|
||||||
input_path = os.path.abspath(os.curdir)
|
input_path = os.path.abspath(os.curdir)
|
||||||
|
search_path = sys.path
|
||||||
|
else:
|
||||||
|
search_path = sys.path
|
||||||
|
search_path.remove(os.path.abspath(os.curdir))
|
||||||
|
search_path.append(os.path.abspath(input_path))
|
||||||
|
|
||||||
if extra_ignore_dirs:
|
if extra_ignore_dirs:
|
||||||
extra_ignore_dirs = extra_ignore_dirs.split(',')
|
extra_ignore_dirs = extra_ignore_dirs.split(',')
|
||||||
@ -439,10 +444,10 @@ def init(args):
|
|||||||
if args["--use-local"]:
|
if args["--use-local"]:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Getting package information ONLY from local installation.")
|
"Getting package information ONLY from local installation.")
|
||||||
imports = get_import_local(candidates, encoding=encoding)
|
imports = get_import_local(search_path, candidates, encoding=encoding)
|
||||||
else:
|
else:
|
||||||
logging.debug("Getting packages information from Local/PyPI")
|
logging.debug("Getting packages information from Local/PyPI")
|
||||||
local = get_import_local(candidates, encoding=encoding)
|
local = get_import_local(search_path, candidates, encoding=encoding)
|
||||||
# Get packages that were not found locally
|
# Get packages that were not found locally
|
||||||
difference = [x for x in candidates
|
difference = [x for x in candidates
|
||||||
if x.lower() not in [z['name'].lower() for z in local]]
|
if x.lower() not in [z['name'].lower() for z in local]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user