From 3f5964fcb90ec6eb6df46d78e651a1b73538d0ba Mon Sep 17 00:00:00 2001 From: adeadfed Date: Tue, 14 Mar 2023 21:14:19 +0100 Subject: [PATCH] fix name resolution for local packages --- pipreqs/pipreqs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 0ceb402..4195a75 100644 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -229,7 +229,8 @@ def get_import_local(imports, encoding=None): result = [] for item in imports: if item.lower() in local: - result.append(local[item.lower()]) + # append to result a matching package, as well as its exported modules + result.append(dict(**local[item.lower()], exports=item.lower())) # removing duplicates of package/version result_unique = [ @@ -443,9 +444,12 @@ def init(args): else: logging.debug("Getting packages information from Local/PyPI") local = get_import_local(candidates, encoding=encoding) + # Get packages that were not found locally - difference = [x for x in candidates - if x.lower() not in [z['name'].lower() for z in local]] + difference = [x for x in candidates + # check if candidate name is found in the list of exported modules, installed locally + if x.lower() not in [y['exports'] for y in local]] + imports = local + get_imports_info(difference, proxy=proxy, pypi_server=pypi_server)