Skip to content

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jun 28, 2025

Summary

Uses the python version and environment selected in the Python extension as a fallback if the configuration doesn't specify a version or environment respectively.

Depends on astral-sh/ty-vscode#65

Closes astral-sh/ty-vscode#26

Test Plan

Screen.Recording.2025-07-10.at.14.23.50.mov

@MichaReiser MichaReiser added ty Multi-file analysis & type inference server Related to the LSP server labels Jun 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 28, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@github-actions
Copy link
Contributor

github-actions bot commented Jun 28, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Base automatically changed from micha/configuration-request to main July 2, 2025 09:01
@MichaReiser MichaReiser force-pushed the micha/python-extension-environment branch 2 times, most recently from fa7d08f to 0de50c6 Compare July 10, 2025 12:39
@MichaReiser MichaReiser marked this pull request as ready for review July 10, 2025 12:39
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.

Nice.

If the extension isn't able to give us the Python version but is able to give us the Python executable (for some reason), will we infer the Python version from that executable the same way as we would with a virtual environment that had been activated?

@MichaReiser
Copy link
Member Author

If the extension isn't able to give us the Python version but is able to give us the Python executable (for some reason), will we infer the Python version from that executable the same way as we would with a virtual environment that had been activated?

Yes, we would try to infer the version from the environment.

Copy link
Member

@dhruvmanila dhruvmanila 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!

Comment on lines +155 to +160
pub(crate) executable: PythonExecutable,
pub(crate) environment: Option<PythonEnvironment>,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need both the executable and the environment?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, this would probably allow us to show some kind of warning if the selected Python version in an editor is different than the configured Python version or even if there's a mismatch in the selected and used virtual environment even though the Python version might be the same.

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 mainly thought that I'm not to picky about what we should send to the server and let the server decide what information it needs

Comment on lines +710 to +712
ValueSource::PythonVSCodeExtension => {
unreachable!("Can't configure rules from the Python VSCode extension")
}
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this and other unreachables correctly, we need to decide whether we want to support these overrides (rules, includes, excludes) to be set in the editor settings, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Once we do, we'd need to implement the match arms.

@dhruvmanila
Copy link
Member

That's a smart way of testing this out!

@MichaReiser MichaReiser force-pushed the micha/python-extension-environment branch from 0de50c6 to 2e35bfd Compare July 14, 2025 09:30
@MichaReiser MichaReiser enabled auto-merge (squash) July 14, 2025 09:44
@MichaReiser MichaReiser merged commit 9002604 into main Jul 14, 2025
36 checks passed
@MichaReiser MichaReiser deleted the micha/python-extension-environment branch July 14, 2025 09:47
dcreager added a commit that referenced this pull request Jul 14, 2025
* dcreager/merge-arguments: (223 commits)
  fix docs
  Combine CallArguments and CallArgumentTypes
  [ty] Sync vendored typeshed stubs (#19334)
  [`refurb`] Make example error out-of-the-box (`FURB122`) (#19297)
  [refurb] Make example error out-of-the-box (FURB177) (#19309)
  [ty] ignore errors when reformatting codemodded typeshed (#19332)
  [ty] Provide docstrings for stdlib APIs when hovering over them in an IDE (#19311)
  [ty] Add virtual files to the only project database (#19322)
  Add t-string fixtures for rules that do not need to be modified (#19146)
  [ty] Remove `FileLookupError` (#19323)
  [ty] Fix handling of metaclasses in `object.<CURSOR>` completions
  [ty] Use an interval map for scopes by expression (#19025)
  [ty] List all `enum` members (#19283)
  [ty] Handle configuration errors in LSP more gracefully (#19262)
  [ty] Use python version and path from Python extension (#19012)
  [`pep8_naming`] Avoid false positives on standard library functions with uppercase names (`N802`) (#18907)
  Update Rust crate toml to 0.9.0 (#19320)
  [ty] Fix server version (#19284)
  Update NPM Development dependencies (#19319)
  Update taiki-e/install-action action to v2.56.13 (#19317)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the selected Python interpreter from the editor

4 participants