Skip to content

Commit

Permalink
pythonPackages: Switch to lib.makeScope for overrideScope support
Browse files Browse the repository at this point in the history
This change allows previously ~final package sets to be overridden with
overlays , e.g. you can do `pkgs.python.pkgs.overrideScope' (self: super: { ... })`
whereas previously only `pkgs.python.override { packageOverrides =
(self: super: { ... })` was possible.

This therefore also allows packages definitions to transitively override
dependencies. So e.g. if jupyterlab_server requires jsonschema >= 3, but
the rest of the packages should still use jsonschema == 2, you can
define it as such:

  jupyterlab_server = (self.overrideScope' (self: super: {
    jsonschema = self.jsonschema3;
  })).callPackage ../development/python-modules/jupyterlab_server { };

This applies the overlay to the whole dependency closure, whereas

  jupyterlab_server = callPackage ../development/python-modules/jupyterlab_server {
    jsonschema = self.jsonschema3;
  };

would only make it apply to jupyterlab_server itself, but not its
dependencies, resulting in build-time errors. To get the desired effect without
this change, this would be needed for this specific case:

  jupyterlab_server = callPackage ../development/python-modules/jupyterlab_server {
    jsonschema = self.jsonschema3;
    notebook = self.notebook.override {
      nbformat = self.nbformat.override {
        jsonschema = self.jsonschema3;
      };
      nbconvert = self.nbconvert.override {
        nbformat = self.nbformat.override {
          jsonschema = self.jsonschema3;
        };
      };
    };
  };
  • Loading branch information
infinisil committed Aug 25, 2019
1 parent 004e9b5 commit c5f7278
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

with pkgs.lib;

let
packages = ( self:
(makeScope pkgs.newScope ( self:

let
inherit (python.passthru) isPy27 isPy33 isPy34 isPy35 isPy36 isPy37 isPy38 isPy3k isPyPy pythonAtLeast pythonOlder;

callPackage = pkgs.newScope self;
callPackage = self.callPackage;

namePrefix = python.libPrefix + "-";

Expand Down Expand Up @@ -105,7 +104,7 @@ in {

inherit (python.passthru) isPy27 isPy33 isPy34 isPy35 isPy36 isPy37 isPy3k isPyPy pythonAtLeast pythonOlder;
inherit python bootstrapped-pip buildPythonPackage buildPythonApplication;
inherit fetchPypi callPackage;
inherit fetchPypi;
inherit hasPythonModule requiredPythonModules makePythonPath disabledIf;
inherit toPythonModule toPythonApplication;
inherit buildSetupcfg;
Expand Down Expand Up @@ -6194,6 +6193,4 @@ in {
runway-python = callPackage ../development/python-modules/runway-python { };

pyprof2calltree = callPackage ../development/python-modules/pyprof2calltree { };
});

in fix' (extends overrides packages)
})).overrideScope' overrides

0 comments on commit c5f7278

Please sign in to comment.