MCPcopy
hub / github.com/bndr/pipreqs / get_pkg_names

Function get_pkg_names

pipreqs/pipreqs.py:275–293  ·  view source on GitHub ↗

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.

(pkgs)

Source from the content-addressed store, hash-verified

273
274
275def get_pkg_names(pkgs):
276 """Get PyPI package names from a list of imports.
277
278 Args:
279 pkgs (List[str]): List of import names.
280
281 Returns:
282 List[str]: The corresponding PyPI package names.
283
284 """
285 result = set()
286 with open(join("mapping"), "r") as f:
287 data = dict(x.strip().split(":") for x in f)
288 for pkg in pkgs:
289 # Look up the mapped requirement. If a mapping isn't found,
290 # simply use the package name.
291 result.add(data.get(pkg, pkg))
292 # Return a sorted list for backward compatibility.
293 return sorted(result, key=lambda s: s.lower())
294
295
296def get_name_without_alias(name):

Callers 1

initFunction · 0.85

Calls 1

joinFunction · 0.85

Tested by

no test coverage detected