mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 19:45:22 +00:00
Merge pull request #102 from jonafato/cleanup-get_pkg_names
Simplify get_pkg_names function
This commit is contained in:
commit
7afbcb4b16
@ -120,7 +120,7 @@ def get_all_imports(
|
|||||||
with open(join("stdlib"), "r") as f:
|
with open(join("stdlib"), "r") as f:
|
||||||
data = [x.strip() for x in f.readlines()]
|
data = [x.strip() for x in f.readlines()]
|
||||||
data = [x for x in data if x not in py2_exclude] if py2 else data
|
data = [x for x in data if x not in py2_exclude] if py2 else data
|
||||||
return sorted(list(set(packages) - set(data)))
|
return list(set(packages) - set(data))
|
||||||
|
|
||||||
|
|
||||||
def filter_line(l):
|
def filter_line(l):
|
||||||
@ -224,18 +224,24 @@ def get_import_local(imports, encoding=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_pkg_names(pkgs):
|
def get_pkg_names(pkgs):
|
||||||
result = []
|
"""Get PyPI package names from a list of imports.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pkgs (List[str]): List of import names.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[str]: The corresponding PyPI package names.
|
||||||
|
|
||||||
|
"""
|
||||||
|
result = set()
|
||||||
with open(join("mapping"), "r") as f:
|
with open(join("mapping"), "r") as f:
|
||||||
data = [x.strip().split(":") for x in f.readlines()]
|
data = dict(x.strip().split(":") for x in f)
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
toappend = pkg
|
# Look up the mapped requirement. If a mapping isn't found,
|
||||||
for item in data:
|
# simply use the package name.
|
||||||
if item[0] == pkg:
|
result.add(data.get(pkg, pkg))
|
||||||
toappend = item[1]
|
# Return a sorted list for backward compatibility.
|
||||||
break
|
return sorted(result)
|
||||||
if toappend not in result:
|
|
||||||
result.append(toappend)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def get_name_without_alias(name):
|
def get_name_without_alias(name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user