Skip to content

chore(deps): upgrade pex to latest #544

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

chore(deps): upgrade pex to latest #544

wants to merge 1 commit into from

Conversation

alexeagle
Copy link
Member

No description provided.

@alexeagle alexeagle requested a review from arrdem April 2, 2025 20:33
Copy link

github-actions bot commented Apr 2, 2025

e2e/use_release folder: LCOV of commit 74fc16c during CI #1693

Summary coverage rate:
  lines......: 100.0% (2 of 2 lines)
  functions..: 100.0% (1 of 1 function)
  branches...: no data found

Files changed coverage rate: n/a

@alexeagle
Copy link
Member Author

hmm @thesayyn looks like this hacky bit needs a re-hack https://github.com/aspect-build/rules_py/blob/main/py/tools/pex/main.py#L112

@thesayyn
Copy link
Member

thesayyn commented Apr 2, 2025

hmm @thesayyn looks like this hacky bit needs a re-hack https://github.com/aspect-build/rules_py/blob/main/py/tools/pex/main.py#L112

eh, i was hoping we wouldn't need to update it again. I'll TAL tomorrow

@jsirois
Copy link

jsirois commented Apr 3, 2025

Pex maintainer here. FWIW importing pex is absolutely unsupported. The Pex CLI will never break you but the non-existent API definitely will. If someone can give me a high-level confirmation of what you're trying to do, I can hopefully point out how you might acheive that with the CLI.

@thesayyn
Copy link
Member

thesayyn commented Apr 3, 2025

Pex maintainer here. FWIW importing pex is absolutely unsupported. The Pex CLI will never break you but the non-existent API definitely will. If someone can give me a high-level confirmation of what you're trying to do, I can hopefully point out how you might acheive that with the CLI.

What we were trying with that patch was to do two things.

Add expanded wheels into deps here:

for dep in options.dependencies:
dist = Distribution.load(dep)
# TODO: explain which level of inferno is this!
key = "%s-%s" % (dist.key, dist.version)
dist_hash = pex_builder._add_dist(
path= dist.location,
dist_name = key
)
pex_info.add_distribution(key, dist_hash)
pex_builder.add_requirement(dist.as_requirement())

And set some environment variables

And append some paths to sys.path to support py_binary#imports so that relative imports work.

@thesayyn
Copy link
Member

thesayyn commented Apr 3, 2025

FWIW importing pex is absolutely unsupported
Yes, we were aware of that in this case and went with a custom cli after finding some of related issues that went stale. (been a long time can't remember what i saw)

@jsirois
Copy link

jsirois commented Apr 3, 2025

Thanks @thesayyn. A few questions:

Add expanded wheels into deps here:

What is an "expanded wheel"? Just unzipped, or fully installed (unpack + spread as specified here: https://packaging.python.org/en/latest/specifications/binary-distribution-format/#details) or something else?

And set some environment variables

I think --inject-env is what you want. That's new within the last several years. No real doc except CLI --help, but mentioned here: https://docs.pex-tool.org/recipes.html#uvicorn-and-other-customizable-application-servers

And append some paths to sys.path to support py_binary#imports so that relative imports work.

There is no CLI option to build this into the PEX file itself like --inject-env, but there is this env var knob: https://docs.pex-tool.org/api/vars.html#PEX_EXTRA_SYS_PATH. If you need the modification baked into the PEX you can use the very old --preamble option. For example:

:; echo 'import os; os.environ["PEX_EXTRA_SYS_PATH"] = "foo:bar"' > preamble

:; pex cowsay -c cowsay --preamble preamble -o cowsay.pex

:; PEX_VERBOSE=1 ./cowsay.pex -t Moo!
pex: Laying out PEX zipfile /home/jsirois/dev/pex-tool/pexcz/cowsay.pex: 0.2ms
pex: Executing installed PEX for /home/jsirois/dev/pex-tool/pexcz/./cowsay.pex at /home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e
pex:   Testing /home/jsirois/.pyenv/versions/3.11.11/bin/python3.11 can resolve PEX at /home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e: 2.0ms
pex: Using the current interpreter /home/jsirois/.pyenv/versions/3.11.11/bin/python3.11 since it matches constraints and PYTHONPATH is not set.
pex: Discarding site packages path: Platlib(/home/jsirois/.pyenv/versions/3.11.11/lib/python3.11/site-packages)
pex: Tainted path element: /home/jsirois/.pyenv/versions/3.11.11/lib/python3.11/site-packages
pex: Tainted path element: foo
pex: Scrubbing from user site: /home/jsirois/.local/lib/python3.11/site-packages
pex: Scrubbing from site-packages: /home/jsirois/.pyenv/versions/3.11.11/lib/python3.11/site-packages
pex: Scrubbing from site-packages: foo
pex: Scrubbing from site-packages: /home/jsirois/dev/pex-tool/pexcz/foo
pex: Adding foo:bar to sys.path
pex: New sys.path: ['/home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e/.bootstrap/pex/vendor/_vendored/attrs', '/home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e/.bootstrap', '/home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e', '/home/jsirois/.pyenv/versions/3.11.11/lib/python311.zip', '/home/jsirois/.pyenv/versions/3.11.11/lib/python3.11', '/home/jsirois/.pyenv/versions/3.11.11/lib/python3.11/lib-dynload', 'foo', 'bar']
pex: Activating PEX virtual environment from /home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e: 0.2ms
pex: Bootstrap complete, performing final sys.path modifications...
pex: PYTHONPATH contains:
pex:     /home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e
pex:   * /home/jsirois/.pyenv/versions/3.11.11/lib/python311.zip
pex:     /home/jsirois/.pyenv/versions/3.11.11/lib/python3.11
pex:     /home/jsirois/.pyenv/versions/3.11.11/lib/python3.11/lib-dynload
pex:   * foo
pex:   * bar
pex:     /home/jsirois/.cache/pex/installed_wheels/0/274b1e6fc1b966d53976333eb90ac94cb07a450a700b455af9fbdf882244b30a/cowsay-6.1-py3-none-any.whl
pex:     /home/jsirois/.cache/pex/unzipped_pexes/1/e18d55d51b2bbad12f8e13eccd0de5cb994eee1e/.bootstrap
pex:   * - paths that do not exist or will be imported via zipimport
  ____
| Moo! |
  ====
    \
     \
       ^__^
       (oo)\_______
       (__)\       )\/\
           ||----w |
           ||     ||

Note the verbose lines just above the cow that start with pex: PYTHONPATH contains:.

@arrdem arrdem self-assigned this Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants