Skip to content

Commit c7935ed

Browse files
committed
linehaul: log subcommand
1 parent d6eb285 commit c7935ed

4 files changed

Lines changed: 68 additions & 34 deletions

File tree

crates/uv-client/src/base_client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct BaseClientBuilder<'a> {
8989
cross_origin_credential_policy: CrossOriginCredentialsPolicy,
9090
/// Optional custom reqwest client to use instead of creating a new one.
9191
custom_client: Option<Client>,
92+
/// uv subcommand in which this client is being used
93+
subcommand: Option<Vec<String>>,
9294
}
9395

9496
/// The policy for handling HTTP redirects.
@@ -143,6 +145,7 @@ impl Default for BaseClientBuilder<'_> {
143145
redirect_policy: RedirectPolicy::default(),
144146
cross_origin_credential_policy: CrossOriginCredentialsPolicy::Secure,
145147
custom_client: None,
148+
subcommand: None,
146149
}
147150
}
148151
}
@@ -276,6 +279,12 @@ impl<'a> BaseClientBuilder<'a> {
276279
self
277280
}
278281

282+
#[must_use]
283+
pub fn subcommand(mut self, subcommand: Vec<String>) -> Self {
284+
self.subcommand = Some(subcommand);
285+
self
286+
}
287+
279288
pub fn is_native_tls(&self) -> bool {
280289
self.native_tls
281290
}
@@ -358,7 +367,7 @@ impl<'a> BaseClientBuilder<'a> {
358367
let mut user_agent_string = format!("uv/{}", version());
359368

360369
// Add linehaul metadata.
361-
let linehaul = LineHaul::new(self.markers, self.platform);
370+
let linehaul = LineHaul::new(self.markers, self.platform, self.subcommand.clone());
362371
if let Ok(output) = serde_json::to_string(&linehaul) {
363372
let _ = write!(user_agent_string, " {output}");
364373
}

crates/uv-client/src/linehaul.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use uv_version::version;
1212
pub struct Installer {
1313
pub name: Option<String>,
1414
pub version: Option<String>,
15+
pub subcommand: Option<Vec<String>>,
1516
}
1617

1718
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
@@ -63,7 +64,11 @@ pub struct LineHaul {
6364
impl LineHaul {
6465
/// Initializes Linehaul information based on PEP 508 markers.
6566
#[instrument(name = "linehaul", skip_all)]
66-
pub fn new(markers: Option<&MarkerEnvironment>, platform: Option<&Platform>) -> Self {
67+
pub fn new(
68+
markers: Option<&MarkerEnvironment>,
69+
platform: Option<&Platform>,
70+
subcommand: Option<Vec<String>>,
71+
) -> Self {
6772
// https://github.com/pypa/pip/blob/24.0/src/pip/_internal/network/session.py#L87
6873
let looks_like_ci = [
6974
EnvVars::BUILD_BUILDID,
@@ -123,6 +128,7 @@ impl LineHaul {
123128
installer: Option::from(Installer {
124129
name: Some("uv".to_string()),
125130
version: Some(version().to_string()),
131+
subcommand,
126132
}),
127133
python: markers.map(|markers| markers.python_full_version().version.to_string()),
128134
implementation: Option::from(Implementation {

crates/uv-client/tests/it/user_agent_version.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async fn test_user_agent_has_version() -> Result<()> {
5757
assert_json_snapshot!(&linehaul.installer, @r#"
5858
{
5959
"name": "uv",
60-
"version": "[VERSION]"
60+
"version": "[VERSION]",
61+
"subcommand": null
6162
}
6263
"#);
6364
});
@@ -152,11 +153,12 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
152153
assert_json_snapshot!(&linehaul, {
153154
".distro" => "[distro]",
154155
".ci" => "[ci]"
155-
}, @r###"
156+
}, @r#"
156157
{
157158
"installer": {
158159
"name": "uv",
159-
"version": "[VERSION]"
160+
"version": "[VERSION]",
161+
"subcommand": null
160162
},
161163
"python": "3.12.2",
162164
"implementation": {
@@ -174,7 +176,7 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
174176
"rustc_version": null,
175177
"ci": "[ci]"
176178
}
177-
"###);
179+
"#);
178180
});
179181

180182
// Assert distro

crates/uv/src/lib.rs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
624624
args.settings.torch_backend,
625625
args.settings.dependency_metadata,
626626
args.settings.keyring_provider,
627-
&client_builder,
627+
&client_builder.subcommand(vec!["pip".to_owned(), "compile".to_owned()]),
628628
args.settings.config_setting,
629629
args.settings.config_settings_package,
630630
args.settings.build_isolation.clone(),
@@ -701,7 +701,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
701701
args.settings.torch_backend,
702702
args.settings.dependency_metadata,
703703
args.settings.keyring_provider,
704-
&client_builder,
704+
&client_builder.subcommand(vec!["pip".to_owned(), "sync".to_owned()]),
705705
args.settings.allow_empty_requirements,
706706
globals.installer_metadata,
707707
&args.settings.config_setting,
@@ -850,7 +850,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
850850
args.settings.torch_backend,
851851
args.settings.dependency_metadata,
852852
args.settings.keyring_provider,
853-
&client_builder,
853+
&client_builder.subcommand(vec!["pip".to_owned(), "install".to_owned()]),
854854
args.settings.reinstall,
855855
args.settings.link_mode,
856856
args.settings.compile_bytecode,
@@ -913,7 +913,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
913913
args.settings.prefix,
914914
cache,
915915
args.settings.keyring_provider,
916-
&client_builder,
916+
&client_builder.subcommand(vec!["pip".to_owned(), "uninstall".to_owned()]),
917917
args.dry_run,
918918
printer,
919919
globals.preview,
@@ -962,7 +962,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
962962
args.settings.index_locations,
963963
args.settings.index_strategy,
964964
args.settings.keyring_provider,
965-
&client_builder,
965+
&client_builder.subcommand(vec!["pip".to_owned(), "list".to_owned()]),
966966
globals.concurrency,
967967
args.settings.strict,
968968
args.settings.exclude_newer,
@@ -1016,7 +1016,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
10161016
args.settings.index_locations,
10171017
args.settings.index_strategy,
10181018
args.settings.keyring_provider,
1019-
client_builder,
1019+
client_builder.subcommand(vec!["pip".to_owned(), "tree".to_owned()]),
10201020
globals.concurrency,
10211021
args.settings.strict,
10221022
args.settings.exclude_newer,
@@ -1103,7 +1103,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
11031103
args.python,
11041104
args.install_mirrors,
11051105
&args.settings,
1106-
&client_builder,
1106+
&client_builder.subcommand(vec!["build".to_owned()]),
11071107
cli.top_level.no_config,
11081108
globals.python_preference,
11091109
globals.python_downloads,
@@ -1170,7 +1170,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
11701170
args.settings.index_strategy,
11711171
args.settings.dependency_metadata,
11721172
args.settings.keyring_provider,
1173-
&client_builder,
1173+
&client_builder.subcommand(vec!["venv".to_owned()]),
11741174
uv_virtualenv::Prompt::from_args(prompt),
11751175
args.system_site_packages,
11761176
args.seed,
@@ -1210,7 +1210,16 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
12101210
token,
12111211
dry_run,
12121212
}),
1213-
}) => commands::self_update(target_version, token, dry_run, printer, client_builder).await,
1213+
}) => {
1214+
commands::self_update(
1215+
target_version,
1216+
token,
1217+
dry_run,
1218+
printer,
1219+
client_builder.subcommand(vec!["self".to_owned(), "update".to_owned()]),
1220+
)
1221+
.await
1222+
}
12141223
Commands::Self_(SelfNamespace {
12151224
command:
12161225
SelfCommand::Version {
@@ -1317,6 +1326,13 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
13171326
.map(RequirementsSource::from_constraints_txt)
13181327
.collect::<Result<Vec<_>, _>>()?;
13191328

1329+
let client_builder = match invocation_source {
1330+
ToolRunCommand::Uvx => client_builder.subcommand(vec!["uvx".to_owned()]),
1331+
ToolRunCommand::ToolRun => {
1332+
client_builder.subcommand(vec!["tool".to_owned(), "run".to_owned()])
1333+
}
1334+
};
1335+
13201336
Box::pin(commands::tool_run(
13211337
args.command,
13221338
args.from,
@@ -1426,7 +1442,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
14261442
args.force,
14271443
args.options,
14281444
args.settings,
1429-
client_builder,
1445+
client_builder.subcommand(vec!["tool".to_owned(), "install".to_owned()]),
14301446
globals.python_preference,
14311447
globals.python_downloads,
14321448
globals.installer_metadata,
@@ -1475,7 +1491,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
14751491
args.install_mirrors,
14761492
args.args,
14771493
args.filesystem,
1478-
client_builder,
1494+
client_builder.subcommand(vec!["tool".to_owned(), "upgrade".to_owned()]),
14791495
globals.python_preference,
14801496
globals.python_downloads,
14811497
globals.installer_metadata,
@@ -1532,7 +1548,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
15321548
args.python_downloads_json_url,
15331549
globals.python_preference,
15341550
globals.python_downloads,
1535-
&client_builder,
1551+
&client_builder.subcommand(vec!["python".to_owned(), "list".to_owned()]),
15361552
&cache,
15371553
printer,
15381554
globals.preview,
@@ -1558,7 +1574,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
15581574
args.python_install_mirror,
15591575
args.pypy_install_mirror,
15601576
args.python_downloads_json_url,
1561-
client_builder,
1577+
client_builder.subcommand(vec!["python".to_owned(), "install".to_owned()]),
15621578
args.default,
15631579
globals.python_downloads,
15641580
cli.top_level.no_config,
@@ -1587,7 +1603,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
15871603
args.python_install_mirror,
15881604
args.pypy_install_mirror,
15891605
args.python_downloads_json_url,
1590-
client_builder,
1606+
client_builder.subcommand(vec!["python".to_owned(), "upgrade".to_owned()]),
15911607
args.default,
15921608
globals.python_downloads,
15931609
cli.top_level.no_config,
@@ -1625,7 +1641,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
16251641
commands::python_find_script(
16261642
(&script).into(),
16271643
args.show_version,
1628-
&client_builder,
1644+
// TODO(zsol): is this the right thing to do here?
1645+
&client_builder.subcommand(vec!["python".to_owned(), "find".to_owned()]),
16291646
globals.python_preference,
16301647
globals.python_downloads,
16311648
cli.top_level.no_config,
@@ -1644,7 +1661,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
16441661
args.system,
16451662
globals.python_preference,
16461663
args.python_downloads_json_url.as_deref(),
1647-
&client_builder,
1664+
&client_builder.subcommand(vec!["python".to_owned(), "find".to_owned()]),
16481665
&cache,
16491666
printer,
16501667
globals.preview,
@@ -1671,7 +1688,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
16711688
args.global,
16721689
args.rm,
16731690
args.install_mirrors,
1674-
client_builder,
1691+
client_builder.subcommand(vec!["python".to_owned(), "pin".to_owned()]),
16751692
&cache,
16761693
printer,
16771694
globals.preview,
@@ -1727,7 +1744,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
17271744
trusted_publishing,
17281745
keyring_provider,
17291746
&environment,
1730-
&client_builder,
1747+
&client_builder.subcommand(vec!["publish".to_owned()]),
17311748
username,
17321749
password,
17331750
check_url,
@@ -1869,7 +1886,7 @@ async fn run_project(
18691886
args.python,
18701887
args.install_mirrors,
18711888
args.no_workspace,
1872-
&client_builder,
1889+
&client_builder.subcommand(vec!["init".to_owned()]),
18731890
globals.python_preference,
18741891
globals.python_downloads,
18751892
no_config,
@@ -1930,7 +1947,7 @@ async fn run_project(
19301947
args.python_platform,
19311948
args.install_mirrors,
19321949
args.settings,
1933-
client_builder,
1950+
client_builder.subcommand(vec!["run".to_owned()]),
19341951
globals.python_preference,
19351952
globals.python_downloads,
19361953
globals.installer_metadata,
@@ -1981,7 +1998,7 @@ async fn run_project(
19811998
globals.python_preference,
19821999
globals.python_downloads,
19832000
args.settings,
1984-
client_builder,
2001+
client_builder.subcommand(vec!["sync".to_owned()]),
19852002
script,
19862003
globals.installer_metadata,
19872004
globals.concurrency,
@@ -2027,7 +2044,7 @@ async fn run_project(
20272044
args.python,
20282045
args.install_mirrors,
20292046
args.settings,
2030-
client_builder,
2047+
client_builder.subcommand(vec!["lock".to_owned()]),
20312048
script,
20322049
globals.python_preference,
20332050
globals.python_downloads,
@@ -2154,7 +2171,7 @@ async fn run_project(
21542171
args.workspace,
21552172
args.install_mirrors,
21562173
args.settings,
2157-
client_builder,
2174+
client_builder.subcommand(vec!["add".to_owned()]),
21582175
script,
21592176
globals.python_preference,
21602177
globals.python_downloads,
@@ -2198,7 +2215,7 @@ async fn run_project(
21982215
args.python,
21992216
args.install_mirrors,
22002217
args.settings,
2201-
client_builder,
2218+
client_builder.subcommand(vec!["remove".to_owned()]),
22022219
script,
22032220
globals.python_preference,
22042221
globals.python_downloads,
@@ -2239,7 +2256,7 @@ async fn run_project(
22392256
args.python,
22402257
args.install_mirrors,
22412258
args.settings,
2242-
client_builder,
2259+
client_builder.subcommand(vec!["version".to_owned()]),
22432260
globals.python_preference,
22442261
globals.python_downloads,
22452262
globals.installer_metadata,
@@ -2284,7 +2301,7 @@ async fn run_project(
22842301
args.python,
22852302
args.install_mirrors,
22862303
args.resolver,
2287-
&client_builder,
2304+
&client_builder.subcommand(vec!["tree".to_owned()]),
22882305
script,
22892306
globals.python_preference,
22902307
globals.python_downloads,
@@ -2331,7 +2348,7 @@ async fn run_project(
23312348
args.python,
23322349
args.install_mirrors,
23332350
args.settings,
2334-
client_builder,
2351+
client_builder.subcommand(vec!["export".to_owned()]),
23352352
globals.python_preference,
23362353
globals.python_downloads,
23372354
globals.concurrency,
@@ -2358,7 +2375,7 @@ async fn run_project(
23582375
args.diff,
23592376
args.extra_args,
23602377
args.version,
2361-
client_builder,
2378+
client_builder.subcommand(vec!["format".to_owned()]),
23622379
cache,
23632380
printer,
23642381
globals.preview,

0 commit comments

Comments
 (0)