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

No activate.bat Created with venv Command on Windows #1471

Closed
bwanshoom opened this issue Feb 16, 2024 · 0 comments · Fixed by #1523
Closed

No activate.bat Created with venv Command on Windows #1471

bwanshoom opened this issue Feb 16, 2024 · 0 comments · Fixed by #1523
Assignees
Labels
compatibility Compatibility with a specification or another tool windows Specific to the Windows platform

Comments

@bwanshoom
Copy link

activate.ps1 is created, but the Python module venv also creates activate.bat. Some of us still use cmd-compatible shells. It would be nice for compatibility sake for uv to create it as well.

@AlexWaygood AlexWaygood added the windows Specific to the Windows platform label Feb 16, 2024
@MichaReiser MichaReiser added the compatibility Compatibility with a specification or another tool label Feb 16, 2024
@MichaReiser MichaReiser self-assigned this Feb 16, 2024
charliermarsh pushed a commit that referenced this issue Feb 17, 2024
## Sumamry

This PR adds the `activation.bat`, `deactivation.bat` and `pyenv.bat`
files to add support for using uv from CMD.

This PR further fixes an issue with our trampoline implementation where
calling an executable like `black` failed:

```
(venv) C:\Users\Micha\astral\test>where black
C:\Users\Micha\astral\test\.venv\Scripts\black.exe

(venv) C:\Users\Micha\astral\test>black
C:\Users\Micha\AppData\Local\Programs\Python\Python312\python.exe: can't open file 'C:\\Users\\Micha\\astral\\test\\black': [Errno 2] No such file or directory
```

The issue was that CMD doesn't extend `black` to its full path before
passing it to the trampoline and our trampoline generated the command
`<python> black` instead of `<python> .venv/Scripts/black`, and Python
can't find `black` in the project directory.

This PR fixes this by using the full executable name (that we already
parsed out to discover the Python version). This adds one complication,
we need to preserve the arguments without repeating the executable name
that is the first argument.
One option is to use
[`CommandLineToArgvW`](https://learn.microsoft.com/de-de/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw)
and then serialize the arguments 1.. to a string again. I decided
against that. Win32 API calls are easy to get wrong. That's why I
implemented the parsing rules specified in
[`CommandLineToArgvW`](https://learn.microsoft.com/de-de/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw)
to skip the first argument.

Fixes #1471

## Test Plan


https://github.com/astral-sh/uv/assets/1203881/bdb537b6-97c8-4f7e-bb4a-3a614eb5e0f6

Powershell continues to work


https://github.com/astral-sh/uv/assets/1203881/6c806477-a7c6-4047-9ffc-5ed91c6f1c84

I haven't been able to test the aarch binaries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants