2024-03-12 17:11:50 -07:00
|
|
|
use pep508_rs::{MarkerEnvironment, StringVersion};
|
2024-02-15 11:19:46 -06:00
|
|
|
use uv_interpreter::Interpreter;
|
2024-01-03 11:20:45 -04:00
|
|
|
|
2024-03-12 17:11:50 -07:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2024-01-22 00:32:02 -06:00
|
|
|
pub struct PythonRequirement {
|
2024-01-03 11:20:45 -04:00
|
|
|
/// The installed version of Python.
|
2024-03-12 17:11:50 -07:00
|
|
|
installed: StringVersion,
|
2024-01-03 11:20:45 -04:00
|
|
|
/// The target version of Python; that is, the version of Python for which we are resolving
|
|
|
|
|
/// dependencies. This is typically the same as the installed version, but may be different
|
|
|
|
|
/// when specifying an alternate Python version for the resolution.
|
2024-03-12 17:11:50 -07:00
|
|
|
target: StringVersion,
|
2024-01-03 11:20:45 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-22 00:32:02 -06:00
|
|
|
impl PythonRequirement {
|
2024-06-02 21:33:18 -04:00
|
|
|
pub fn from_marker_environment(interpreter: &Interpreter, env: &MarkerEnvironment) -> Self {
|
2024-01-03 11:20:45 -04:00
|
|
|
Self {
|
2024-03-12 17:11:50 -07:00
|
|
|
installed: interpreter.python_full_version().clone(),
|
2024-06-02 21:33:18 -04:00
|
|
|
target: env.python_full_version().clone(),
|
2024-01-03 11:20:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-02 21:33:18 -04:00
|
|
|
pub fn from_interpreter(interpreter: &Interpreter) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
installed: interpreter.python_full_version().clone(),
|
|
|
|
|
target: interpreter.python_full_version().clone(),
|
|
|
|
|
}
|
2024-05-08 11:21:11 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-03 11:20:45 -04:00
|
|
|
/// Return the installed version of Python.
|
2024-03-12 17:11:50 -07:00
|
|
|
pub fn installed(&self) -> &StringVersion {
|
2024-01-22 00:32:02 -06:00
|
|
|
&self.installed
|
2024-01-03 11:20:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the target version of Python.
|
2024-03-12 17:11:50 -07:00
|
|
|
pub fn target(&self) -> &StringVersion {
|
2024-01-22 00:32:02 -06:00
|
|
|
&self.target
|
2024-01-03 11:20:45 -04:00
|
|
|
}
|
|
|
|
|
}
|