-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Escape Windows paths with spaces in venv
activation command
#2223
Conversation
@charliermarsh In cmd.exe it would just be |
Yeah I can't figure out how to detect if it's PowerShell or CMD... Do you know of any way to do it? |
From an env perspective? Not that I'm aware of unfortunately. I did see some code rely on It's heuristic because a user could potentially modify PSModulePath to their system environment variables and it would break this detection, but without modifications it would work since PowerShell itself modifies PSModulePath on launch per docs and always prefixes three or more entries on startup (regardless of system env) since it's a special PowerShell variable. |
Thinking about the oposite angle (which might be simpler), an asnwer on the same SO also mentions cmd.exe always defines |
Example implementation of last comment in #2226 |
## Summary Follow up from discussion in #2223 Detect CMD.exe by checking if `PROMPT` env var is set on windows, otherwise assume it's PowerShell. Note, this will not work if user modifies their system env vars to include `PROMPT` by default or if they launch nested PowerShell from Command Prompt (e.g. `Developer PowerShell for VS 2022`). ## Test Plan Only tested locally, although we try to add some CI tests that specifically use CMD.exe Command Prompt ``` Microsoft Windows [Version 10.0.19044.3086] (c) Microsoft Corporation. All rights reserved. Z:\Users\samypr100\dev\uv>Z:\Users\samypr100\.cargo\bin\cargo.exe +stable run --color=always -- venv "Foo Bar" Finished dev [unoptimized + debuginfo] target(s) in 0.69s Running `target\debug\uv.exe venv "Foo Bar"` Using Python 3.12.2 interpreter at: Z:\Users\samypr100\AppData\Local\Programs\Python\Python312\python.exe Creating virtualenv at: Foo Bar Activate with: "Foo Bar\Scripts\activate" ``` Power Shell ``` Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS Z:\Users\samypr100\dev\uv>Z:\Users\samypr100\.cargo\bin\cargo.exe +stable run --color=always -- venv "Foo Bar" Finished dev [unoptimized + debuginfo] target(s) in 0.63s Running `target\debug\uv.exe venv "Foo Bar"` Using Python 3.12.2 interpreter at: Z:\Users\samypr100\AppData\Local\Programs\Python\Python312\python.exe Creating virtualenv at: Foo Bar Activate with: & "Foo Bar\Scripts\activate" ```
Summary
Ensure that we print
& "foo bar\Scripts\activate"
if necessary.