From 76213d102c1eaa91e733b326d9d312b60103d88a Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Sat, 1 Apr 2017 12:19:53 +0200 Subject: python: Move catch_conflicts.py into subdirectory (#23600) Python does add the script's directory into "sys.path". For the case of "catch_conflicts.py" this means "/nix/store" is added to "sys.path". This can result in very long delays if the store contains a lot of entries. --- .../interpreters/python/catch_conflicts.py | 30 ---------------------- .../interpreters/python/catch_conflicts/README.md | 13 ++++++++++ .../python/catch_conflicts/catch_conflicts.py | 30 ++++++++++++++++++++++ .../interpreters/python/mk-python-derivation.nix | 9 +++---- 4 files changed, 47 insertions(+), 35 deletions(-) delete mode 100644 pkgs/development/interpreters/python/catch_conflicts.py create mode 100644 pkgs/development/interpreters/python/catch_conflicts/README.md create mode 100644 pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py (limited to 'pkgs/development/interpreters') diff --git a/pkgs/development/interpreters/python/catch_conflicts.py b/pkgs/development/interpreters/python/catch_conflicts.py deleted file mode 100644 index bb82900c65a9..000000000000 --- a/pkgs/development/interpreters/python/catch_conflicts.py +++ /dev/null @@ -1,30 +0,0 @@ -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/catch_conflicts/README.md b/pkgs/development/interpreters/python/catch_conflicts/README.md new file mode 100644 index 000000000000..d144b80e3385 --- /dev/null +++ b/pkgs/development/interpreters/python/catch_conflicts/README.md @@ -0,0 +1,13 @@ + + +catch_conflicts.py +================== + +The file catch_conflicts.py is in a subdirectory because, if it isn't, the +/nix/store/ directory is added to sys.path causing a delay when building. + +Pointers: + +- https://docs.python.org/3/library/sys.html#sys.path + +- https://github.com/NixOS/nixpkgs/pull/23600 diff --git a/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py new file mode 100644 index 000000000000..bb82900c65a9 --- /dev/null +++ b/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.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/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index f30bd175daac..5d710fcad882 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -79,9 +79,10 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // { postFixup = '' wrapPythonPrograms '' + lib.optionalString catchConflicts '' - # check if we have two packages with the same name in closure and fail - # this shouldn't happen, something went wrong with dependencies specs - ${python.interpreter} ${./catch_conflicts.py} + # Check if we have two packages with the same name in the closure and fail. + # If this happens, something went wrong with the dependencies specs. + # Intentionally kept in a subdirectory, see catch_conflicts/README.md. + ${python.interpreter} ${./catch_conflicts}/catch_conflicts.py '' + attrs.postFixup or ''''; passthru = { @@ -98,5 +99,3 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // { isBuildPythonPackage = python.meta.platforms; }; }) - - -- cgit 1.4.1