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

Detect current venv when uv is invoked from within a virtualenv #3379

Merged
merged 3 commits into from
May 5, 2024

Conversation

gotcha
Copy link
Contributor

@gotcha gotcha commented May 5, 2024

Fixes #3378

Does this still demands a test ?

@charliermarsh
Copy link
Member

Thanks, this looks reasonable to me.

@charliermarsh charliermarsh added the bug Something isn't working label May 5, 2024
@charliermarsh charliermarsh changed the title Detect current venv if called from within. Detect current venv when uv is invoked from within a virtualenv May 5, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) May 5, 2024 22:44
@charliermarsh charliermarsh merged commit ef92c38 into astral-sh:main May 5, 2024
43 checks passed
Copy link
Contributor Author

@gotcha gotcha left a comment

Choose a reason for hiding this comment

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

Still have questions...

/// Finds a `.venv` directory in the current or any parent directory.
/// Checks if the working directory is a virtual environment.
///
/// If not, finds a `.venv` directory in the current or any parent directory.
pub(crate) fn virtualenv_from_working_dir() -> Result<Option<PathBuf>, Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for merging !

The comment is not in line with the strategy.

Should I make a PR or let you fix it ?

Copy link
Member

Choose a reason for hiding this comment

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

if dir.join("pyvenv.cfg").is_file() {
debug!("Found a virtualenv at: {}", dir.display());
return Ok(Some(dir.to_path_buf()));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the reasoning behind moving the check for pyvenv.cfg before search for .venv to after the search ?

Copy link
Member

Choose a reason for hiding this comment

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

The main thing I wanted to change here was looking in ancestor directories, so that if you're in .venv/bin, we still find the current venv. Whether this check comes before or after the // Search for a .venv directory. step is somewhat less clear, that's a weird situation (you have a nested venv within a venv).

Copy link
Member

Choose a reason for hiding this comment

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

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 this pull request may close these issues.

uvshould not complain about a missing virtual env when called from a non activated virtual environment.
2 participants