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-wrapper: Wrap interpreter rather than script #7931

Closed
wants to merge 1 commit into from

Conversation

spwhitt
Copy link
Contributor

@spwhitt spwhitt commented May 21, 2015

A quick implementation of an alternative approach to solving #7366. According to a post on nix-dev, the solution in d4460d1 still causes problems.

This was written quite quickly, and it's highly unlikely that it's completely ready for a merge. So please discuss and review carefully.

@domenkozar @aszlig

@spwhitt spwhitt changed the title python-wrapper: Wrap interpreter rather than script [WIP]python-wrapper: Wrap interpreter rather than script May 21, 2015
@spwhitt spwhitt changed the title [WIP]python-wrapper: Wrap interpreter rather than script [WIP] python-wrapper: Wrap interpreter rather than script May 21, 2015
@spwhitt spwhitt force-pushed the wrapPython branch 3 times, most recently from 0e6dfea to 0d7788a Compare May 22, 2015 05:43
@spwhitt spwhitt changed the title [WIP] python-wrapper: Wrap interpreter rather than script python-wrapper: Wrap interpreter rather than script May 22, 2015
@domenkozar
Copy link
Member

Hmm, interesting approach. It would fix issues like #7368. Do you think of any downsides?

@spwhitt
Copy link
Contributor Author

spwhitt commented May 24, 2015

I haven't been able to think of any downsides. I tested on a good number of packages without finding any breakage.

There are only two minor things I'm still somewhat unsure of. The first is putting the python wrapper in $dir/.python-wrapped. It seems more semantically meaningful to put it in $out/bin/.python-wrapped, but I'm not sure how this would interact with multiple invocations of wrapPythonProgramsIn, and it would require me to ensure that the bin directory actually exists. For these reasons I'm leaving the current implementation alone unless anyone has a better idea. Since the file is hidden anyway, the ugliness of putting it in $dir (which is usually $out) is not too egregious.

The second thing is the handling of EGG-INFO scripts. Should I be skipping them? Do they need to have their shebangs patched in some way?

Other than that, I believe this is ready for a merge. I think it's significantly simpler and more robust than the current approach.

@spwhitt
Copy link
Contributor Author

spwhitt commented May 24, 2015

Resolved conflict with current master.

Wrapping python scripts changes sys.argv[0], so we have had to patch
these scripts to set sys.argv[0] back to the right value. Doing this
patching correctly is difficult, and tends to break scripts. See NixOS#7366
for an example.

This implements an alternative approach in which python scripts are not
wrapped at all. Instead, the python interpreter is wrapped, and the
python scripts have their shebang modified to point at the wrapped
python.
@spwhitt
Copy link
Contributor Author

spwhitt commented Nov 21, 2015

I've updated this to master and re-tested it, but am now running into shebang lines which are too long. I'm not sure why I didn't encounter this problem last time I tested it, but regardless this is a problem that could be fixed by #11133, if we can't find another approach.

@FRidh
Copy link
Member

FRidh commented Nov 23, 2015

Any idea how this would work with alternative interpreters like IPython/Jupyter?

@spwhitt
Copy link
Contributor Author

spwhitt commented Nov 23, 2015

@FRidh Perhaps I don't understand the question, but I can't think of any way this would impact IPython/Jupyter use, since this PR only effects executable python scripts.

@FRidh
Copy link
Member

FRidh commented Nov 24, 2015

If I understand correctly you will wrap the Python interpreter, and patch the shebangs of all scripts in say /bin to use the patched interpreter.

However, IPython/Jupyter resides also in /bin, and being an alternative interpreter, needs to be able to import modules in a similar way as CPython, which is currently broken when using python.buildEnv, but not when using nix-shell though). See #11147. I'm trying to see whether and how work here relates to that. If I am correct I can't just wrap everything in /bin in case this PR would get merged.

@RonnyPfannschmidt
Copy link
Contributor

this is broken in the same way that the current wrapping mechanism is broken,
it leaks python-path to sub-processes, that may have a different oath and/or python major version

@domenkozar
Copy link
Member

@FRidh would you test this with jupyter?

@bennofs
Copy link
Contributor

bennofs commented Apr 22, 2017

@FRidh is this still relevant? If I'm informed correctly, the python infrastructure has changed significantly since this PR was created, so perhaps we can close this? Even if it is closed, the diff will stay if anyone would like to look at it later.

@FRidh
Copy link
Member

FRidh commented Apr 23, 2017

@bennofs you're right, let's close this.

@FRidh FRidh closed this Apr 23, 2017
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

5 participants