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

Pex external venv should copy wheel files #2313

Open
zmanji opened this issue Dec 29, 2023 · 0 comments
Open

Pex external venv should copy wheel files #2313

zmanji opened this issue Dec 29, 2023 · 0 comments

Comments

@zmanji
Copy link
Collaborator

zmanji commented Dec 29, 2023

Peeled out of #2312 (comment)

Thinking about it an external venv should copy files from the wheel cache instead of hardlinks / symlinks.

In my case I use pex to create venvs for tools like VSCode. I could choose to edit a file in a venv for debugging purposes and if I do, I inadvertently corrupt the wheel cache.

Example:

PEX_SCRIPT='pex3' pex venv create -vv --copies --force -d ./tenv  --no-build 'cowsay==6.1'

Then remove the first line (import re) of

./tenv/lib/python3.10/site-packages/cowsay/main.py

Then the venv is broken when I run:

./tenv/bin/cowsay -t 'test'
Traceback (most recent call last):
  File "/home/zmanji/tmp/./tenv/bin/cowsay", line 14, in <module>
    sys.exit(entry_point())
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/__main__.py", line 28, in cli
    char_funcs[args.character](args.text)
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/__init__.py", line 24, in func
    draw(str(text), char_lines)
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/main.py", line 54, in draw
    if len(re.sub(r'\s', '', text)) == 0:
NameError: name 're' is not defined

Even if I delete the venv and recreate it it still suffers from the same problem

rm -rf ./tenv 
PEX_SCRIPT='pex3' pex venv create -vv --copies --force -d ./tenv  --no-build 'cowsay==6.1'
./tenv/bin/cowsay -t 'test'  
Traceback (most recent call last):
  File "/home/zmanji/tmp/./tenv/bin/cowsay", line 14, in <module>
    sys.exit(entry_point())
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/__main__.py", line 28, in cli
    char_funcs[args.character](args.text)
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/__init__.py", line 24, in func
    draw(str(text), char_lines)
  File "/home/zmanji/tmp/tenv/lib/python3.10/site-packages/cowsay/main.py", line 54, in draw
    if len(re.sub(r'\s', '', text)) == 0:
NameError: name 're' is not defined

The only way to fix this is to delete the pex wheel cache.

A way to fix this is to overload the existing --copies flag to also copy files from the wheel cache or to introduce another flag to signal this and change this function
https://github.com/pantsbuild/pex/blob/4eb5c9aa25c6a695bf55263ab239189b720cebaf/pex/pep_376.py#L350-L404

to do copies instead of links.

@zmanji zmanji changed the title Pex external venv Pex external venv should copy wheel files Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant