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.
This commit is contained in:
Martin Weinelt 2023-11-15 14:44:01 +01:00
parent b3e8dae766
commit f292ef4958
No known key found for this signature in database
GPG key ID: 87C1E9888F856759
2 changed files with 39 additions and 2 deletions

View file

@ -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)

View file

@ -106,9 +106,16 @@ in {
pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }: pythonCatchConflictsHook = callPackage ({ makePythonHook, setuptools }:
makePythonHook { makePythonHook {
name = "python-catch-conflicts-hook"; name = "python-catch-conflicts-hook";
substitutions = { substitutions = let
useLegacyHook = lib.versionOlder python.version "3.10";
in {
inherit pythonInterpreter pythonSitePackages; 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) {}; } ./python-catch-conflicts-hook.sh) {};