pep508: un-export fields for MarkerEnvironment

We now use the getters and setters everywhere.

There were some places where we wanted to build a `MarkerEnvironment`
out of whole cloth, usually in tests. To facilitate those use cases, we
add a `MarkerEnvironmentBuilder` that provides a convenient constructor.
It's basically like a `MarkerEnvironment::new`, but with named
parameters. That's useful here because there are so many fields (and
they many have the same type).
This commit is contained in:
Andrew Gallant 2024-05-08 19:01:44 -04:00 committed by Andrew Gallant
parent be12cfb2b8
commit 7d67b7bb49
11 changed files with 198 additions and 169 deletions

View file

@ -38,13 +38,12 @@ criterion_main!(uv);
mod resolver { mod resolver {
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr;
use anyhow::Result; use anyhow::Result;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use distribution_types::{IndexLocations, Requirement, Resolution, SourceDist}; use distribution_types::{IndexLocations, Requirement, Resolution, SourceDist};
use pep508_rs::{MarkerEnvironment, StringVersion}; use pep508_rs::{MarkerEnvironment, MarkerEnvironmentBuilder};
use platform_tags::{Arch, Os, Platform, Tags}; use platform_tags::{Arch, Os, Platform, Tags};
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::RegistryClient; use uv_client::RegistryClient;
@ -58,19 +57,19 @@ mod resolver {
}; };
static MARKERS: Lazy<MarkerEnvironment> = Lazy::new(|| { static MARKERS: Lazy<MarkerEnvironment> = Lazy::new(|| {
MarkerEnvironment { MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "cpython".to_string(), implementation_name: "cpython",
implementation_version: StringVersion::from_str("3.11.5").unwrap(), implementation_version: "3.11.5",
os_name: "posix".to_string(), os_name: "posix",
platform_machine: "arm64".to_string(), platform_machine: "arm64",
platform_python_implementation: "CPython".to_string(), platform_python_implementation: "CPython",
platform_release: "21.6.0".to_string(), platform_release: "21.6.0",
platform_system: "Darwin".to_string(), platform_system: "Darwin",
platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000".to_string(), platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000",
python_full_version: StringVersion::from_str("3.11.5").unwrap(), python_full_version: "3.11.5",
python_version: StringVersion::from_str("3.11").unwrap(), python_version: "3.11",
sys_platform: "darwin".to_string(), sys_platform: "darwin",
} }).unwrap()
}); });
static PLATFORM: Platform = Platform::new( static PLATFORM: Platform = Platform::new(

View file

@ -40,8 +40,8 @@ use unicode_width::UnicodeWidthChar;
use url::Url; use url::Url;
pub use marker::{ pub use marker::{
MarkerEnvironment, MarkerExpression, MarkerOperator, MarkerTree, MarkerValue, MarkerEnvironment, MarkerEnvironmentBuilder, MarkerExpression, MarkerOperator, MarkerTree,
MarkerValueString, MarkerValueVersion, MarkerWarningKind, StringVersion, MarkerValue, MarkerValueString, MarkerValueVersion, MarkerWarningKind, StringVersion,
}; };
#[cfg(feature = "pyo3")] #[cfg(feature = "pyo3")]
use pep440_rs::PyVersion; use pep440_rs::PyVersion;

View file

@ -21,7 +21,7 @@ use pyo3::{
}; };
use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use pep440_rs::{Version, VersionPattern, VersionSpecifier}; use pep440_rs::{Version, VersionParseError, VersionPattern, VersionSpecifier};
use uv_normalize::ExtraName; use uv_normalize::ExtraName;
use crate::cursor::Cursor; use crate::cursor::Cursor;
@ -311,12 +311,12 @@ pub struct StringVersion {
} }
impl FromStr for StringVersion { impl FromStr for StringVersion {
type Err = String; type Err = VersionParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self { Ok(Self {
string: s.to_string(), string: s.to_string(),
version: Version::from_str(s).map_err(|e| e.to_string())?, version: Version::from_str(s)?,
}) })
} }
} }
@ -363,49 +363,49 @@ impl Deref for StringVersion {
#[derive(Clone, Debug, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "pyo3", pyclass(get_all, module = "pep508"))] #[cfg_attr(feature = "pyo3", pyclass(get_all, module = "pep508"))]
pub struct MarkerEnvironment { pub struct MarkerEnvironment {
pub implementation_name: String, implementation_name: String,
pub implementation_version: StringVersion, implementation_version: StringVersion,
pub os_name: String, os_name: String,
pub platform_machine: String, platform_machine: String,
pub platform_python_implementation: String, platform_python_implementation: String,
pub platform_release: String, platform_release: String,
pub platform_system: String, platform_system: String,
pub platform_version: String, platform_version: String,
pub python_full_version: StringVersion, python_full_version: StringVersion,
pub python_version: StringVersion, python_version: StringVersion,
pub sys_platform: String, sys_platform: String,
} }
impl MarkerEnvironment { impl MarkerEnvironment {
/// Returns of the PEP 440 version typed value of the key in the current environment /// Returns of the PEP 440 version typed value of the key in the current environment
pub fn get_version(&self, key: &MarkerValueVersion) -> &Version { pub fn get_version(&self, key: &MarkerValueVersion) -> &Version {
match key { match key {
MarkerValueVersion::ImplementationVersion => &self.implementation_version.version, MarkerValueVersion::ImplementationVersion => &self.implementation_version().version,
MarkerValueVersion::PythonFullVersion => &self.python_full_version.version, MarkerValueVersion::PythonFullVersion => &self.python_full_version().version,
MarkerValueVersion::PythonVersion => &self.python_version.version, MarkerValueVersion::PythonVersion => &self.python_version().version,
} }
} }
/// Returns of the stringly typed value of the key in the current environment /// Returns of the stringly typed value of the key in the current environment
pub fn get_string(&self, key: &MarkerValueString) -> &str { pub fn get_string(&self, key: &MarkerValueString) -> &str {
match key { match key {
MarkerValueString::ImplementationName => &self.implementation_name, MarkerValueString::ImplementationName => self.implementation_name(),
MarkerValueString::OsName | MarkerValueString::OsNameDeprecated => &self.os_name, MarkerValueString::OsName | MarkerValueString::OsNameDeprecated => self.os_name(),
MarkerValueString::PlatformMachine | MarkerValueString::PlatformMachineDeprecated => { MarkerValueString::PlatformMachine | MarkerValueString::PlatformMachineDeprecated => {
&self.platform_machine self.platform_machine()
} }
MarkerValueString::PlatformPythonImplementation MarkerValueString::PlatformPythonImplementation
| MarkerValueString::PlatformPythonImplementationDeprecated | MarkerValueString::PlatformPythonImplementationDeprecated
| MarkerValueString::PythonImplementationDeprecated => { | MarkerValueString::PythonImplementationDeprecated => {
&self.platform_python_implementation self.platform_python_implementation()
} }
MarkerValueString::PlatformRelease => &self.platform_release, MarkerValueString::PlatformRelease => self.platform_release(),
MarkerValueString::PlatformSystem => &self.platform_system, MarkerValueString::PlatformSystem => self.platform_system(),
MarkerValueString::PlatformVersion | MarkerValueString::PlatformVersionDeprecated => { MarkerValueString::PlatformVersion | MarkerValueString::PlatformVersionDeprecated => {
&self.platform_version self.platform_version()
} }
MarkerValueString::SysPlatform | MarkerValueString::SysPlatformDeprecated => { MarkerValueString::SysPlatform | MarkerValueString::SysPlatformDeprecated => {
&self.sys_platform self.sys_platform()
} }
} }
} }
@ -643,7 +643,7 @@ impl MarkerEnvironment {
/// ///
/// See also [`MarkerEnvironment::python_full_version`]. /// See also [`MarkerEnvironment::python_full_version`].
#[inline] #[inline]
pub fn with_python(self, value: impl Into<StringVersion>) -> MarkerEnvironment { pub fn with_python_version(self, value: impl Into<StringVersion>) -> MarkerEnvironment {
MarkerEnvironment { MarkerEnvironment {
python_version: value.into(), python_version: value.into(),
..self ..self
@ -791,6 +791,50 @@ impl MarkerEnvironment {
} }
} }
/// A builder for constructing a marker environment.
///
/// A value of this type can be fallibly converted to a full
/// [`MarkerEnvironment`] via `MarkerEnvironment::try_from`. This can fail when
/// the version strings given aren't valid.
///
/// The main utility of this type is for constructing dummy or test environment
/// values.
#[allow(missing_docs)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct MarkerEnvironmentBuilder<'a> {
pub implementation_name: &'a str,
pub implementation_version: &'a str,
pub os_name: &'a str,
pub platform_machine: &'a str,
pub platform_python_implementation: &'a str,
pub platform_release: &'a str,
pub platform_system: &'a str,
pub platform_version: &'a str,
pub python_full_version: &'a str,
pub python_version: &'a str,
pub sys_platform: &'a str,
}
impl<'a> TryFrom<MarkerEnvironmentBuilder<'a>> for MarkerEnvironment {
type Error = VersionParseError;
fn try_from(builder: MarkerEnvironmentBuilder<'a>) -> Result<Self, Self::Error> {
Ok(MarkerEnvironment {
implementation_name: builder.implementation_name.to_string(),
implementation_version: builder.implementation_version.parse()?,
os_name: builder.os_name.to_string(),
platform_machine: builder.platform_machine.to_string(),
platform_python_implementation: builder.platform_python_implementation.to_string(),
platform_release: builder.platform_release.to_string(),
platform_system: builder.platform_system.to_string(),
platform_version: builder.platform_version.to_string(),
python_full_version: builder.python_full_version.parse()?,
python_version: builder.python_version.parse()?,
sys_platform: builder.sys_platform.to_string(),
})
}
}
/// Represents one clause such as `python_version > "3.8"` in the form /// Represents one clause such as `python_version > "3.8"` in the form
/// ```text /// ```text
/// <a name from the PEP508 list | a string> <an operator> <a name from the PEP508 list | a string> /// <a name from the PEP508 list | a string> <an operator> <a name from the PEP508 list | a string>
@ -1736,7 +1780,7 @@ mod test {
use uv_normalize::ExtraName; use uv_normalize::ExtraName;
use crate::marker::{MarkerEnvironment, StringVersion}; use crate::marker::{MarkerEnvironment, MarkerEnvironmentBuilder};
use crate::{ use crate::{
MarkerExpression, MarkerOperator, MarkerTree, MarkerValue, MarkerValueString, MarkerExpression, MarkerOperator, MarkerTree, MarkerValue, MarkerValueString,
MarkerValueVersion, MarkerValueVersion,
@ -1747,21 +1791,20 @@ mod test {
} }
fn env37() -> MarkerEnvironment { fn env37() -> MarkerEnvironment {
let v37 = StringVersion::from_str("3.7").unwrap(); MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "",
MarkerEnvironment { implementation_version: "3.7",
implementation_name: String::new(), os_name: "linux",
implementation_version: v37.clone(), platform_machine: "",
os_name: "linux".to_string(), platform_python_implementation: "",
platform_machine: String::new(), platform_release: "",
platform_python_implementation: String::new(), platform_system: "",
platform_release: String::new(), platform_version: "",
platform_system: String::new(), python_full_version: "3.7",
platform_version: String::new(), python_version: "3.7",
python_full_version: v37.clone(), sys_platform: "linux",
python_version: v37, })
sys_platform: "linux".to_string(), .unwrap()
}
} }
/// Copied from <https://github.com/pypa/packaging/blob/85ff971a250dc01db188ef9775499c15553a8c95/tests/test_markers.py#L175-L221> /// Copied from <https://github.com/pypa/packaging/blob/85ff971a250dc01db188ef9775499c15553a8c95/tests/test_markers.py#L175-L221>
@ -1803,20 +1846,20 @@ mod test {
#[test] #[test]
fn test_marker_evaluation() { fn test_marker_evaluation() {
let v27 = StringVersion::from_str("2.7").unwrap(); let env27 = MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
let env27 = MarkerEnvironment { implementation_name: "",
implementation_name: String::new(), implementation_version: "2.7",
implementation_version: v27.clone(), os_name: "linux",
os_name: "linux".to_string(), platform_machine: "",
platform_machine: String::new(), platform_python_implementation: "",
platform_python_implementation: String::new(), platform_release: "",
platform_release: String::new(), platform_system: "",
platform_system: String::new(), platform_version: "",
platform_version: String::new(), python_full_version: "2.7",
python_full_version: v27.clone(), python_version: "2.7",
python_version: v27, sys_platform: "linux",
sys_platform: "linux".to_string(), })
}; .unwrap();
let env37 = env37(); let env37 = env37();
let marker1 = MarkerTree::from_str("python_version == '2.7'").unwrap(); let marker1 = MarkerTree::from_str("python_version == '2.7'").unwrap();
let marker2 = MarkerTree::from_str( let marker2 = MarkerTree::from_str(

View file

@ -118,17 +118,17 @@ impl LineHaul {
name: Some("uv".to_string()), name: Some("uv".to_string()),
version: Some(version().to_string()), version: Some(version().to_string()),
}), }),
python: Some(markers.python_full_version.version.to_string()), python: Some(markers.python_full_version().version.to_string()),
implementation: Option::from(Implementation { implementation: Option::from(Implementation {
name: Some(markers.platform_python_implementation.to_string()), name: Some(markers.platform_python_implementation().to_string()),
version: Some(markers.python_full_version.version.to_string()), version: Some(markers.python_full_version().version.to_string()),
}), }),
distro, distro,
system: Option::from(System { system: Option::from(System {
name: Some(markers.platform_system.to_string()), name: Some(markers.platform_system().to_string()),
release: Some(markers.platform_release.to_string()), release: Some(markers.platform_release().to_string()),
}), }),
cpu: Some(markers.platform_machine.to_string()), cpu: Some(markers.platform_machine().to_string()),
// Should probably always be None in uv. // Should probably always be None in uv.
openssl_version: None, openssl_version: None,
// Should probably always be None in uv. // Should probably always be None in uv.

View file

@ -8,7 +8,7 @@ use hyper::service::service_fn;
use hyper::{Request, Response}; use hyper::{Request, Response};
use hyper_util::rt::TokioIo; use hyper_util::rt::TokioIo;
use insta::{assert_json_snapshot, assert_snapshot, with_settings}; use insta::{assert_json_snapshot, assert_snapshot, with_settings};
use pep508_rs::{MarkerEnvironment, StringVersion}; use pep508_rs::{MarkerEnvironment, MarkerEnvironmentBuilder};
use platform_tags::{Arch, Os, Platform}; use platform_tags::{Arch, Os, Platform};
use tokio::net::TcpListener; use tokio::net::TcpListener;
use uv_cache::Cache; use uv_cache::Cache;
@ -106,28 +106,20 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
}); });
// Add some representative markers for an Ubuntu CI runner // Add some representative markers for an Ubuntu CI runner
let markers = MarkerEnvironment { let markers = MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "cpython".to_string(), implementation_name: "cpython",
implementation_version: StringVersion { implementation_version: "3.12.2",
string: "3.12.2".to_string(), os_name: "posix",
version: "3.12.2".parse()?, platform_machine: "x86_64",
}, platform_python_implementation: "CPython",
os_name: "posix".to_string(), platform_release: "6.5.0-1016-azure",
platform_machine: "x86_64".to_string(), platform_system: "Linux",
platform_python_implementation: "CPython".to_string(), platform_version: "#16~22.04.1-Ubuntu SMP Fri Feb 16 15:42:02 UTC 2024",
platform_release: "6.5.0-1016-azure".to_string(), python_full_version: "3.12.2",
platform_system: "Linux".to_string(), python_version: "3.12",
platform_version: "#16~22.04.1-Ubuntu SMP Fri Feb 16 15:42:02 UTC 2024".to_string(), sys_platform: "linux",
python_full_version: StringVersion { })
string: "3.12.2".to_string(), .unwrap();
version: "3.12.2".parse()?,
},
python_version: StringVersion {
string: "3.12".to_string(),
version: "3.12".parse()?,
},
sys_platform: "linux".to_string(),
};
// Initialize uv-client // Initialize uv-client
let cache = Cache::temp()?; let cache = Cache::temp()?;

