-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mark uv pip invocations in linehaul data
#16702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
472fe8e
Skip python_install_emulated_macos except on ARM64 macos with rosetta
zsol 404a355
try to run an emulated binary instead of checking for rosetta files
zsol a730bd6
Fail emulated test in CI if emulation isn't available
zsol c444692
Fix shell-specific test snapshots
zsol bbb9bd6
Fix windows case
zsol a21094d
address review feedback
zsol 90b93bb
Stop pinning SHELL to bash on windows
zsol f027c3b
Mark `uv pip` invocations in linehaul data
zsol 8d7ad79
extract test helper
zsol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use hyper_util::rt::TokioIo; | |
| use insta::{assert_json_snapshot, assert_snapshot, with_settings}; | ||
| use std::str::FromStr; | ||
| use tokio::net::TcpListener; | ||
| use tokio::task::JoinHandle; | ||
| use url::Url; | ||
| use uv_cache::Cache; | ||
| use uv_client::RegistryClientBuilder; | ||
|
|
@@ -19,11 +20,13 @@ use uv_platform_tags::{Arch, Os, Platform}; | |
| use uv_redacted::DisplaySafeUrl; | ||
| use uv_version::version; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_user_agent_has_version() -> Result<()> { | ||
| /// Spawns a dummy HTTP server that echoes back the User-Agent header. | ||
| /// Returns the server URL and the server task handle. | ||
| async fn spawn_user_agent_echo_server() -> Result<(DisplaySafeUrl, JoinHandle<()>)> { | ||
|
Comment on lines
+23
to
+25
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, a new abstraction to spawing this server will be in #16473 |
||
| // Set up the TCP listener on a random available port | ||
| let listener = TcpListener::bind("127.0.0.1:0").await?; | ||
| let addr = listener.local_addr()?; | ||
| let url = DisplaySafeUrl::from_str(&format!("http://{addr}"))?; | ||
|
|
||
| // Spawn the server loop in a background task | ||
| let server_task = tokio::spawn(async move { | ||
|
|
@@ -50,12 +53,18 @@ async fn test_user_agent_has_version() -> Result<()> { | |
| }); | ||
| }); | ||
|
|
||
| Ok((url, server_task)) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_user_agent_has_version() -> Result<()> { | ||
| let (url, server_task) = spawn_user_agent_echo_server().await?; | ||
|
|
||
| // Initialize uv-client | ||
| let cache = Cache::temp()?.init()?; | ||
| let client = RegistryClientBuilder::new(BaseClientBuilder::default(), cache).build(); | ||
|
|
||
| // Send request to our dummy server | ||
| let url = DisplaySafeUrl::from_str(&format!("http://{addr}"))?; | ||
| let res = client | ||
| .cached_client() | ||
| .uncached() | ||
|
|
@@ -81,34 +90,7 @@ async fn test_user_agent_has_version() -> Result<()> { | |
|
|
||
| #[tokio::test] | ||
| async fn test_user_agent_has_linehaul() -> Result<()> { | ||
| // Set up the TCP listener on a random available port | ||
| let listener = TcpListener::bind("127.0.0.1:0").await?; | ||
| let addr = listener.local_addr()?; | ||
|
|
||
| // Spawn the server loop in a background task | ||
| let server_task = tokio::spawn(async move { | ||
| let svc = service_fn(move |req: Request<hyper::body::Incoming>| { | ||
| // Get User Agent Header and send it back in the response | ||
| let user_agent = req | ||
| .headers() | ||
| .get(USER_AGENT) | ||
| .and_then(|v| v.to_str().ok()) | ||
| .map(ToString::to_string) | ||
| .unwrap_or_default(); // Empty Default | ||
| future::ok::<_, hyper::Error>(Response::new(Full::new(Bytes::from(user_agent)))) | ||
| }); | ||
| // Start Server (not wrapped in loop {} since we want a single response server) | ||
| // If you want server to accept multiple connections, wrap it in loop {} | ||
| let (socket, _) = listener.accept().await.unwrap(); | ||
| let socket = TokioIo::new(socket); | ||
| tokio::task::spawn(async move { | ||
| http1::Builder::new() | ||
| .serve_connection(socket, svc) | ||
| .with_upgrades() | ||
| .await | ||
| .expect("Server Started"); | ||
| }); | ||
| }); | ||
| let (url, server_task) = spawn_user_agent_echo_server().await?; | ||
|
|
||
| // Add some representative markers for an Ubuntu CI runner | ||
| let markers = MarkerEnvironment::try_from(MarkerEnvironmentBuilder { | ||
|
|
@@ -153,7 +135,6 @@ async fn test_user_agent_has_linehaul() -> Result<()> { | |
| let client = builder.build(); | ||
|
|
||
| // Send request to our dummy server | ||
| let url = DisplaySafeUrl::from_str(&format!("http://{addr}"))?; | ||
| let res = client | ||
| .cached_client() | ||
| .uncached() | ||
|
|
@@ -259,3 +240,73 @@ async fn test_user_agent_has_linehaul() -> Result<()> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_user_agent_installer_name_override() -> Result<()> { | ||
| let (url, server_task) = spawn_user_agent_echo_server().await?; | ||
|
|
||
| // Add some representative markers for an Ubuntu CI runner | ||
| 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 with custom installer name | ||
| let cache = Cache::temp()?.init()?; | ||
| let base_client = BaseClientBuilder::default() | ||
| .markers(&markers) | ||
| .installer_name("uv-pip"); | ||
| let client = RegistryClientBuilder::new(base_client, cache).build(); | ||
|
|
||
| // Send request to our dummy server | ||
| let res = client | ||
| .cached_client() | ||
| .uncached() | ||
| .for_host(&url) | ||
| .get(Url::from(url)) | ||
| .send() | ||
| .await?; | ||
|
|
||
| // Check the HTTP status | ||
| assert!(res.status().is_success()); | ||
|
|
||
| // Check User Agent | ||
| let body = res.text().await?; | ||
|
|
||
| // Wait for the server task to complete, to be a good citizen. | ||
| server_task.await?; | ||
|
|
||
| let (prefix, linehaul_json) = body | ||
| .split_once(' ') | ||
| .expect("Failed to split User-Agent header"); | ||
|
|
||
| let linehaul: LineHaul = | ||
| serde_json::from_str(linehaul_json).expect("Failed to deserialize linehaul"); | ||
| let installer = linehaul | ||
| .installer | ||
| .expect("linehaul installer field is missing"); | ||
| insta::with_settings!({ | ||
| filters => vec![(version(), "<VERSION>")] | ||
| }, { | ||
| // make sure the installer name in the prefix is kept as `uv` | ||
| assert_snapshot!(prefix, @r#"uv/<VERSION> "#); | ||
| assert_json_snapshot!(installer, @r#" | ||
| { | ||
| "name": "uv-pip", | ||
| "version": "<VERSION>" | ||
| } | ||
| "#); | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly surprised but linehaul doesn't seem to check this field at all, which is good for us.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As part of Google BigQuery? I feel I've queried based on installer name in the past 😅 e.g.details.installer.nameAh, you meant the cloud function doesn't validate the field contents. Ignore my initial reaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect changing details.installer.name could have some consequences / churn in terms of how statistics are reported for uv in cases where someone using Big Query doesn't group by details.installer.name and does a select on
details.installer.name = 'uv'directly for popular clients. I'd expect this to be a common scenario to avoid associated costs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we had an additional field so that querying for uv can be done in a single condition instead of splitting this into two names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @pradyunsg, @di or @ewdurbin may have better ideas on how to avoid splitting
details.installer.namebetweenuvanduv-pipor this use case in general?I think that'd be great if adding a new field could be a supported option to avoid the confusion of having two potential installer names, but I'm not sure what type of coordination or process would be needed in linehaul's side first. There may be better options I'm missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also posted in the PyPA Discord https://discord.com/channels/803025117553754132/885686683507494913/1438509254964281435
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we won't merge this as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems entirely reasonable to add additional values under the details key, though that can take some time since we no longer get to run our own schema migrations now that our dataset is part of the google public datasets. file an issue at https://github.com/pypi/linehaul-cloud-function/issues and tag me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: pypi/linehaul-cloud-function#233