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

@ -118,17 +118,17 @@ impl LineHaul {
name: Some("uv".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 {
name: Some(markers.platform_python_implementation.to_string()),
version: Some(markers.python_full_version.version.to_string()),
name: Some(markers.platform_python_implementation().to_string()),
version: Some(markers.python_full_version().version.to_string()),
}),
distro,
system: Option::from(System {
name: Some(markers.platform_system.to_string()),
release: Some(markers.platform_release.to_string()),
name: Some(markers.platform_system().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.
openssl_version: None,
// Should probably always be None in uv.

View file

@ -8,7 +8,7 @@ use hyper::service::service_fn;
use hyper::{Request, Response};
use hyper_util::rt::TokioIo;
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 tokio::net::TcpListener;
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
let markers = MarkerEnvironment {
implementation_name: "cpython".to_string(),
implementation_version: StringVersion {
string: "3.12.2".to_string(),
version: "3.12.2".parse()?,
},
os_name: "posix".to_string(),
platform_machine: "x86_64".to_string(),
platform_python_implementation: "CPython".to_string(),
platform_release: "6.5.0-1016-azure".to_string(),
platform_system: "Linux".to_string(),
platform_version: "#16~22.04.1-Ubuntu SMP Fri Feb 16 15:42:02 UTC 2024".to_string(),
python_full_version: StringVersion {
string: "3.12.2".to_string(),
version: "3.12.2".parse()?,
},
python_version: StringVersion {
string: "3.12".to_string(),
version: "3.12".parse()?,
},
sys_platform: "linux".to_string(),
};
let markers = MarkerEnvironment::try_from(MarkerEnvironmentBuilder {
implementation_name: "cpython",
implementation_version: "3.12.2",
os_name: "posix",
platform_machine: "x86_64",
platform_python_implementation: "CPython",
platform_release: "6.5.0-1016-azure",
platform_system: "Linux",
platform_version: "#16~22.04.1-Ubuntu SMP Fri Feb 16 15:42:02 UTC 2024",
python_full_version: "3.12.2",
python_version: "3.12",
sys_platform: "linux",
})
.unwrap();
// Initialize uv-client
let cache = Cache::temp()?;