Files
uv/crates/uv-python/src/lib.rs
T
samypr100 01c44af3c3 chore: unify all env vars used (#8151)
## Summary

This PR declares and documents all environment variables that are used
in one way or another in `uv`, either internally, or externally, or
transitively under a common struct.

I think over time as uv has grown there's been many environment
variables introduced. Its harder to know which ones exists, which ones
are missing, what they're used for, or where are they used across the
code. The docs only documents a handful of them, for others you'd have
to dive into the code and inspect across crates to know which crates
they're used on or where they're relevant.

This PR is a starting attempt to unify them, make it easier to discover
which ones we have, and maybe unlock future posibilities in automating
generating documentation for them.

I think we can split out into multiple structs later to better organize,
but given the high influx of PR's and possibly new environment variables
introduced/re-used, it would be hard to try to organize them all now
into their proper namespaced struct while this is all happening given
merge conflicts and/or keeping up to date.

I don't think this has any impact on performance as they all should
still be inlined, although it may affect local build times on changes to
the environment vars as more crates would likely need a rebuild. Lastly,
some of them are declared but not used in the code, for example those in
`build.rs`. I left them declared because I still think it's useful to at
least have a reference.

Did I miss any? Are their initial docs cohesive?

Note, `uv-static` is a terrible name for a new crate, thoughts? Others
considered `uv-vars`, `uv-consts`.

## Test Plan

Existing tests
2024-10-14 16:48:13 -05:00

92 lines
2.6 KiB
Rust

//! Find requested Python interpreters and query interpreters for information.
use thiserror::Error;
#[cfg(test)]
use uv_static::EnvVars;
pub use crate::discovery::{
find_python_installations, EnvironmentPreference, Error as DiscoveryError, PythonDownloads,
PythonNotFound, PythonPreference, PythonRequest, PythonSource, PythonVariant, VersionRequest,
};
pub use crate::environment::{InvalidEnvironment, InvalidEnvironmentKind, PythonEnvironment};
pub use crate::implementation::ImplementationName;
pub use crate::installation::{PythonInstallation, PythonInstallationKey};
pub use crate::interpreter::{Error as InterpreterError, Interpreter};
pub use crate::pointer_size::PointerSize;
pub use crate::prefix::Prefix;
pub use crate::python_version::PythonVersion;
pub use crate::target::Target;
pub use crate::version_files::{
PythonVersionFile, PYTHON_VERSIONS_FILENAME, PYTHON_VERSION_FILENAME,
};
pub use crate::virtualenv::{Error as VirtualEnvError, PyVenvConfiguration, VirtualEnvironment};
mod discovery;
pub mod downloads;
mod environment;
mod implementation;
mod installation;
mod interpreter;
mod libc;
pub mod managed;
#[cfg(windows)]
mod microsoft_store;
pub mod platform;
mod pointer_size;
mod prefix;
#[cfg(windows)]
mod py_launcher;
mod python_version;
mod target;
mod version_files;
mod virtualenv;
#[cfg(not(test))]
pub(crate) fn current_dir() -> Result<std::path::PathBuf, std::io::Error> {
std::env::current_dir()
}
#[cfg(test)]
pub(crate) fn current_dir() -> Result<std::path::PathBuf, std::io::Error> {
std::env::var_os(EnvVars::PWD)
.map(std::path::PathBuf::from)
.map(Ok)
.unwrap_or(std::env::current_dir())
}
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
VirtualEnv(#[from] virtualenv::Error),
#[error(transparent)]
Query(#[from] interpreter::Error),
#[error(transparent)]
Discovery(#[from] discovery::Error),
#[error(transparent)]
ManagedPython(#[from] managed::Error),
#[error(transparent)]
Download(#[from] downloads::Error),
// TODO(zanieb) We might want to ensure this is always wrapped in another type
#[error(transparent)]
KeyError(#[from] installation::PythonInstallationKeyError),
#[error(transparent)]
MissingPython(#[from] PythonNotFound),
#[error(transparent)]
MissingEnvironment(#[from] environment::EnvironmentNotFound),
#[error(transparent)]
InvalidEnvironment(#[from] environment::InvalidEnvironment),
}
// The mock interpreters are not valid on Windows so we don't have unit test coverage there
// TODO(zanieb): We should write a mock interpreter script that works on Windows
#[cfg(all(test, unix))]
mod tests;