@@ -31,10 +31,9 @@ let
3131
3232 callPackage = pkgs.newScope self;
3333
34− bootstrapped-pip = callPackage ../development/python-modules/bootstrapped-pip { };
34+ namePrefix = python.libPrefix + "-";
3535
36− mkPythonDerivation = makeOverridable( callPackage ../development/interpreters/python/mk-python-derivation.nix {
37− });
36+ bootstrapped-pip = callPackage ../development/python-modules/bootstrapped-pip { };
3837
3938 # Derivations built with `buildPythonPackage` can already be overriden with `override`, `overrideAttrs`, and `overrideDerivation`.
4039 # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`.
@@ -52,13 +51,20 @@ let
5251 }
5352 else ff;
5453
55− buildPythonPackage = makeOverridablePythonPackage (callPackage ../development/interpreters/python/build-python-package.nix {
56− inherit mkPythonDerivation;
54+ buildPythonPackage = makeOverridablePythonPackage ( makeOverridable (callPackage ../development/interpreters/python/build-python-package.nix {
5755 inherit bootstrapped-pip;
5856 flit = self.flit;
59− });
57+ # We want Python libraries to be named like e.g. "python3.6-${name}"
58+ inherit namePrefix;
59+ pythonModule = python;
60+ }));
6061
61− buildPythonApplication = args: buildPythonPackage ({namePrefix="";} // args );
62+ buildPythonApplication = makeOverridablePythonPackage ( makeOverridable (callPackage ../development/interpreters/python/build-python-package.nix {
63+ inherit bootstrapped-pip;
64+ flit = self.flit;
65+ namePrefix = "";
66+ pythonModule = false;
67+ }));
6268
6369 graphiteVersion = "1.0.2";
6470
@@ -80,10 +86,40 @@ let
8086 else throw "Unsupported kind ${kind}");
8187 in fetcher (builtins.removeAttrs attrs ["format"]) );
8288
89+ # Check whether a derivation provides a Python module.
90+ hasPythonModule = drv: (hasAttr "pythonModule" drv) && ( (getAttr "pythonModule" drv) == python);
91+
92+ # Get list of required Python modules given a list of derivations.
93+ requiredPythonModules = drvs: let
94+ filterNull = list: filter (x: !isNull x) list;
95+ conditionalGetRecurse = attr: condition: drv: let f = conditionalGetRecurse attr condition; in
96+ (if (condition drv) then unique [drv]++(concatMap f (filterNull(getAttr attr drv))) else []);
97+ _required = drv: conditionalGetRecurse "propagatedBuildInputs" hasPythonModule drv;
98+ in [python] ++ (unique (concatMap _required (filterNull drvs)));
99+
100+ # Create a PYTHONPATH from a list of derivations. This function recurses into the items to find derivations
101+ # providing Python modules.
102+ makePythonPath = drvs: stdenv.lib.makeSearchPath python.sitePackages (requiredPythonModules drvs);
103+
104+ # Convert derivation to a Python module.
105+ toPythonModule = drv:
106+ drv.overrideAttrs( oldAttrs: {
107+ # Use passthru in order to prevent rebuilds when possible.
108+ passthru = (oldAttrs.passthru or {})// {
109+ name = namePrefix + oldAttrs.name;
110+ pythonModule = python;
111+ pythonPath = [ ]; # Deprecated, for compatibility.
112+ };
113+ });
114+
115+ disabledIf = x: drv:
116+ if x then throw "${removePrefix namePrefix (drv.pname or drv.name)} not supported for interpreter ${python.executable}" else drv;
117+
83118in {
84119
85− inherit python bootstrapped-pip pythonAtLeast pythonOlder isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k mkPythonDerivation buildPythonPackage buildPythonApplication;
120+ inherit python bootstrapped-pip pythonAtLeast pythonOlder isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k buildPythonPackage buildPythonApplication;
86121 inherit fetchPypi callPackage;
122+ inherit hasPythonModule requiredPythonModules makePythonPath disabledIf;
87123
88124 # helpers
89125
@@ -154,9 +190,7 @@ in {
154190
155191 breathe = callPackage ../development/python-modules/breathe { };
156192
157− browsermob-proxy = if ! isPy3k then
158− callPackage ../development/python-modules/browsermob-proxy {}
159− else throw "browsermob-proxy is not supported for ${python.executable}";
193+ browsermob-proxy = disabledIf isPy3k (callPackage ../development/python-modules/browsermob-proxy {});
160194
161195 bugseverywhere = callPackage ../applications/version-management/bugseverywhere {};
162196
@@ -222,11 +256,11 @@ in {
222256
223257 pyamf = callPackage ../development/python-modules/pyamf { };
224258
225− pyatspi = if isPy3k then callPackage ../development/python-modules/pyatspi { } else throw "pyatspi not supported for interpreter ${python.executable}";
259+ pyatspi = disabledIf (!isPy3k) (callPackage ../development/python-modules/pyatspi { });
226260
227261 pycairo = callPackage ../development/python-modules/pycairo { };
228262
229− pycangjie = if isPy3k then callPackage ../development/python-modules/pycangjie { } else throw "pycangjie not supported for interpreter ${python.executable}";
263+ pycangjie = disabledIf (!isPy3k) (callPackage ../development/python-modules/pycangjie { });
230264
231265 pycrypto = callPackage ../development/python-modules/pycrypto { };
232266
@@ -236,7 +270,7 @@ in {
236270
237271 PyChromecast = callPackage ../development/python-modules/pychromecast { };
238272
239− pyexiv2 = if (!isPy3k) then callPackage ../development/python-modules/pyexiv2 {} else throw "pyexiv2 not supported for interpreter ${python.executable}";
273+ pyexiv2 = disabledIf isPy3k (callPackage ../development/python-modules/pyexiv2 {});
240274
241275 py3exiv2 = callPackage ../development/python-modules/py3exiv2 { };
242276
@@ -298,13 +332,13 @@ in {
298332
299333 PyWebDAV = callPackage ../development/python-modules/pywebdav { };
300334
301− pyxml = if !isPy3k then callPackage ../development/python-modules/pyxml{ } else throw "pyxml not supported for interpreter ${python.executable}";
335+ pyxml = disabledIf isPy3k (callPackage ../development/python-modules/pyxml{ });
302336
303337 relatorio = callPackage ../development/python-modules/relatorio { };
304338
305339 pyzufall = callPackage ../development/python-modules/pyzufall { };
306340
307− rhpl = if !isPy3k then callPackage ../development/python-modules/rhpl {} else throw "rhpl not supported for interpreter ${python.executable}";
341+ rhpl = disabledIf isPy3k (callPackage ../development/python-modules/rhpl {});
308342
309343 simpleeval = callPackage ../development/python-modules/simpleeval { };
310344
@@ -1336,10 +1370,10 @@ in {
13361370
13371371 # Build boost for this specific Python version
13381372 # TODO: use separate output for libboost_python.so
1339− boost = pkgs.boost.override {
1373+ boost = toPythonModule (pkgs.boost.override {
13401374 inherit (self) python numpy;
13411375 enablePython = true;
1342− };
1376+ });
13431377
13441378 buttersink = buildPythonPackage rec {
13451379 name = "buttersink-0.6.8";
@@ -3200,15 +3234,15 @@ in {
32003234 propagatedBuildInputs = with self; [ pyusb ];
32013235 };
32023236
3203− opencv = pkgs.opencv.override {
3237+ opencv = toPythonModule (pkgs.opencv.override {
32043238 enablePython = true;
32053239 pythonPackages = self;
3206− };
3240+ });
32073241
3208− opencv3 = pkgs.opencv3.override {
3242+ opencv3 = toPythonModule (pkgs.opencv3.override {
32093243 enablePython = true;
32103244 pythonPackages = self;
3211− };
3245+ });
32123246
32133247 openidc-client = callPackage ../development/python-modules/openidc-client/default.nix {};
32143248
@@ -4735,13 +4769,11 @@ in {
47354769
47364770 easy-thumbnails = callPackage ../development/python-modules/easy-thumbnails { };
47374771
4738− eccodes = if (isPy27) then
4739− (pkgs.eccodes.overrideAttrs (oldattrs: {
4740− name = "${python.libPrefix}-" + oldattrs.name;
4741− })).override {
4742− enablePython = true;
4743− pythonPackages = self;
4744− } else throw "eccodes not supported for interpreter ${python.executable}";
4772+ eccodes = disabledIf (!isPy27)
4773+ (toPythonModule (pkgs.eccodes.override {
4774+ enablePython = true;
4775+ pythonPackages = self;
4776+ }));
47454777
47464778 EditorConfig = buildPythonPackage rec {
47474779 name = "EditorConfig-${version}";
@@ -8712,10 +8744,10 @@ in {
87128744
87138745 folium = callPackage ../development/python-modules/folium { };
87148746
8715− fontforge = pkgs.fontforge.override {
8747+ fontforge = toPythonModule (pkgs.fontforge.override {
87168748 withPython = true;
87178749 inherit python;
8718− };
8750+ });
87198751
87208752 fonttools = callPackage ../development/python-modules/fonttools { };
87218753
@@ -8889,11 +8921,9 @@ in {
88898921 };
88908922 };
88918923
8892− gdal = (pkgs.gdal.overrideDerivation (oldattrs: {
8893− name = "${python.libPrefix}-" + oldattrs.name;
8894− })).override {
8924+ gdal = toPythonModule (pkgs.gdal.override {
88958925 pythonPackages = self;
8896− };
8926+ });
88978927
88988928 gdrivefs = buildPythonPackage rec {
88998929 version = "0.14.8";
@@ -9265,13 +9295,11 @@ in {
92659295 };
92669296 };
92679297
9268− grib-api = if (isPy27) then
9269− (pkgs.grib-api.overrideAttrs (oldattrs: {
9270− name = "${python.libPrefix}-" + oldattrs.name;
9271− })).override {
9272− enablePython = true;
9273− pythonPackages = self;
9274− } else throw "grib-api not supported for interpreter ${python.executable}";
9298+ grib-api = disabledIf (!isPy27) (toPythonModule
9299+ (pkgs.grib-api.override {
9300+ enablePython = true;
9301+ pythonPackages = self;
9302+ }));
92759303
92769304 gspread = buildPythonPackage rec {
92779305 version = "0.2.3";
@@ -10373,14 +10401,14 @@ in {
1037310401 inherit (pkgs) libsodium;
1037410402 };
1037510403
10376− libplist = if isPy3k then throw "libplist not supported for interpreter ${python.executable}" else
10377− (pkgs.libplist.override{python2Packages=self; }).py;
10404+ libplist = disabledIf isPy3k
10405+ (toPythonModule (pkgs.libplist.override{python2Packages=self; })).py;
1037810406
10379− libxml2 = if isPy3k then throw "libxml2 not supported for interpreter ${python.executable}" else
10380− (pkgs.libxml2.override{pythonSupport=true; python2=python;}).py;
10407+ libxml2 = disabledIf isPy3k
10408+ (toPythonModule (pkgs.libxml2.override{pythonSupport=true; python2=python;})).py;
1038110409
10382− libxslt = if isPy3k then throw "libxslt not supported for interpreter ${python.executable}" else
10383− (pkgs.libxslt.override{pythonSupport=true; python2=python; inherit (self) libxml2;}).py;
10410+ libxslt = disabledIf isPy3k
10411+ (toPythonModule (pkgs.libxslt.override{pythonSupport=true; python2=python; inherit (self) libxml2;})).py;
1038410412
1038510413 limnoria = buildPythonPackage rec {
1038610414 name = "limnoria-${version}";
@@ -10436,22 +10464,7 @@ in {
1043610464 fuse = pkgs.fuse; # use "real" fuse, not the python module
1043710465 };
1043810466
10439− locustio = buildPythonPackage rec {
10440− name = "locustio-0.7.2";
10441−
10442− src = pkgs.fetchurl {
10443− url = "mirror://pypi/l/locustio/${name}.tar.gz";
10444− sha256 = "c9ca6fdfe6a6fb187a3d54ddf9b1518196348e8f20537f0a14ca81a264ffafa2";
10445− };
10446−
10447− propagatedBuildInputs = [ self.msgpack self.requests self.flask self.gevent self.pyzmq ];
10448− buildInputs = [ self.mock self.unittest2 ];
10449−
10450− meta = {
10451− homepage = http://locust.io/;
10452− description = "A load testing tool";
10453− };
10454− };
10467+ locustio = callPackage ../development/python-modules/locustio { };
1045510468
1045610469 llvmlite = callPackage ../development/python-modules/llvmlite {llvm=pkgs.llvm_4;};
1045710470
@@ -14853,31 +14866,13 @@ in {
1485314866
1485414867 psd-tools = callPackage ../development/python-modules/psd-tools { };
1485514868
14856− psutil = buildPythonPackage rec {
14857− name = "psutil-${version}";
14858− version = "4.3.0";
14859−
14860− src = pkgs.fetchurl {
14861− url = "mirror://pypi/p/psutil/${name}.tar.gz";
14862− sha256 = "1w4r09fvn6kd80m5mx4ws1wz100brkaq6hzzpwrns8cgjzjpl6c6";
14863− };
14864−
14865− # Certain tests fail due to being in a chroot.
14866− # See also the older issue: https://code.google.com/p/psutil/issues/detail?id=434
14867− doCheck = false;
14868−
14869− buildInputs = with self; [ mock ] ++ optionals stdenv.isDarwin [ pkgs.darwin.IOKit ];
14869+ psutil = callPackage ../development/python-modules/psutil { };
1487014870
14871− meta = {
14872− description = "Process and system utilization information interface for python";
14873− homepage = https://github.com/giampaolo/psutil;
14874− };
14875− };
14876−
14877− psutil_1 = self.psutil.overrideDerivation (self: rec {
14878− name = "psutil-1.2.1";
14879− src = pkgs.fetchurl {
14880− url = "mirror://pypi/p/psutil/${name}.tar.gz";
14871+ psutil_1 = self.psutil.overrideAttrs (oldAttrs: rec {
14872+ name = "${oldAttrs.pname}-${version}";
14873+ version = "1.2.1";
14874+ src = oldAttrs.src.override {
14875+ inherit version;
1488114876 sha256 = "0ibclqy6a4qmkjhlk3g8jhpvnk0v9aywknc61xm3hfi5r124m3jh";
1488214877 };
1488314878 });
@@ -16994,9 +16989,8 @@ in {
1699416989 };
1699516990 };
1699616991
16997− qscintilla = if isPy3k || isPyPy
16998− then throw "qscintilla-${pkgs.qscintilla.version} not supported for interpreter ${python.executable}"
16999− else buildPythonPackage rec {
16992+ qscintilla = disabledIf (isPy3k || isPyPy)
16993+ (buildPythonPackage rec {
1700016994 # TODO: Qt5 support
1700116995 name = "qscintilla-${version}";
1700216996 version = pkgs.qscintilla.version;
@@ -17025,7 +17019,7 @@ in {
1702517019 maintainers = with maintainers; [ danbst ];
1702617020 platforms = platforms.linux;
1702717021 };
17028− };
17022+ });
1702917023
1703017024
1703117025 qserve = buildPythonPackage rec {
@@ -17173,6 +17167,10 @@ in {
1717317167
1717417168 readme_renderer = callPackage ../development/python-modules/readme_renderer { };
1717517169
17170+ rivet = disabledIf isPy3k (toPythonModule (pkgs.rivet.override {
17171+ python2 = python;
17172+ }));
17173+
1717617174 rjsmin = callPackage ../development/python-modules/rjsmin { };
1717717175
1717817176 pysolr = buildPythonPackage rec {
@@ -17444,7 +17442,7 @@ in {
1744417442
1744517443 rply = callPackage ../development/python-modules/rply/default.nix {};
1744617444
17447− rpm = (pkgs.rpm.override{inherit python;});
17445+ rpm = toPythonModule (pkgs.rpm.override{inherit python;});
1744817446
1744917447 rpmfluff = callPackage ../development/python-modules/rpmfluff {};
1745017448
@@ -22093,7 +22091,7 @@ EOF
2209322091 };
2209422092
2209522093 # For backwards compatibility. Please use nixpkgs.udiskie instead.
22096− udiskie = pkgs.udiskie.override { pythonPackages = self; };
22094+ udiskie = toPythonModule (pkgs.udiskie.override { pythonPackages = self; });
2209722095
2209822096 # Should be bumped along with EFL!
2209922097 pythonefl = buildPythonPackage rec {
@@ -24355,9 +24353,8 @@ EOF
2435524353 ROPGadget = callPackage ../development/python-modules/ROPGadget { };
2435624354
2435724355 # We need "normal" libxml2 and not the python package by the same name.
24358− pywbem = if !(isPy36)
24359− then callPackage ../development/python-modules/pywbem { libxml2 = pkgs.libxml2; }
24360− else throw "pywbem not supported for interpreter ${python.executable}";
24356+ pywbem = disabledIf isPy36
24357+ (callPackage ../development/python-modules/pywbem { libxml2 = pkgs.libxml2; });
2436124358
2436224359 unicorn = callPackage ../development/python-modules/unicorn { };
2436324360
@@ -24429,8 +24426,8 @@ EOF
2442924426
2443024427 zeep = callPackage ../development/python-modules/zeep { };
2443124428
24432− zeitgeist = if isPy3k then throw "zeitgeist not supported for interpreter ${python.executable}" else
24433− (pkgs.zeitgeist.override{python2Packages=self;}).py;
24429+ zeitgeist = disabledIf isPy3k
24430+ (toPythonModule (pkgs.zeitgeist.override{python2Packages=self;})).py;
2443424431
2443524432 zeroconf = callPackage ../development/python-modules/zeroconf { };
2443624433