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

Rename venv-path to python #16347

Merged
merged 3 commits into from
Feb 24, 2025
Merged

Rename venv-path to python #16347

merged 3 commits into from
Feb 24, 2025

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Feb 24, 2025

Summary

Closes #15530

This PR renames the CLI argument --venv-path and the environment.venv-path option to --python and environment.python
to align with uv's python option.

The Python option takes a path to a virtual environment or Python system installation (any directory that has a lib/python3.x/site-packages subdirectory on unix).

This PR doesn't yet add support for:

  • Specifying a path to a python executable
  • Specifying a python version

uv supports both (and more). The CLI proposal does mention that we should support python executables. I recommend to add support for this, if wanted, as a separate PR

Test plan

I ran Red Knot over Black and both main and this PR produce the same diagnostic when pointing it to a venv path.

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Feb 24, 2025
@MichaReiser MichaReiser marked this pull request as ready for review February 24, 2025 14:28
}
})
.transpose()?
.unwrap_or_else(|| cli_base_path.clone());
.unwrap_or_else(|| cwd.clone());
Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed while testing that relative path arguments on the CLI were incorrectly anchored to the project directory instead of the cwd. For example, the python path for --project ../test --python ../test/venv resolved to ../test/test/venv.

Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you.

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.

Looks great, thank you!

@@ -69,7 +69,7 @@ fn run_check(args: CheckCommand) -> anyhow::Result<ExitStatus> {
let _guard = setup_tracing(verbosity)?;

// The base path to which all CLI arguments are relative to.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems out of date (or at least badly located) now?

Copy link
Member Author

@MichaReiser MichaReiser Feb 24, 2025

Choose a reason for hiding this comment

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

This is still true. We relativize the paths in RelativePathBuf::absolute. The main change here is that we don't use the project path as cwd when it is set (which is incorrect)

@carljm
Copy link
Contributor

carljm commented Feb 24, 2025

any directory that has a site-packages sub-directory

This is from the PR summary, not the PR itself, but in case it represents an actual misunderstanding: site-packages is not a direct subdirectory of venvs or of system Python installations, it always lives under lib/pythonX.X/site-packages. (Or maybe you meant "sub-directory" in the transitive sense?)

@MichaReiser
Copy link
Member Author

This is from the PR summary, not the PR itself, but in case it represents an actual misunderstanding: site-packages is not a direct subdirectory of venvs or of system Python installations, it always lives under lib/pythonX.X/site-packages. (Or maybe you meant "sub-directory" in the transitive sense?

You give me too much credit. I was just still confused by how the directory structure looks.

@MichaReiser MichaReiser merged commit 4732c58 into main Feb 24, 2025
21 checks passed
@MichaReiser MichaReiser deleted the micha/rename-venv-path-to-python branch February 24, 2025 18:41
dcreager added a commit that referenced this pull request Feb 25, 2025
* main: (38 commits)
  [red-knot] Use arena-allocated association lists for narrowing constraints (#16306)
  [red-knot] Rewrite `Type::try_iterate()` to improve type inference and diagnostic messages (#16321)
  Add issue templates (#16213)
  Normalize inconsistent markdown headings in docstrings (#16364)
  [red-knot] Better diagnostics for method calls (#16362)
  [red-knot] Add argfile and windows glob path support (#16353)
  [red-knot] Handle pipe-errors gracefully (#16354)
  Rename `venv-path` to `python` (#16347)
  [red-knot] Fixup some formatting in `infer.rs` (#16348)
  [red-knot] Restrict visibility of more things in `class.rs` (#16346)
  [red-knot] Add diagnostic for class-object access to pure instance variables (#16036)
  Add `per-file-target-version` option (#16257)
  [PLW1507] Mark fix unsafe (#16343)
  [red-knot] Add a test to ensure that `KnownClass::try_from_file_and_name()` is kept up to date (#16326)
  Extract class and instance types (#16337)
  Re-order changelog entries for 0.9.7 (#16344)
  [red-knot] Add support for `@classmethod`s (#16305)
  Update Salsa (#16338)
  Update Salsa part 1 (#16340)
  Upgrade Rust toolchain to 1.85.0 (#16339)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[red-knot] Rename environment.site-packages to python
4 participants