View file

@ -261,21 +261,13 @@ impl TargetTriple {
/// The returned [`MarkerEnvironment`] will preserve the base environment's Python version /// The returned [`MarkerEnvironment`] will preserve the base environment's Python version
/// markers, but override its platform markers. /// markers, but override its platform markers.
pub fn markers(self, base: &MarkerEnvironment) -> MarkerEnvironment { pub fn markers(self, base: &MarkerEnvironment) -> MarkerEnvironment {
MarkerEnvironment { base.clone()
// Platform markers .with_os_name(self.os_name())
os_name: self.os_name().to_string(), .with_platform_machine(self.platform_machine())
platform_machine: self.platform_machine().to_string(), .with_platform_system(self.platform_system())
platform_system: self.platform_system().to_string(), .with_sys_platform(self.sys_platform())
sys_platform: self.sys_platform().to_string(), .with_platform_release(self.platform_release())
platform_release: self.platform_release().to_string(), .with_platform_version(self.platform_version())
platform_version: self.platform_version().to_string(),
// Python version markers
implementation_name: base.implementation_name.clone(),
implementation_version: base.implementation_version.clone(),
platform_python_implementation: base.platform_python_implementation.clone(),
python_full_version: base.python_full_version.clone(),
python_version: base.python_version.clone(),
}
} }
} }

View file

@ -202,31 +202,31 @@ impl Interpreter {
/// Returns the Python version. /// Returns the Python version.
#[inline] #[inline]
pub const fn python_version(&self) -> &Version { pub fn python_version(&self) -> &Version {
&self.markers.python_full_version.version &self.markers.python_full_version().version
} }
/// Returns the `python_full_version` marker corresponding to this Python version. /// Returns the `python_full_version` marker corresponding to this Python version.
#[inline] #[inline]
pub const fn python_full_version(&self) -> &StringVersion { pub fn python_full_version(&self) -> &StringVersion {
&self.markers.python_full_version self.markers.python_full_version()
} }
/// Return the major version of this Python version. /// Return the major version of this Python version.
pub fn python_major(&self) -> u8 { pub fn python_major(&self) -> u8 {
let major = self.markers.python_full_version.version.release()[0]; let major = self.markers.python_full_version().version.release()[0];
u8::try_from(major).expect("invalid major version") u8::try_from(major).expect("invalid major version")
} }
/// Return the minor version of this Python version. /// Return the minor version of this Python version.
pub fn python_minor(&self) -> u8 { pub fn python_minor(&self) -> u8 {
let minor = self.markers.python_full_version.version.release()[1]; let minor = self.markers.python_full_version().version.release()[1];
u8::try_from(minor).expect("invalid minor version") u8::try_from(minor).expect("invalid minor version")
} }
/// Return the patch version of this Python version. /// Return the patch version of this Python version.
pub fn python_patch(&self) -> u8 { pub fn python_patch(&self) -> u8 {
let minor = self.markers.python_full_version.version.release()[2]; let minor = self.markers.python_full_version().version.release()[2];
u8::try_from(minor).expect("invalid patch version") u8::try_from(minor).expect("invalid patch version")
} }
@ -237,13 +237,13 @@ impl Interpreter {
/// Return the major version of the implementation (e.g., `CPython` or `PyPy`). /// Return the major version of the implementation (e.g., `CPython` or `PyPy`).
pub fn implementation_major(&self) -> u8 { pub fn implementation_major(&self) -> u8 {
let major = self.markers.implementation_version.version.release()[0]; let major = self.markers.implementation_version().version.release()[0];
u8::try_from(major).expect("invalid major version") u8::try_from(major).expect("invalid major version")
} }
/// Return the minor version of the implementation (e.g., `CPython` or `PyPy`). /// Return the minor version of the implementation (e.g., `CPython` or `PyPy`).
pub fn implementation_minor(&self) -> u8 { pub fn implementation_minor(&self) -> u8 {
let minor = self.markers.implementation_version.version.release()[1]; let minor = self.markers.implementation_version().version.release()[1];
u8::try_from(minor).expect("invalid minor version") u8::try_from(minor).expect("invalid minor version")
} }
@ -254,7 +254,7 @@ impl Interpreter {
/// Returns the implementation name (e.g., `CPython` or `PyPy`). /// Returns the implementation name (e.g., `CPython` or `PyPy`).
pub fn implementation_name(&self) -> &str { pub fn implementation_name(&self) -> &str {
&self.markers.implementation_name self.markers.implementation_name()
} }
/// Return the `sys.base_exec_prefix` path for this Python interpreter. /// Return the `sys.base_exec_prefix` path for this Python interpreter.
@ -337,7 +337,7 @@ impl Interpreter {
Layout { Layout {
python_version: self.python_tuple(), python_version: self.python_tuple(),
sys_executable: self.sys_executable().to_path_buf(), sys_executable: self.sys_executable().to_path_buf(),
os_name: self.markers.os_name.clone(), os_name: self.markers.os_name().to_string(),
scheme: if let Some(target) = self.target.as_ref() { scheme: if let Some(target) = self.target.as_ref() {
target.scheme() target.scheme()
} else { } else {
@ -540,7 +540,7 @@ impl InterpreterInfo {
if cached.timestamp == modified { if cached.timestamp == modified {
debug!( debug!(
"Cached interpreter info for Python {}, skipping probing: {}", "Cached interpreter info for Python {}, skipping probing: {}",
cached.data.markers.python_full_version, cached.data.markers.python_full_version(),
executable.user_display() executable.user_display()
); );
return Ok(cached.data); return Ok(cached.data);
@ -567,7 +567,7 @@ impl InterpreterInfo {
let info = Self::query(executable, cache)?; let info = Self::query(executable, cache)?;
debug!( debug!(
"Found Python {} for: {}", "Found Python {} for: {}",
info.markers.python_full_version, info.markers.python_full_version(),
executable.display() executable.display()
); );
@ -670,7 +670,7 @@ mod tests {
.unwrap(); .unwrap();
let interpreter = Interpreter::query(&mocked_interpreter, &cache).unwrap(); let interpreter = Interpreter::query(&mocked_interpreter, &cache).unwrap();
assert_eq!( assert_eq!(
interpreter.markers.python_version.version, interpreter.markers.python_version().version,
Version::from_str("3.12").unwrap() Version::from_str("3.12").unwrap()
); );
fs::write( fs::write(
@ -683,7 +683,7 @@ mod tests {
.unwrap(); .unwrap();
let interpreter = Interpreter::query(&mocked_interpreter, &cache).unwrap(); let interpreter = Interpreter::query(&mocked_interpreter, &cache).unwrap();
assert_eq!( assert_eq!(
interpreter.markers.python_version.version, interpreter.markers.python_version().version,
Version::from_str("3.13").unwrap() Version::from_str("3.13").unwrap()
); );
} }

View file

@ -88,29 +88,29 @@ impl PythonVersion {
let mut markers = base.clone(); let mut markers = base.clone();
// Ex) `implementation_version == "3.12.0"` // Ex) `implementation_version == "3.12.0"`
if markers.implementation_name == "cpython" { if markers.implementation_name() == "cpython" {
let python_full_version = self.python_full_version(); let python_full_version = self.python_full_version();
markers.implementation_version = StringVersion { markers = markers.with_implementation_version(StringVersion {
// Retain the verbatim representation, provided by the user. // Retain the verbatim representation, provided by the user.
string: self.0.to_string(), string: self.0.to_string(),
version: python_full_version, version: python_full_version,
}; });
} }
// Ex) `python_full_version == "3.12.0"` // Ex) `python_full_version == "3.12.0"`
let python_full_version = self.python_full_version(); let python_full_version = self.python_full_version();
markers.python_full_version = StringVersion { markers = markers.with_python_full_version(StringVersion {
// Retain the verbatim representation, provided by the user. // Retain the verbatim representation, provided by the user.
string: self.0.to_string(), string: self.0.to_string(),
version: python_full_version, version: python_full_version,
}; });
// Ex) `python_version == "3.12"` // Ex) `python_version == "3.12"`
let python_version = self.python_version(); let python_version = self.python_version();
markers.python_version = StringVersion { markers = markers.with_python_version(StringVersion {
string: python_version.to_string(), string: python_version.to_string(),
version: python_version, version: python_version,
}; });
markers markers
} }

View file

@ -20,7 +20,7 @@ impl PythonRequirement {
} }
pub fn from_marker_environment(interpreter: &Interpreter, env: &MarkerEnvironment) -> Self { pub fn from_marker_environment(interpreter: &Interpreter, env: &MarkerEnvironment) -> Self {
Self::new(interpreter, &env.python_full_version) Self::new(interpreter, env.python_full_version())
} }
/// Return the installed version of Python. /// Return the installed version of Python.

View file

@ -11,7 +11,7 @@ use chrono::{DateTime, Utc};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use distribution_types::{IndexLocations, Requirement, Resolution, SourceDist}; use distribution_types::{IndexLocations, Requirement, Resolution, SourceDist};
use pep508_rs::{MarkerEnvironment, StringVersion}; use pep508_rs::{MarkerEnvironment, MarkerEnvironmentBuilder};
use platform_tags::{Arch, Os, Platform, Tags}; use platform_tags::{Arch, Os, Platform, Tags};
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::RegistryClientBuilder; use uv_client::RegistryClientBuilder;
@ -724,19 +724,19 @@ async fn msgraph_sdk() -> Result<()> {
} }
static MARKERS_311: Lazy<MarkerEnvironment> = Lazy::new(|| { static MARKERS_311: Lazy<MarkerEnvironment> = Lazy::new(|| {
MarkerEnvironment { MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "cpython".to_string(), implementation_name: "cpython",
implementation_version: StringVersion::from_str("3.11.5").unwrap(), implementation_version: "3.11.5",
os_name: "posix".to_string(), os_name: "posix",
platform_machine: "arm64".to_string(), platform_machine: "arm64",
platform_python_implementation: "CPython".to_string(), platform_python_implementation: "CPython",
platform_release: "21.6.0".to_string(), platform_release: "21.6.0",
platform_system: "Darwin".to_string(), platform_system: "Darwin",
platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000".to_string(), platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000",
python_full_version: StringVersion::from_str("3.11.5").unwrap(), python_full_version: "3.11.5",
python_version: StringVersion::from_str("3.11").unwrap(), python_version: "3.11",
sys_platform: "darwin".to_string(), sys_platform: "darwin",
} }).unwrap()
}); });
static TAGS_311: Lazy<Tags> = Lazy::new(|| { static TAGS_311: Lazy<Tags> = Lazy::new(|| {
@ -757,19 +757,19 @@ static TAGS_311: Lazy<Tags> = Lazy::new(|| {
}); });
static MARKERS_310: Lazy<MarkerEnvironment> = Lazy::new(|| { static MARKERS_310: Lazy<MarkerEnvironment> = Lazy::new(|| {
MarkerEnvironment { MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "cpython".to_string(), implementation_name: "cpython",
implementation_version: StringVersion::from_str("3.10.5").unwrap(), implementation_version: "3.10.5",
os_name: "posix".to_string(), os_name: "posix",
platform_machine: "arm64".to_string(), platform_machine: "arm64",
platform_python_implementation: "CPython".to_string(), platform_python_implementation: "CPython",
platform_release: "21.6.0".to_string(), platform_release: "21.6.0",
platform_system: "Darwin".to_string(), platform_system: "Darwin",
platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000".to_string(), platform_version: "Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000",
python_full_version: StringVersion::from_str("3.10.5").unwrap(), python_full_version: "3.10.5",
python_version: StringVersion::from_str("3.10").unwrap(), python_version: "3.10",
sys_platform: "darwin".to_string(), sys_platform: "darwin",
} }).unwrap()
}); });
static TAGS_310: Lazy<Tags> = Lazy::new(|| { static TAGS_310: Lazy<Tags> = Lazy::new(|| {

View file

@ -235,12 +235,15 @@ pub fn create_bare_venv(
), ),
( (
"implementation".to_string(), "implementation".to_string(),
interpreter.markers().platform_python_implementation.clone(), interpreter
.markers()
.platform_python_implementation()
.to_string(),
), ),
("uv".to_string(), version().to_string()), ("uv".to_string(), version().to_string()),
( (
"version_info".to_string(), "version_info".to_string(),
interpreter.markers().python_full_version.string.clone(), interpreter.markers().python_full_version().string.clone(),
), ),
( (
"include-system-site-packages".to_string(), "include-system-site-packages".to_string(),