2024-05-21 15:37:23 -04:00
|
|
|
//! Find requested Python interpreters and query interpreters for information.
|
2023-11-23 09:57:33 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
2024-10-14 21:48:13 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
use uv_static::EnvVars;
|
|
|
|
|
|
2024-05-21 15:37:23 -04:00
|
|
|
pub use crate::discovery::{
|
2024-08-09 13:10:19 -05:00
|
|
|
find_python_installations, EnvironmentPreference, Error as DiscoveryError, PythonDownloads,
|
2024-10-02 13:10:45 -05:00
|
|
|
PythonNotFound, PythonPreference, PythonRequest, PythonSource, PythonVariant, VersionRequest,
|
2024-05-21 15:37:23 -04:00
|
|
|
};
|
2024-09-20 12:28:17 -05:00
|
|
|
pub use crate::environment::{InvalidEnvironment, InvalidEnvironmentKind, PythonEnvironment};
|
2024-06-14 13:03:16 -04:00
|
|
|
pub use crate::implementation::ImplementationName;
|
2024-07-08 04:01:35 +08:00
|
|
|
pub use crate::installation::{PythonInstallation, PythonInstallationKey};
|
2024-06-18 10:52:59 -04:00
|
|
|
pub use crate::interpreter::{Error as InterpreterError, Interpreter};
|
2024-05-14 14:33:44 -04:00
|
|
|
pub use crate::pointer_size::PointerSize;
|
2024-06-06 16:15:28 -04:00
|
|
|
pub use crate::prefix::Prefix;
|
2024-04-30 12:49:46 -05:00
|
|
|
pub use crate::python_version::PythonVersion;
|
2024-04-25 19:15:39 -04:00
|
|
|
pub use crate::target::Target;
|
2024-07-10 11:36:25 -04:00
|
|
|
pub use crate::version_files::{
|
2024-08-21 16:41:20 -05:00
|
|
|
PythonVersionFile, PYTHON_VERSIONS_FILENAME, PYTHON_VERSION_FILENAME,
|
2024-07-10 11:36:25 -04:00
|
|
|
};
|
2024-05-21 15:37:23 -04:00
|
|
|
pub use crate::virtualenv::{Error as VirtualEnvError, PyVenvConfiguration, VirtualEnvironment};
|
2024-07-19 13:19:28 -04:00
|
|
|
|
2024-05-21 15:37:23 -04:00
|
|
|
mod discovery;
|
2024-06-05 08:27:30 -04:00
|
|
|
pub mod downloads;
|
2024-04-30 12:49:46 -05:00
|
|
|
mod environment;
|
2024-05-02 06:55:01 -05:00
|
|
|
mod implementation;
|
2024-07-03 08:44:29 -04:00
|
|
|
mod installation;
|
2023-11-23 09:57:33 +01:00
|
|
|
mod interpreter;
|
2024-08-27 02:06:53 +02:00
|
|
|
mod libc;
|
2024-04-30 12:49:46 -05:00
|
|
|
pub mod managed;
|
2024-08-29 22:56:41 +02:00
|
|
|
#[cfg(windows)]
|
|
|
|
|
mod microsoft_store;
|
2024-05-02 06:55:01 -05:00
|
|
|
pub mod platform;
|
2024-05-14 14:33:44 -04:00
|
|
|
mod pointer_size;
|
2024-06-06 16:15:28 -04:00
|
|
|
mod prefix;
|
2024-08-29 22:48:22 +02:00
|
|
|
#[cfg(windows)]
|
2024-05-02 06:44:07 -05:00
|
|
|
mod py_launcher;
|
2024-04-30 12:49:46 -05:00
|
|
|
mod python_version;
|
2024-04-25 19:15:39 -04:00
|
|
|
mod target;
|
2024-06-17 14:54:22 -04:00
|
|
|
mod version_files;
|
2024-05-02 06:58:48 -05:00
|
|
|
mod virtualenv;
|
2023-11-23 09:57:33 +01:00
|
|
|
|
2024-05-21 15:37:23 -04:00
|
|
|
#[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> {
|
2024-10-14 21:48:13 +00:00
|
|
|
std::env::var_os(EnvVars::PWD)
|
2024-05-21 15:37:23 -04:00
|
|
|
.map(std::path::PathBuf::from)
|
2024-05-27 00:17:49 -04:00
|
|
|
.map(Ok)
|
2024-05-21 15:37:23 -04:00
|
|
|
.unwrap_or(std::env::current_dir())
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 09:57:33 +01:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
|
pub enum Error {
|
|
|
|
|
#[error(transparent)]
|
2024-05-21 15:37:23 -04:00
|
|
|
VirtualEnv(#[from] virtualenv::Error),
|
|
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Query(#[from] interpreter::Error),
|
|
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Discovery(#[from] discovery::Error),
|
|
|
|
|
|
2024-06-10 10:10:45 -04:00
|
|
|
#[error(transparent)]
|
2024-07-03 08:44:29 -04:00
|
|
|
ManagedPython(#[from] managed::Error),
|
2024-06-10 10:10:45 -04:00
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Download(#[from] downloads::Error),
|
|
|
|
|
|
2024-06-17 14:11:24 -04:00
|
|
|
// TODO(zanieb) We might want to ensure this is always wrapped in another type
|
|
|
|
|
#[error(transparent)]
|
2024-07-03 08:44:29 -04:00
|
|
|
KeyError(#[from] installation::PythonInstallationKeyError),
|
2024-06-17 14:11:24 -04:00
|
|
|
|
2024-05-21 15:37:23 -04:00
|
|
|
#[error(transparent)]
|
2024-07-03 08:44:29 -04:00
|
|
|
MissingPython(#[from] PythonNotFound),
|
2024-06-28 11:16:59 -04:00
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
MissingEnvironment(#[from] environment::EnvironmentNotFound),
|
2024-09-19 06:49:35 -05:00
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
InvalidEnvironment(#[from] environment::InvalidEnvironment),
|
2024-05-21 15:37:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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))]
|
2024-10-11 16:41:35 +02:00
|
|
|
mod tests;
|