Skip to content

Python: use buildEnv for application, remove PYTHONPATH wrapper - #16672

Closed
FRidh wants to merge 1 commit into
NixOS:masterfrom
FRidh:buildapplication
Closed

FRidh wants to merge 1 commit into
NixOS:masterfrom
FRidh:buildapplication

Conversation

@FRidh

@FRidh FRidh commented Jul 3, 2016 •

Copy link
Copy Markdown
Member
Motivation for this change

I got the following idea to make Python applications work, without wrapping all scripts with a wrapper that sets PYTHONPATH. In this PR I introduce a function that builds a python.buildEnv for the chosen Python application, and then another derivation that symlinks only the scripts of the application, but then via the buildEnv. This works because python.buildEnv sets PYTHONHOME.

Eventually, I will want to put this function in the passthru of the interpreter and have a python.packages and a python.applications with the latter mapping this function to python.packages.

Things done
  • Tested using sandboxing
    (nix.useChroot on NixOS,
    or option build-use-chroot in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • OS X
    • 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.

@RonnyPfannschmidt this might be of interest to you.

Replaces #16668

@FRidh FRidh added 6.topic: python Python is a high-level, general-purpose programming language. 2.status: work-in-progress labels Jul 3, 2016
@FRidh FRidh self-assigned this Jul 3, 2016
@mention-bot

Copy link
Copy Markdown

@FRidh, thanks for your PR! By analyzing the annotation information on this pull request, we identified @domenkozar, @offlinehacker and @adnelson to be potential reviewers

tox = buildApplication { package = pythonPackages.tox; };
ipython = buildApplication { package = pythonPackages.ipython; };

python26 = callPackage ../development/interpreters/python/2.6 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are just examples, I definitely won't keep these here.

@bennofs

bennofs commented Aug 16, 2016

Copy link
Copy Markdown
Contributor

Perhaps you could make the bin derivation just be another output of the env one, using multiple-outputs nix feature?

@FRidh

FRidh commented Aug 16, 2016

Copy link
Copy Markdown
Member Author

Indeed. python.buildEnv will need to get an extra parameter, outputs ? [ "out" ] then which will be "bin" in case of an application.

@FRidh

FRidh commented Aug 16, 2016

Copy link
Copy Markdown
Member Author

or could Python applications also create other output that we'd be interested in?

@FRidh

FRidh commented Aug 16, 2016 •

Copy link
Copy Markdown
Member Author

I couldn't figure out a way to give outputs to pkgs.buildEnv. Since it uses its own builder I don't think it has been implemented. Is that correct @vcunat ?

Example:

$ nix-shell -E 'with import <nixpkgs>{}; (pkgs.python35.buildEnv.override { extraLibs=[python35Packages.pytest]; outputs=["bin"];}).env'  -I nixpkgs=.
error: anonymous function at /home/freddy/Data/Data/Code/libraries/nixpkgs/pkgs/build-support/buildenv/default.nix:7:1 called with unexpected argument ‘outputs’, at /home/freddy/Data/Data/Code/libraries/nixpkgs/pkgs/development/interpreters/python/wrapper.nix:12:6
(use ‘--show-trace’ to show detailed location information)

@FRidh

FRidh commented Aug 16, 2016

Copy link
Copy Markdown
Member Author

Actually, using multiple-outputs won't work; we don't just want all of /bin, we only want the items that are in the package we're interested in. If we take /bin, we also get python, and then we can't install multiple Python applications simultaneously. @vcunat , you can ignore my question :)

{stdenv}:

{ package
}:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like sort of non-standard formatting. Perhaps either {package}: like you have above, or

{
  package
}:

Not a big deal but this reads kind of weird to me

@FRidh

FRidh commented Aug 16, 2016

Copy link
Copy Markdown
Member Author

@adnelson It can indeed use some cleanup. Note that the intention of this PR was to show how we can solve an issue, not really merging it as is. Implementing certain things takes a lot of time, so I rather get feedback first. Thanks for that.

@vcunat

vcunat commented Aug 16, 2016

Copy link
Copy Markdown
Member

In any case, buildEnv always produced a single output, at least around the time of the last NixCon.

@jgeerds

jgeerds commented Oct 25, 2016

Copy link
Copy Markdown
Member

I think this would be a really good way to avoid the more or less fragile PYTHONPATH solution. Are there any downsides?

What can we do about the missing multiple output support? Any new ideas?

@jgeerds

jgeerds commented Oct 25, 2016

Copy link
Copy Markdown
Member

Something like this is also on the todo list of triton: triton/triton#64

@FRidh

FRidh commented Oct 25, 2016

Copy link
Copy Markdown
Member Author

Are there any downsides?

Not that I can think of. I would prefer if there weren't any wrappers at all, but that would mean copying the contents of bin to the new env.

After some more thinking about this issue, I think PYTHONPATH isn't too bad either. The problem was just that we used prefix instead of set. However, if we use set, we break some other stuff, like the checkPhase. In #17749 I wrote that using set would break ipython, however, ipython would still be usable when creating an environment. Furthermore, and this is I think key to not using set PYTHONPATH, is that PYTHONPATH is an environment variable you might want to modify outside of Nix to add impure modules for whatever reason.

What can we do about the missing multiple output support? Any new ideas?

What do you mean with missing? Why do we need multiple outputs?

Are there any specific issues you're facing with the current implementation? That is, what Nixpkgs now uses.

@jgeerds

jgeerds commented Oct 25, 2016

Copy link
Copy Markdown
Member

Exactly! This is what I thought too.

Nope! I didn't read all coments carefully enough. Someone mentioned
multiple outputs a few comments ago and I thought that this is still a
missing piece.

@domenkozar What do you think about it?

@FRidh FRidh mentioned this pull request Jan 24, 2017
5 of 7 tasks
@FRidh FRidh mentioned this pull request May 27, 2017
5 of 7 tasks
@fpletz

fpletz commented Aug 15, 2017

Copy link
Copy Markdown
Member

What's the status here?

@FRidh FRidh added this to the 18.03 milestone Aug 19, 2017
@FRidh

FRidh commented Aug 19, 2017

Copy link
Copy Markdown
Member Author

I still think this is the way forward, but this won't make it in before 17.09 though. I have no idea when I could continue on this so I'm closing this now.

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.

7 participants