From 7e8ba2b68eeecd4f25424d0bdeb7dd48e1c36a49 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Sat, 10 May 2025 15:52:49 -0500 Subject: [PATCH] [ty] Remove vestigial `pyvenv.cfg` creation in mdtest (#18006) Following #17991, removes some of https://github.com/astral-sh/ruff/pull/17222 which is no longer strictly necessary. I don't actually think it's that ugly to have around? no strong feelings on retaining it or not. --- crates/ty_test/README.md | 18 ++++++------------ crates/ty_test/src/lib.rs | 16 ++-------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/crates/ty_test/README.md b/crates/ty_test/README.md index 6930a09528..e16b56ec49 100644 --- a/crates/ty_test/README.md +++ b/crates/ty_test/README.md @@ -314,9 +314,9 @@ typeshed = "/typeshed" For more details, take a look at the [custom-typeshed Markdown test]. -### Mocking a virtual environment +### Mocking a Python environment -Mdtest supports mocking a virtual environment for a specific test at an arbitrary location, again +Mdtest supports mocking a Python environment for a specific test at an arbitrary location, again using the `[environment]` configuration option: ````markdown @@ -326,16 +326,10 @@ python = ".venv" ``` ```` -ty will reject virtual environments that do not have valid `pyvenv.cfg` files at the -virtual-environment directory root (here, `.venv/pyvenv.cfg`). However, if a `pyvenv.cfg` file does -not have its contents specified by the test, mdtest will automatically generate one for you, to -make mocking a virtual environment more ergonomic. - -Mdtest also makes it easy to write Python packages to the mock virtual environment's -`site-packages` directory using the `` magic path segment. This would -otherwise be hard, due to the fact that the `site-packages` subdirectory in a virtual environment -is located at a different relative path depending on the platform the virtual environment was -created on. In the following test, mdtest will write the Python file to +Mdtest also makes it easy to write Python packages to the mock environment's `site-packages` +directory using the `` magic path segment. This would otherwise be hard, due +to the fact that the `site-packages` subdirectory in an environment is located at a different +relative path depending on the platform. In the following test, mdtest will write the Python file to `.venv/Lib/site-packages/foo.py` in its in-memory filesystem used for the test if the test is being executed on Windows, and `.venv/lib/python3.13/site-packages/foo.py` otherwise: diff --git a/crates/ty_test/src/lib.rs b/crates/ty_test/src/lib.rs index 43e6b14108..cc4e92130a 100644 --- a/crates/ty_test/src/lib.rs +++ b/crates/ty_test/src/lib.rs @@ -170,7 +170,6 @@ fn run_test( let mut typeshed_files = vec![]; let mut has_custom_versions_file = false; - let mut has_custom_pyvenv_cfg_file = false; let test_files: Vec<_> = test .files() @@ -196,9 +195,8 @@ fn run_test( } } else if let Some(python_path) = python_path { if let Ok(relative_path) = full_path.strip_prefix(python_path) { - if relative_path.as_str() == "pyvenv.cfg" { - has_custom_pyvenv_cfg_file = true; - } else { + // Construct the path to the site-packages directory + if relative_path.as_str() != "pyvenv.cfg" { let mut new_path = SystemPathBuf::new(); for component in full_path.components() { let component = component.as_str(); @@ -256,16 +254,6 @@ fn run_test( } } - if let Some(python_path) = python_path { - if !has_custom_pyvenv_cfg_file { - let pyvenv_cfg_file = python_path.join("pyvenv.cfg"); - let home_directory = SystemPathBuf::from(format!("/Python{python_version}")); - db.create_directory_all(&home_directory).unwrap(); - db.write_file(&pyvenv_cfg_file, format!("home = {home_directory}")) - .unwrap(); - } - } - let configuration = test.configuration(); let settings = ProgramSettings {