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

Print activation instructions for a venv after one has been created #1580

Merged
merged 13 commits into from
Feb 20, 2024

Conversation

0v00
Copy link
Contributor

@0v00 0v00 commented Feb 17, 2024

Summary

If the platform os matches Os::Windows then we provide the following prompt:

writeln!(
   printer,
   "Activate with .\\{}\\Scripts\\activate.ps1",
   path.normalized_display().cyan()
)

Otherwise we provide the following prompt:

writeln!(
  printer,
  "Activate with source {}/bin/activate",
  path.normalized_display().cyan()
)

I've added additional filters in crates/uv/tests/venv.rs so there shouldn't be issues on any of the CI runs (not sure what some of the Windows paths could look like, so these filters might need to be changed):

        (
            r".*?\\\.venv\\Scripts\\activate\.ps1", 
            "Activate with source /home/ferris/project/.venv/bin/activate"
        )

Test Plan

  • Ran tests in crates/uv/tests/venv.rs and updated snapshots.
  • Ran uv venv in a Docker container to test that the output is correct (running Ubuntu)

@@ -188,5 +189,22 @@ async fn venv_impl(
}
}

match &platform.os() {
Os::Windows => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about cmd users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can detect the current terminal type in Windows...

Copy link
Member

@zanieb zanieb Feb 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or if we should just show both?)

Copy link
Contributor Author

@0v00 0v00 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure if we can correctly/reliably detect the current terminal type in Windows, I've added in the below prompt:

Activate with:
- Powershell: .\.venv\Scripts\activate.ps1
- CMD: .\.venv\Scripts\activate.bat

and updated filters and snapshots

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexWaygood / @MichaReiser can you take over review of this?

Copy link
Member

@AlexWaygood AlexWaygood Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe typing .venv\Scripts\activate (omitting the file extension) should actually work on both PowerShell and CMD. (It does on my Windows machine!) If we just suggested doing that, it woudl avoid us having to figure out how to detect which Windows shell the user is using (and it's also fewer characters to have to type out ;).

If you're on CMD, it'll naturally pick up the .bat file; if you're on PowerShell, it'll naturally pick up the .ps1 file

Copy link
Contributor Author

@0v00 0v00 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that definitely helps make the prompt a lot cleaner/simpler. Have updated it.

crates/uv/src/commands/venv.rs Outdated Show resolved Hide resolved
@0v00 0v00 requested a review from zanieb February 19, 2024 01:42
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

crates/uv/src/commands/venv.rs Show resolved Hide resolved
@AlexWaygood
Copy link
Member

I tested locally with zsh on my mac, CMD on my Windows PC, and PowerShell on my Windows PC. All looked good!

@AlexWaygood AlexWaygood changed the title Prompt activation after uv venv has successfully run Print activation instructions for a venv after one has been created Feb 20, 2024
@AlexWaygood AlexWaygood merged commit 7741e1c into astral-sh:main Feb 20, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv venv does not suggest how to activate
4 participants