Comments (7)
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.
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.
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.
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.
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.
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.
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)
- ValueError: invalid literal for int() with base 10 during pex build HOT 5
- How to bootstrap external pex files within running Python interpreter HOT 23
- Finalize Python 3.13 support HOT 1
- Build fails/incomplete on requirements.txt schema not followed correctly HOT 9
- Allow subsetting a PEX lockfile in PEX format, not just pip HOT 12
- Support for pip-compile generated requirements with hashes HOT 8
- bdist_pex called from tox fails with python 3.12 HOT 7
- Regression of artifact URL due to change since pip 23.3 HOT 12
- Monkey patch warning when using PEX to run a gunicorn app HOT 6
- `pex3 lock export` can turn VCS requirements into PyPI ones, resulting in hash failures HOT 3
- A way to configure sys.executable flags at PEX runtime HOT 8
- Add support for `--override`ing transitive dependencies. HOT 1
- Add `--provided`: like `--exclude`, but require the excluded project is available at boot time.
- "Resolving wheels disallowed" error when using `--lock` and `--only-binary` HOT 3
- Add more distribution metadata parsing context to failures.
- Add support for Pip 24.2 / statically linked musl libc CPythons
- Adding support to have all command line flags respected via environment variables HOT 6
- How does pex resolve defaut `--pip-version` HOT 13
- Support `--scie-pbs-flavor`. HOT 3
- Support `--scie` for PyPy.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pex.