Giter Site home page Giter Site logo

Comments (7)

wickman avatar wickman commented on August 25, 2024

Yeah, hard to tell if this is a feature or a bug. The way pex treats interpreters is as "interpreter classes" -- a tuple of flavor (CPython, PyPy) and major/minor version (2.6, 2.7, 3.4.) So when you do --python= it uses that interpreter to build dependencies but then synthesizes the shebang line based upon the interpreter class instead of as the explicit interpreter. This is mostly for pex portability sake, since '#!/home/wickman/herp/derp/python2.7" is usually not what you want (but admittedly, it could be useful.)

Right now PEX_INTERPRETER is just a boolean to determine whether or not to drop into a repl. I'd like to change that to PEX_REPL=1 and use PEX_INTERPRETER the same way as --python. In other words, if it's an explicit path, re-exec to that interpreter, otherwise, try and search $PATH for an interpreter that satisfies a requirement e.g. PEX_INTERPRETER='PyPy>=2.4,<2.5'. This is why the PythonInterpreter.replace method exists but it has not yet been used in practice.

from pex.

warsaw avatar warsaw commented on August 25, 2024

Just to provide a use-case: I'm building a pex that will then get further bundled into a distributable format for Ubuntu Core Snappy. In that execution environment, there may not be a suitable $PATH to resolve the shebang, but I know that /usr/bin/python3 (or /usr/bin/python3.4) will exist. So I need a way to tell pex "no, really, this is the exact path I want you to use for the shebang". It's tricky to munge the shebang after the pex has been written.

from pex.

wickman avatar wickman commented on August 25, 2024

Totally agree this makes sense. I don't want it to be the default behavior but we should allow this. It should probably be an option to PythonInterpreter (e.g. preserve_hashbang=True?) but not completely sure what the API should look like. Thoughts?

from pex.

warsaw avatar warsaw commented on August 25, 2024

Looking at just the --help output, I found it surprising that --python didn't preserve my argument verbatim. I'm not sure if you've been following PEP 441, but we had a similar discussion over there. Totally get the need for pex to preserve its backward compatibility of course. I suppose in that case, something like --shebang=<everything-after-hashbang-exactly-preserved> would make sense. Maybe that would have to be mutually exclusive with --python?

from pex.

wickman avatar wickman commented on August 25, 2024

Good point. I thought about it a little more and I thought you're right, --python should probably be 'use this interpreter, exactly.' Perhaps a separate command flag, --python-version, could be switched out with the current --python semantics.

from pex.

warsaw avatar warsaw commented on August 25, 2024

On Feb 20, 2015, at 02:39 PM, brian wickman wrote:

Good point. I thought about it a little more and I thought you're right,
--python should probably be 'use this interpreter, exactly.' Perhaps a
separate command flag, --python-version, could be switched out with the
current --python semantics.

+1 :)

from pex.

wickman avatar wickman commented on August 25, 2024

I ultimately decided to leave --python alone. However, I added --python-shebang which allows you to set the shebang line exactly.

I also added the PEX_PYTHON environment variable which allows you to change which interpreter invokes the PEX, e.g.

mba=pex=; head -1 dist/pex
#!/usr/bin/env python2.7

mba=pex=; PEX_PYTHON=pypy PEX_INTERPRETER=1 dist/pex
Python 2.7.8 (f5dcc2477b97, Sep 19 2014, 18:09:54)
[PyPy 2.4.0 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 

This is on master now with 1.0.0.dev3. 'tox -e py34-package' to build a pex with all the above functionality.

from pex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.