1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 16:27:13 +03:00
EDMarketConnector/scripts/pip_rev_deps.py
Athanasius 5064b10744
Bring in scripts/pip_rev_deps.py
* This finds the pip-installed modules that depend on the specified module.
  Handy for cleaning things up.
* Leads to needing types-pkg-resources for mypy (and via pre-commit).
2022-12-23 14:48:21 +00:00

23 lines
556 B
Python

#!/usr/bin/env python
"""Find the reverse dependencies of a package according to pip."""
import sys
import pkg_resources
def find_reverse_deps(package_name: str):
"""
Find the packages that depend on the named one.
:param package_name: Target package.
:return: List of packages that depend on this one.
"""
return [
pkg.project_name for pkg in pkg_resources.WorkingSet()
if package_name in {req.project_name for req in pkg.requires()}
]
if __name__ == '__main__':
print(find_reverse_deps(sys.argv[1]))