Skip to content

Python: add buildPythonPackage.overridePythonPackage method.#26155

Closed
FRidh wants to merge 1 commit intoNixOS:masterfrom
FRidh:override
Closed

Python: add buildPythonPackage.overridePythonPackage method.#26155
FRidh wants to merge 1 commit intoNixOS:masterfrom
FRidh:override

Conversation

@FRidh
Copy link
Member

@FRidh FRidh commented May 27, 2017

This allows one to always override the call to buildPythonPackage.

In the following example we create an environment where we have the blaze package using an older version of pandas. We override first the Python interpreter and pass packageOverrides which contains the overrides for packages in
the package set.

with import <nixpkgs> {};

(let
  python = let
    packageOverrides = self: super: {
      pandas = super.pandas.overridePythonPackage(old: rec {
        version = "0.19.1";
        name = "pandas-${version}";
        src =  super.fetchPypi {
          pname = "pandas";
          inherit version;
          sha256 = "08blshqj9zj1wyjhhw3kl2vas75vhhicvv72flvf1z3jvapgw295";
        };
      });
    };
  in pkgs.python35.override {inherit packageOverrides;};

in python.withPackages(ps: [ps.blaze])).env
Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@FRidh FRidh added 0.kind: enhancement Add something new or improve an existing system. 6.topic: python Python is a high-level, general-purpose programming language. labels May 27, 2017
@mention-bot
Copy link

@FRidh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @alexeymuranov, @bennofs, @Azulinho and @FRidh to be potential reviewers.

@FRidh
Copy link
Member Author

FRidh commented May 27, 2017

This is a follow-up of #24155.
The previous PR I closed because I thought it wasn't working anymore. Maybe I did something wrong then because it does seem to work now.

This allows one to always override the call to `buildPythonPackage`.

In the following example we create an environment where we have the `blaze` package using an older version of `pandas`. We override first the Python interpreter and pass `packageOverrides` which contains the overrides for packages in
the package set.

```
with import <nixpkgs> {};

(let
  python = let
    packageOverrides = self: super: {
      pandas = super.pandas.overridePythonPackage(old: rec {
        version = "0.19.1";
        name = "pandas-${version}";
        src =  super.fetchPypi {
          pname = "pandas";
          inherit version;
          sha256 = "08blshqj9zj1wyjhhw3kl2vas75vhhicvv72flvf1z3jvapgw295";
        };
      });
    };
  in pkgs.python35.override {inherit packageOverrides;};

in python.withPackages(ps: [ps.blaze])).env
```
@FRidh FRidh added this to the 17.09 milestone Jul 31, 2017
@FRidh
Copy link
Member Author

FRidh commented Aug 9, 2017

I've pushed 345b35c to master.

@bennofs
Copy link
Contributor

bennofs commented Aug 9, 2017

@FRidh sorry that I didn't comment earlier, but wouldn't it be better to name this function overrideAttrs, for consistency with stdenv?

@FRidh
Copy link
Member Author

FRidh commented Aug 9, 2017

@bennofs I thought it would be good not to shadow any of the current names. overrideAttrs can still be used, although you likely wouldn't want to. Because of that, indeed, we might as well use overrideAttrs. I would prefer some more feedback before using that name.

@bennofs
Copy link
Contributor

bennofs commented Aug 9, 2017

@FRidh right, didn't think of the shadowing when I wrote that comment. But perhaps then, overridePythonAttrs would fit the existing naming scheme better?

@FRidh
Copy link
Member Author

FRidh commented Aug 12, 2017

@bennofs I agree
abdb58e

@FRidh FRidh closed this Aug 12, 2017
FRidh added a commit that referenced this pull request Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.kind: enhancement Add something new or improve an existing system. 6.topic: python Python is a high-level, general-purpose programming language.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants