Skip to content

Comments

[red-knot] Allow setting python in mdtests#17221

Merged
MichaReiser merged 1 commit intomainfrom
micha/mdtest-python
Apr 5, 2025
Merged

[red-knot] Allow setting python in mdtests#17221
MichaReiser merged 1 commit intomainfrom
micha/mdtest-python

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Apr 5, 2025

Summary

This PR extends the mdtest options to allow setting the environment.python option.

Test Plan

I let @AlexWaygood write a test and he'll tell me if it works 😆

@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Apr 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2025

mypy_primer results

No ecosystem changes detected ✅

@AlexWaygood
Copy link
Member

👍 the test I have locally passes when it's rebased on this branch

@AlexWaygood
Copy link
Member

thanks!

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 5, 2025

Oh no shoot, I messed it up locally. Actually it now fails with this when my PR branch is rebased onto this branch:

failures:

---- mdtest__import_relative stdout ----

thread 'mdtest__import_relative' panicked at crates/red_knot_test/src/lib.rs:247:6:
Failed to update Program settings in TestDb: .venv does not point to a directory
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@MichaReiser MichaReiser merged commit 1c652e6 into main Apr 5, 2025
23 checks passed
@MichaReiser MichaReiser deleted the micha/mdtest-python branch April 5, 2025 14:43
Comment on lines +233 to +239
python_path: PythonPath::KnownSitePackages(
configuration
.python()
.into_iter()
.map(SystemPath::to_path_buf)
.collect(),
),
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm still struggling to get my test to pass locally. I think this is incorrect because the python configuration setting is meant to point to the installation's sys.prefix value (e.g. .venv) but the KnownSitePackages variant of PythonPath is meant to hold the resolved site-packages subdirectory of sys.prefix (e.g. .venv/lib/python3.13/site-packages if it's a Python 3.13 virtual environment)

Copy link
Member

Choose a reason for hiding this comment

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

I think this should be using PythonPath::SysPrefix instead

Copy link
Member

Choose a reason for hiding this comment

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

I'll fix this as part of my PR

Copy link
Member Author

@MichaReiser MichaReiser Apr 5, 2025

Choose a reason for hiding this comment

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

🤦 yes, this should be SysPrefix, at least if it should mirror the CLI

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm writing a fix!

AlexWaygood added a commit that referenced this pull request Apr 6, 2025
…ges` test as an mdtest (#17222)

## Summary

This PR does the following things:
- Fixes the `python` configuration setting for mdtest (added in
#17221) so that it expects a path
pointing to a venv's `sys.prefix` variable rather than the a path
pointing to the venv's `site-packages` subdirectory. This brings the
`python` setting in mdtest in sync with our CLI `--python` flag.
- Tweaks mdtest so that it automatically creates a valid `pyvenv.cfg`
file for you if you don't specify one. This makes it much more ergonomic
to write an mdtest with a custom `python` setting: red-knot will reject
a `python` setting that points to a directory that doesn't have a
`pyvenv.cfg` file in it
- Tweaks mdtest so that it doesn't check a custom `pyvenv.cfg` as Python
source code if you _do_ add a custom `pyvenv.cfg` file for your mock
virtual environment in an mdtest. (You get a lot of diagnostics about
Python syntax errors in the `pyvenv.cfg` file, otherwise!)
- Rewrites the test added in
#17178 as an mdtest, and deletes
the original test that was added in that PR

## Test Plan

I verified that the new mdtest fails if I revert the changes to
`resolver.rs` that were added in
#17178
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants