[ty] Introduce and use System::env_var for better test isolation (#18538)
Some checks failed
CI / cargo test (linux) (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / benchmarks (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
[ty Playground] Release / publish (push) Has been cancelled

This commit is contained in:
Micha Reiser 2025-06-07 19:56:58 +02:00 committed by GitHub
parent 0c20010bb9
commit 86e5a311f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 2 deletions

View file

@ -171,6 +171,21 @@ pub trait System: Debug {
PatternError, PatternError,
>; >;
/// Fetches the environment variable `key` from the current process.
///
/// # Errors
///
/// Returns [`std::env::VarError::NotPresent`] if:
/// - The variable is not set.
/// - The variable's name contains an equal sign or NUL (`'='` or `'\0'`).
///
/// Returns [`std::env::VarError::NotUnicode`] if the variable's value is not valid
/// Unicode.
fn env_var(&self, name: &str) -> std::result::Result<String, std::env::VarError> {
let _ = name;
Err(std::env::VarError::NotPresent)
}
fn as_any(&self) -> &dyn std::any::Any; fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any; fn as_any_mut(&mut self) -> &mut dyn std::any::Any;

View file

@ -214,6 +214,10 @@ impl System for OsSystem {
}) })
}))) })))
} }
fn env_var(&self, name: &str) -> std::result::Result<String, std::env::VarError> {
std::env::var(name)
}
} }
impl OsSystem { impl OsSystem {

View file

@ -192,12 +192,12 @@ impl Options {
PythonPath::sys_prefix(python_path.absolute(project_root, system), origin) PythonPath::sys_prefix(python_path.absolute(project_root, system), origin)
}) })
.or_else(|| { .or_else(|| {
std::env::var("VIRTUAL_ENV").ok().map(|virtual_env| { system.env_var("VIRTUAL_ENV").ok().map(|virtual_env| {
PythonPath::sys_prefix(virtual_env, SysPrefixPathOrigin::VirtualEnvVar) PythonPath::sys_prefix(virtual_env, SysPrefixPathOrigin::VirtualEnvVar)
}) })
}) })
.or_else(|| { .or_else(|| {
std::env::var("CONDA_PREFIX").ok().map(|path| { system.env_var("CONDA_PREFIX").ok().map(|path| {
PythonPath::sys_prefix(path, SysPrefixPathOrigin::CondaPrefixVar) PythonPath::sys_prefix(path, SysPrefixPathOrigin::CondaPrefixVar)
}) })
}) })

View file

@ -247,6 +247,10 @@ impl System for LSPSystem {
fn case_sensitivity(&self) -> CaseSensitivity { fn case_sensitivity(&self) -> CaseSensitivity {
self.os_system.case_sensitivity() self.os_system.case_sensitivity()
} }
fn env_var(&self, name: &str) -> std::result::Result<String, std::env::VarError> {
self.os_system.env_var(name)
}
} }
fn not_a_text_document(path: impl Display) -> std::io::Error { fn not_a_text_document(path: impl Display) -> std::io::Error {