Comments (8)
Pex is only supported as a binary, not a library. Can you explain your use case?
from pex.
Ah! I've been using PEX.resolve()
to find all the console_scripts
entry points and export them as shell wrappers after building the PEX, to allow the PEX to subprocess.run()
console_scripts from other requirements.
I'm using the CLI to build the PEX, but have not found a way to enable this use case with the PEX cli.
console_scripts = _get_console_scripts(PEX(str(self.output_file.get())))
if console_scripts:
console_scripts_dir.mkdir(parents=True, exist_ok=True)
self.logger.info("Exporting %d console_scripts in PEX to %s", len(console_scripts), console_scripts_dir)
for script in console_scripts:
file = console_scripts_dir / script
file.write_text(
f'#!/bin/sh\nPEX_SCRIPT={script} PATH="{console_scripts_dir.absolute()}:$PATH" '
f'"{self.output_file.get().absolute()}" "$@"\n'
"exit $?\n"
)
file.chmod(0o777)
else:
self.logger.info("note: PEX has no console_scripts")
# ...
def _get_console_scripts(pex: PEX) -> set[str]:
"""Return all entry points registered under `console_script` for this PEX."""
result = set()
for dist in pex.resolve():
result.update(dist.get_entry_map().get("console_scripts", {}).keys())
return result
There is the --venv
option and PEX_VENV=true PEX_VENV_BIN_PATH=prepend
variables, but I could not find a way to "embed" those variables in the PEX (--inject-var
doesn't seem to work with these PEX_
variables).
from pex.
You found the right answer, build the PEX with --venv prepend
. Or maybe you missed that --venv
optionally takes {prepend,append}
args?
from pex.
Oh, I did miss that! I'll try this right away, thank you. Are there any performance implications for enabling the --venv
mode?
from pex.
It works, unfortunately it has one drawback in my particular case in that the python
executable also resolve to that of the environment that the PEX is unpacked into. So when I run Mypy as a PEX, and pass --python-executable python
, it doesn't find any type hints for the project I actually want to type-check.
I've tried passing shutil.which("python")
to --python-executable
to get the full path to the Python interpreter that I actually want it to use. On my system that resolves to a Pyenv shim though, which later on when Mypy accesses it still resolves to the Python of the PEX's unpacked venv. 🤦
from pex.
@NiklasRosenstein if you can provide a working example using Pip / venv, I'm sure I can translate that to a working Pex example for you.
from pex.
@NiklasRosenstein I'll close this as an answered question unless you can provide an example set up repro steps that lead to a situation the CLI can't handle but your existing API use can.
from pex.
Alright @NiklasRosenstein you've been silent; so I'll close this as answered, but please speak up if you do find a situation the CLI can't handle that you expect it could / should / the (unsupported) APIs do.
from pex.
Related Issues (20)
- pex lock update: mechanism to remove projects from lockfile requirements HOT 7
- pex lock update: mechanism to change the version specifier if an existing requirement (or constraint?) HOT 5
- gmsh library not loaded in the packaged pex python binary HOT 21
- Documentation website is down/missing HOT 6
- lock update does not preserve "binary-ness" and errors out with artifact set changes HOT 6
- Support Pip's `--only-binary` / `--no-binary`. HOT 1
- Support syncing input requirements to a lock file more easily.
- Unify CLI options with Pip options when requirements files are parsed. HOT 2
- URL quoting regression when using `find-links` HOT 1
- Generating lockfiles fails with: unknown error (_ssl.c:3161) HOT 3
- Consider using uv as an optional alternate resolver. HOT 21
- Expose Pip's `--use-feature`. HOT 2
- How to build pex file with requirements.txt ? HOT 3
- Can we build the project without requirements.txt ? HOT 3
- lock create doesn't support tar.bz2 extensions HOT 6
- Implement more permissive `pex3 lock sync` locked resolve selection in multi-resolve locks.
- Trying to use pex to build a ML runtime. HOT 3
- unable to create pex with --no-build flag from lockfile HOT 2
- `--no-pre-install-wheels --requirements-pex .. --layout packed` gives `[Errno 21] Is a directory: '.../.deps/....whl'` errors HOT 3
- Incompatible Python version + `--complete-platforms ...` + `--lock ...` + empty cache gives seemingly-spurious "requires different Python" errors HOT 2
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.