mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +00:00
Merge 2971861bacb3f2212ed5e85eba4b526051eefb03 into e5493d922e7d4a204c92d13d621dbaba084555db
This commit is contained in:
commit
f1ce43a09d
@ -186,9 +186,15 @@ def get_imports_info(
|
|||||||
elif response.status_code >= 300:
|
elif response.status_code >= 300:
|
||||||
raise HTTPError(status_code=response.status_code,
|
raise HTTPError(status_code=response.status_code,
|
||||||
reason=response.reason)
|
reason=response.reason)
|
||||||
except HTTPError:
|
except HTTPError as err:
|
||||||
logging.debug(
|
if err.errno == 404:
|
||||||
'Package %s does not exist or network problems', item)
|
msg = "Package `%s` isn't on pypi, skipping"
|
||||||
|
logging.warning(msg, item)
|
||||||
|
msg = "(possible missing mapping for import name `%s`?)"
|
||||||
|
logging.warning(msg, item)
|
||||||
|
else:
|
||||||
|
msg = "HTTP error %s querying package %s, skipping"
|
||||||
|
logging.warning(msg, err.errno, item)
|
||||||
continue
|
continue
|
||||||
result.append({'name': item, 'version': data.latest_release_id})
|
result.append({'name': item, 'version': data.latest_release_id})
|
||||||
return result
|
return result
|
||||||
@ -252,16 +258,26 @@ def get_pkg_names(pkgs):
|
|||||||
List[str]: The corresponding PyPI package names.
|
List[str]: The corresponding PyPI package names.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
result = set()
|
mapfile = join("mapping")
|
||||||
|
logging.debug("Looking up mappings in %s", mapfile)
|
||||||
with open(join("mapping"), "r") as f:
|
with open(join("mapping"), "r") as f:
|
||||||
data = dict(x.strip().split(":") for x in f)
|
mappings = dict(x.strip().split(":") for x in f)
|
||||||
for pkg in pkgs:
|
|
||||||
# Look up the mapped requirement. If a mapping isn't found,
|
# Look up the mapped requirement. If a mapping isn't found,
|
||||||
# simply use the package name.
|
# simply use the package name.
|
||||||
result.add(data.get(pkg, pkg))
|
names = {pkg: mappings.get(pkg, pkg)
|
||||||
# Return a sorted list for backward compatibility.
|
for pkg in pkgs}
|
||||||
return sorted(result, key=lambda s: s.lower())
|
|
||||||
|
|
||||||
|
# Print mappings to debug logger
|
||||||
|
pkgalign = max(len(s) for s in names.keys())
|
||||||
|
reqalign = max(len(s) for s in names.values())
|
||||||
|
fmt = "[%-{}s] : %-{}s (%s)".format(pkgalign, reqalign)
|
||||||
|
for pkg, name in names.items():
|
||||||
|
note = "mapped" if pkg != name else "default"
|
||||||
|
logging.debug(fmt, pkg, name, note)
|
||||||
|
|
||||||
|
# Return a sorted list for backward compatibility.
|
||||||
|
return sorted(set(names.values()), key=lambda s: s.lower())
|
||||||
|
|
||||||
def get_name_without_alias(name):
|
def get_name_without_alias(name):
|
||||||
if "import " in name:
|
if "import " in name:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user