diff options
author | Martin Weinelt <hexa@darmstadt.ccc.de> | 2023-10-21 15:52:49 +0200 |
---|---|---|
committer | Martin Weinelt <hexa@darmstadt.ccc.de> | 2023-10-30 12:42:36 +0100 |
commit | 646c23a2f7711690cce032233be54dcb1a037965 (patch) | |
tree | 0535ba6d08a5f0ed1b154270a7672c76a437b162 /pkgs/development/interpreters/python | |
parent | 54ae56720020575886dce1acbbb18e8028bb54f0 (diff) | |
download | nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar.gz nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar.bz2 nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar.lz nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar.xz nixlib-646c23a2f7711690cce032233be54dcb1a037965.tar.zst nixlib-646c23a2f7711690cce032233be54dcb1a037965.zip |
buildPythonPackage: port catch-conflicts to importlib.metadata
To escape the pkg_resources API deprecation: > catch-conflicts.py:1: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html Also remove exceptions for the previus bootstrap packages.
Diffstat (limited to 'pkgs/development/interpreters/python')
-rw-r--r-- | pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py | 30 | ||||
-rw-r--r-- | pkgs/development/interpreters/python/hooks/default.nix | 2 |
2 files changed, 18 insertions, 14 deletions
diff --git a/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py index bb82900c65a9..d5c99e64751c 100644 --- a/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py +++ b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py @@ -1,30 +1,34 @@ -import pkg_resources +from importlib.metadata import PathDistribution +from pathlib import Path import collections import sys + do_abort = False packages = collections.defaultdict(list) -for f in sys.path: - for req in pkg_resources.find_distributions(f): - if req not in packages[req.project_name]: - # some exceptions inside buildPythonPackage - if req.project_name in ['setuptools', 'pip', 'wheel']: - continue - packages[req.project_name].append(req) + +for path in sys.path: + for dist_info in Path(path).glob("*.dist-info"): + dist = PathDistribution(dist_info) + + packages[dist._normalized_name].append( + f"{dist._normalized_name} {dist.version} ({dist._path})" + ) for name, duplicates in packages.items(): if len(duplicates) > 1: do_abort = True print("Found duplicated packages in closure for dependency '{}': ".format(name)) - for dup in duplicates: - print(" " + repr(dup)) + for duplicate in duplicates: + print(f"\t{duplicate}") if do_abort: print("") print( - 'Package duplicates found in closure, see above. Usually this ' - 'happens if two packages depend on different version ' - 'of the same dependency.') + "Package duplicates found in closure, see above. Usually this " + "happens if two packages depend on different version " + "of the same dependency." + ) sys.exit(1) diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 6a05a7fa6ee8..16324b30b3f1 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -107,7 +107,7 @@ in { makePythonHook { name = "python-catch-conflicts-hook"; substitutions = { - inherit pythonInterpreter pythonSitePackages setuptools; + inherit pythonInterpreter pythonSitePackages; catchConflicts=../catch_conflicts/catch_conflicts.py; }; } ./python-catch-conflicts-hook.sh) {}; |