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

A loose layout, venv-with-symlink PEX creates brittle symlinks #2023

Closed
thejcannon opened this issue Jan 3, 2023 · 7 comments · Fixed by #2033
Closed

A loose layout, venv-with-symlink PEX creates brittle symlinks #2023

thejcannon opened this issue Jan 3, 2023 · 7 comments · Fixed by #2033
Assignees
Labels

Comments

@thejcannon
Copy link
Contributor

Pex version 2.1.113

I found this through Pants, but ultimately seems like a PEX issue/fix.

$ pex --no-venv-copies --layout=loose --venv prepend awscli --script aws -o  awscli.pex
$ python awscli.pex help
<help output>
$ mv awscli.pex awscli2.pex/
$ python awscli2.pex
Traceback (most recent call last):
  File "/home/josh/.pex/venvs/ea7cb7998ed2db4f784178989a4034013cd10e01/ddab8011daaee380698ac2fb9701af18c90c03f6/bin/aws", line 19, in <module>
    import awscli.clidriver
ModuleNotFoundError: No module named 'awscli

See also:

$ ls -l /home/josh/.pex/venvs/ea7cb7998ed2db4f784178989a4034013cd10e01/ddab8011daaee380698ac2fb9701af18c90c03f6/lib/python3.8/site-packages/awscli
lrwxrwxrwx 1 josh josh 107 Jan  3 11:49 /home/josh/.pex/venvs/ea7cb7998ed2db4f784178989a4034013cd10e01/ddab8011daaee380698ac2fb9701af18c90c03f6/lib/python3.8/site-packages/awscli -> ../../../../../../../../../<CWD>/awscli.pex/.deps/awscli-1.27.41-py3-none-any.whl/awscli

In Pants-land, this manifests as being a symlink to an ephemeral Pants sandbox which has since gone bye-bye.


What I might expect is that on first run, the wheels get copied into the PEX root and then the venv symlinks to the extracted wheels in the pex root so moving/deleting the original pex doesn't invalidate the venv.

@thejcannon thejcannon changed the title A loose layout, venv-with-symlink PEX creates birttle symlinks A loose layout, venv-with-symlink PEX creates brittle symlinks Jan 3, 2023
@jsirois
Copy link
Member

jsirois commented Jan 3, 2023

Pants doesn't use loose, only packed. The same problem likely exists there though. Is loose use new or not a relevant / accurate detail here?

@thejcannon
Copy link
Contributor Author

I'm declaring a pex_binary so the keys are all mine.

@thejcannon
Copy link
Contributor Author

I also couldn't reproduce with packed or zipapp layouts, so I do think it is relevant.

@jsirois
Copy link
Member

jsirois commented Jan 3, 2023

Gotcha. Thanks for the extra context.

Bug fix aside, if you're willing to share the use case, loose -> venv. Its supported and needs to be fixed, but also the oddest use case in the matrix of layouts x execution mode so I'm curious.

@thejcannon
Copy link
Contributor Author

No specific use-case other than "was using loose, then tacked on venv". Our local fix is to drop the "loose".

@jsirois
Copy link
Member

jsirois commented Jan 3, 2023

What was the loose for in the 1st place though? I am aware of 0 loose users (Pants would be if sandboxing were performant); so I'd love to learn what problems it helps people with.

@thejcannon
Copy link
Contributor Author

The PR that introduced it lacks context 😒 If I had to guess it was either to workaround a bug or was a result of "bang on it until it works"

@jsirois jsirois added the bug label Jan 4, 2023
@jsirois jsirois self-assigned this Jan 9, 2023
@jsirois jsirois mentioned this issue Jan 9, 2023
3 tasks
jsirois added a commit to jsirois/pex that referenced this issue Jan 9, 2023
Both packed and zipped PEXes undergo an unzip into the PEX_ROOT prior to
any other action, establishing a known private cache of their contents.
Loose PEXes skip this step and run directly from their loose contents.
This is fine and speedy for the "zipapp" execution mode, but leads to an
incorrect venv cache in symlink mode where venv entries symlink back out
to the loose PEX and can thus be invalidated by moves outside Pex
control. Force loose PEXes in `--venv` mode to use copies so that their
cached venv is robust to external moves.

Fixes pex-tool#2023
jsirois added a commit that referenced this issue Jan 10, 2023
Both packed and zipped PEXes undergo an unzip into the PEX_ROOT prior to
any other action, establishing a known private cache of their contents.
Loose PEXes skip this step and run directly from their loose contents.
This is fine and speedy for the "zipapp" execution mode, but leads to an
incorrect venv cache in symlink mode where venv entries symlink back out
to the loose PEX and can thus be invalidated by moves outside Pex
control. Force loose PEXes in `--venv` mode to use copies so that their
cached venv is robust to external moves.

Fixes #2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants