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

Bugs in the activate_this.py script created by uv venv #3346

Closed
pfmoore opened this issue May 3, 2024 · 4 comments · Fixed by #3376
Closed

Bugs in the activate_this.py script created by uv venv #3346

pfmoore opened this issue May 3, 2024 · 4 comments · Fixed by #3376
Assignees
Labels
bug Something isn't working

Comments

@pfmoore
Copy link
Contributor

pfmoore commented May 3, 2024

If I do uv venv, the file .venv/Scripts/activate_this.py contains errors:

Too many closing parentheses:

    msg = "You must use exec(open(this_file).read(), {'__file__': this_file}))"

Invalid backslash escapes (this is on Windows):

for lib in "..\Lib\site-packages".split(os.pathsep):
@charliermarsh
Copy link
Member

Thanks, we vendored these from virtualenv and looks like the first one at least was fixed: pypa/virtualenv#2651

@charliermarsh charliermarsh added the bug Something isn't working label May 3, 2024
@charliermarsh
Copy link
Member

The second looks like our bug.

@AlexWaygood
Copy link
Member

AlexWaygood commented May 3, 2024

There's some other weirdness as well.

os.environ["VIRTUAL_ENV_PROMPT"] = "" or os.path.basename(base) # noqa: SIM222

Isn't that just exactly equivalent to this?

os.environ["VIRTUAL_ENV_PROMPT"] = os.path.basename(base)

site.addsitedir(path.decode("utf-8") if "" else path)
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]

Isn't that exactly equivalent to this?

     site.addsitedir(path) 
 sys.path[:] = sys.path[prev_length:] + sys.path[:prev_length] 

@konstin
Copy link
Member

konstin commented May 3, 2024

I think some parts were lost when copying the upstream (https://github.com/pypa/virtualenv/blob/01cc6fbeb9f6e4a261d3bcf292801d5959525870/src/virtualenv/activation/python/activate_this.py), i'll give this a proper a look on monday.

@charliermarsh charliermarsh self-assigned this May 4, 2024
charliermarsh added a commit that referenced this issue May 4, 2024
## Summary

Refreshes some of the activation scripts, and fixes some bugs in
`activate_this.py` that were likely the rest of some erroneous
copy-pasting.

Closes #3346.

## Test Plan

```
❯ python
Python 3.12.0 (main, Feb 28 2024, 09:44:16) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import httpx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'httpx'
>>> activator = '.venv/bin/activate_this.py'
>>> with open(activator) as f:
...     exec(f.read(), {'__file__': activator})
...
>>> import httpx
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants