From f292ef4958bf9e1de18c62a315ed09f95954473a Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 15 Nov 2023 14:44:01 +0100 Subject: [PATCH 1/2] python/hooks: restore catchConflictHook for python<3.10 By restoring and diverting to the old version. Previously the newer language features and use of more modern stdlib imports broke the hook on Python<3.10. --- .../catch_conflicts/catch_conflicts_py2.py | 30 +++++++++++++++++++ .../interpreters/python/hooks/default.nix | 11 +++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/interpreters/python/catch_conflicts/catch_conflicts_py2.py diff --git a/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts_py2.py b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts_py2.py new file mode 100644 index 0000000000000..bb82900c65a92 --- /dev/null +++ b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts_py2.py @@ -0,0 +1,30 @@ +import pkg_resources +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 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)) + +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.') + sys.exit(1) diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index f7cc10274ae36..0a4600b9d6c39 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -106,9 +106,16 @@ in { pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }: makePythonHook { name = "python-catch-conflicts-hook"; - substitutions = { + substitutions = let + useLegacyHook = lib.versionOlder python.version "3.10"; + in { inherit pythonInterpreter pythonSitePackages; - catchConflicts=../catch_conflicts/catch_conflicts.py; + catchConflicts = if useLegacyHook then + ../catch_conflicts/catch_conflicts_py2.py + else + ../catch_conflicts/catch_conflicts.py; + } // lib.optionalAttrs useLegacyHook { + inherit setuptools; }; } ./python-catch-conflicts-hook.sh) {}; From d9327a53de76fe34739ce9eda3cc01240fe7321a Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sat, 18 Nov 2023 12:58:15 +0100 Subject: [PATCH 2/2] Revert "python2/mk-python-derivation: disable catchConflictsHook" This reverts commit 397a8fd06bd576cae7f1fae71dbfd9fbce30dc66. The hook now uses the old implementation based on the deprecated pkg_resources library provided by setuptools again. --- .../interpreters/python/python2/mk-python-derivation.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/python/python2/mk-python-derivation.nix b/pkgs/development/interpreters/python/python2/mk-python-derivation.nix index 6d51b51b215d4..1a6f9c784cf67 100644 --- a/pkgs/development/interpreters/python/python2/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/python2/mk-python-derivation.nix @@ -57,8 +57,7 @@ # Raise an error if two packages are installed with the same name # TODO: For cross we probably need a different PYTHONPATH, or not # add the runtime deps until after buildPhase. -# FIXME: disabled for Python 2 because broken -, catchConflicts ? false +, catchConflicts ? (python.stdenv.hostPlatform == python.stdenv.buildPlatform) # Additional arguments to pass to the makeWrapper function, which wraps # generated binaries.