about summary refs log tree commit diff
path: root/pkgs/development/interpreters/python
diff options
context:
space:
mode:
authorMartin Weinelt <hexa@darmstadt.ccc.de>2023-10-21 15:52:49 +0200
committerMartin Weinelt <hexa@darmstadt.ccc.de>2023-10-30 12:42:36 +0100
commit646c23a2f7711690cce032233be54dcb1a037965 (patch)
tree0535ba6d08a5f0ed1b154270a7672c76a437b162 /pkgs/development/interpreters/python
parent54ae56720020575886dce1acbbb18e8028bb54f0 (diff)
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.py30
-rw-r--r--pkgs/development/interpreters/python/hooks/default.nix2
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 bb82900c65a92..d5c99e64751c7 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 6a05a7fa6ee89..16324b30b3f10 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) {};