From f90023104201c03ee08061da8ab448a693d4ab71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Wed, 18 Nov 2015 11:46:21 +0100 Subject: [PATCH] buildPythonPackage: fail if two packages with the same name are in closure --- .../python-modules/generic/default.nix | 4 +++ .../python-modules/generic/do_conflict.py | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/development/python-modules/generic/do_conflict.py diff --git a/pkgs/development/python-modules/generic/default.nix b/pkgs/development/python-modules/generic/default.nix index 0a2fd429f002..2927b3ab4013 100644 --- a/pkgs/development/python-modules/generic/default.nix +++ b/pkgs/development/python-modules/generic/default.nix @@ -103,6 +103,10 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // { postFixup = attrs.postFixup or '' wrapPythonPrograms + + # check if we have two packagegs with the same name in closure and fail + # this shouldn't happen, something went wrong with dependencies specs + python ${./do_conflict.py} ''; shellHook = attrs.shellHook or '' diff --git a/pkgs/development/python-modules/generic/do_conflict.py b/pkgs/development/python-modules/generic/do_conflict.py new file mode 100644 index 000000000000..412c15eac4b5 --- /dev/null +++ b/pkgs/development/python-modules/generic/do_conflict.py @@ -0,0 +1,29 @@ +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]: + if req.project_name == 'setuptools': + continue + packages[req.project_name].append(req) + + +for name, duplicates in packages.iteritems(): + 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)