Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

FRidh
Copy link
Member

@FRidh FRidh commented Jul 3, 2016

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

@mention-bot
Copy link

@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
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
Copy link
Contributor

bennofs commented Aug 16, 2016

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

@FRidh
Copy link
Member Author

FRidh commented Aug 16, 2016

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

@FRidh
Copy link
Member Author

FRidh commented Aug 16, 2016

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

@FRidh
Copy link
Member Author

FRidh commented Aug 16, 2016

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
Copy link
Member Author

FRidh commented Aug 16, 2016

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
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
Copy link
Member Author

FRidh commented Aug 16, 2016

@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
Copy link
Member

vcunat commented Aug 16, 2016

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

@jgeerds
Copy link
Member

jgeerds commented Oct 25, 2016

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
Copy link
Member

jgeerds commented Oct 25, 2016

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

@FRidh
Copy link
Member Author

FRidh commented Oct 25, 2016

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
Copy link
Member

jgeerds commented Oct 25, 2016

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
7 tasks
@FRidh FRidh mentioned this pull request May 27, 2017
7 tasks
@fpletz
Copy link
Member

fpletz commented Aug 15, 2017

What's the status here?

@FRidh FRidh added this to the 18.03 milestone Aug 19, 2017
@FRidh
Copy link
Member Author

FRidh commented Aug 19, 2017

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.

@FRidh FRidh closed this Aug 19, 2017
FRidh referenced this pull request Jan 11, 2018
This allows to have awscli running both under python 2 and 3 as
necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants