Auto-generate environment variable references for ty (#19205)

## Summary

This PR mirrors the environment variable implementation we have in uv:
efc361223c/crates/uv-static/src/env_vars.rs (L6-L7).

See: https://github.com/astral-sh/ty/issues/773.
This commit is contained in:
Charlie Marsh 2025-07-08 10:48:31 -04:00 committed by GitHub
parent 149350bf39
commit 3ee3434187
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 458 additions and 14 deletions

View file

@ -23,6 +23,7 @@ use ruff_python_ast::PythonVersion;
use ruff_python_trivia::Cursor;
use ruff_source_file::{LineIndex, OneIndexed, SourceCode};
use ruff_text_size::{TextLen, TextRange};
use ty_static::EnvVars;
type SitePackagesDiscoveryResult<T> = Result<T, SitePackagesDiscoveryError>;
@ -149,7 +150,7 @@ impl PythonEnvironment {
PythonEnvironment::new(path, origin, system)
}
if let Ok(virtual_env) = system.env_var("VIRTUAL_ENV") {
if let Ok(virtual_env) = system.env_var(EnvVars::VIRTUAL_ENV) {
return resolve_environment(
system,
SystemPath::new(&virtual_env),
@ -158,7 +159,7 @@ impl PythonEnvironment {
.map(Some);
}
if let Ok(conda_env) = system.env_var("CONDA_PREFIX") {
if let Ok(conda_env) = system.env_var(EnvVars::CONDA_PREFIX) {
return resolve_environment(
system,
SystemPath::new(&conda_env),