Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/uv-client/src/base_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct BaseClientBuilder<'a> {
cross_origin_credential_policy: CrossOriginCredentialsPolicy,
/// Optional custom reqwest client to use instead of creating a new one.
custom_client: Option<Client>,
/// uv subcommand in which this client is being used
subcommand: Option<Vec<String>>,
}

/// The policy for handling HTTP redirects.
Expand Down Expand Up @@ -143,6 +145,7 @@ impl Default for BaseClientBuilder<'_> {
redirect_policy: RedirectPolicy::default(),
cross_origin_credential_policy: CrossOriginCredentialsPolicy::Secure,
custom_client: None,
subcommand: None,
}
}
}
Expand Down Expand Up @@ -276,6 +279,12 @@ impl<'a> BaseClientBuilder<'a> {
self
}

#[must_use]
pub fn subcommand(mut self, subcommand: Vec<String>) -> Self {
self.subcommand = Some(subcommand);
self
}

pub fn is_native_tls(&self) -> bool {
self.native_tls
}
Expand Down Expand Up @@ -358,7 +367,7 @@ impl<'a> BaseClientBuilder<'a> {
let mut user_agent_string = format!("uv/{}", version());

// Add linehaul metadata.
let linehaul = LineHaul::new(self.markers, self.platform);
let linehaul = LineHaul::new(self.markers, self.platform, self.subcommand.clone());
if let Ok(output) = serde_json::to_string(&linehaul) {
let _ = write!(user_agent_string, " {output}");
}
Expand Down
8 changes: 7 additions & 1 deletion crates/uv-client/src/linehaul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use uv_version::version;
pub struct Installer {
pub name: Option<String>,
pub version: Option<String>,
pub subcommand: Option<Vec<String>>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
Expand Down Expand Up @@ -63,7 +64,11 @@ pub struct LineHaul {
impl LineHaul {
/// Initializes Linehaul information based on PEP 508 markers.
#[instrument(name = "linehaul", skip_all)]
pub fn new(markers: Option<&MarkerEnvironment>, platform: Option<&Platform>) -> Self {
pub fn new(
markers: Option<&MarkerEnvironment>,
platform: Option<&Platform>,
subcommand: Option<Vec<String>>,
) -> Self {
// https://github.com/pypa/pip/blob/24.0/src/pip/_internal/network/session.py#L87
let looks_like_ci = [
EnvVars::BUILD_BUILDID,
Expand Down Expand Up @@ -123,6 +128,7 @@ impl LineHaul {
installer: Option::from(Installer {
name: Some("uv".to_string()),
version: Some(version().to_string()),
subcommand,
}),
python: markers.map(|markers| markers.python_full_version().version.to_string()),
implementation: Option::from(Implementation {
Expand Down
73 changes: 45 additions & 28 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.torch_backend,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["pip".to_owned(), "compile".to_owned()]),
args.settings.config_setting,
args.settings.config_settings_package,
args.settings.build_isolation.clone(),
Expand Down Expand Up @@ -701,7 +701,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.torch_backend,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["pip".to_owned(), "sync".to_owned()]),
args.settings.allow_empty_requirements,
globals.installer_metadata,
&args.settings.config_setting,
Expand Down Expand Up @@ -850,7 +850,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.torch_backend,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["pip".to_owned(), "install".to_owned()]),
args.settings.reinstall,
args.settings.link_mode,
args.settings.compile_bytecode,
Expand Down Expand Up @@ -913,7 +913,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.prefix,
cache,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["pip".to_owned(), "uninstall".to_owned()]),
args.dry_run,
printer,
globals.preview,
Expand Down Expand Up @@ -962,7 +962,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.index_locations,
args.settings.index_strategy,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["pip".to_owned(), "list".to_owned()]),
globals.concurrency,
args.settings.strict,
args.settings.exclude_newer,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.index_locations,
args.settings.index_strategy,
args.settings.keyring_provider,
client_builder,
client_builder.subcommand(vec!["pip".to_owned(), "tree".to_owned()]),
globals.concurrency,
args.settings.strict,
args.settings.exclude_newer,
Expand Down Expand Up @@ -1103,7 +1103,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.python,
args.install_mirrors,
&args.settings,
&client_builder,
&client_builder.subcommand(vec!["build".to_owned()]),
cli.top_level.no_config,
globals.python_preference,
globals.python_downloads,
Expand Down Expand Up @@ -1170,7 +1170,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.index_strategy,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&client_builder,
&client_builder.subcommand(vec!["venv".to_owned()]),
uv_virtualenv::Prompt::from_args(prompt),
args.system_site_packages,
args.seed,
Expand Down Expand Up @@ -1210,7 +1210,16 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
token,
dry_run,
}),
}) => commands::self_update(target_version, token, dry_run, printer, client_builder).await,
}) => {
commands::self_update(
target_version,
token,
dry_run,
printer,
client_builder.subcommand(vec!["self".to_owned(), "update".to_owned()]),
)
.await
}
Commands::Self_(SelfNamespace {
command:
SelfCommand::Version {
Expand Down Expand Up @@ -1317,6 +1326,13 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.map(RequirementsSource::from_constraints_txt)
.collect::<Result<Vec<_>, _>>()?;

let client_builder = match invocation_source {
ToolRunCommand::Uvx => client_builder.subcommand(vec!["uvx".to_owned()]),
ToolRunCommand::ToolRun => {
client_builder.subcommand(vec!["tool".to_owned(), "run".to_owned()])
}
};

Box::pin(commands::tool_run(
args.command,
args.from,
Expand Down Expand Up @@ -1426,7 +1442,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.force,
args.options,
args.settings,
client_builder,
client_builder.subcommand(vec!["tool".to_owned(), "install".to_owned()]),
globals.python_preference,
globals.python_downloads,
globals.installer_metadata,
Expand Down Expand Up @@ -1475,7 +1491,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.install_mirrors,
args.args,
args.filesystem,
client_builder,
client_builder.subcommand(vec!["tool".to_owned(), "upgrade".to_owned()]),
globals.python_preference,
globals.python_downloads,
globals.installer_metadata,
Expand Down Expand Up @@ -1532,7 +1548,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.python_downloads_json_url,
globals.python_preference,
globals.python_downloads,
&client_builder,
&client_builder.subcommand(vec!["python".to_owned(), "list".to_owned()]),
&cache,
printer,
globals.preview,
Expand All @@ -1558,7 +1574,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.python_install_mirror,
args.pypy_install_mirror,
args.python_downloads_json_url,
client_builder,
client_builder.subcommand(vec!["python".to_owned(), "install".to_owned()]),
args.default,
globals.python_downloads,
cli.top_level.no_config,
Expand Down Expand Up @@ -1587,7 +1603,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.python_install_mirror,
args.pypy_install_mirror,
args.python_downloads_json_url,
client_builder,
client_builder.subcommand(vec!["python".to_owned(), "upgrade".to_owned()]),
args.default,
globals.python_downloads,
cli.top_level.no_config,
Expand Down Expand Up @@ -1625,7 +1641,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
commands::python_find_script(
(&script).into(),
args.show_version,
&client_builder,
// TODO(zsol): is this the right thing to do here?
&client_builder.subcommand(vec!["python".to_owned(), "find".to_owned()]),
globals.python_preference,
globals.python_downloads,
cli.top_level.no_config,
Expand All @@ -1644,7 +1661,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.system,
globals.python_preference,
args.python_downloads_json_url.as_deref(),
&client_builder,
&client_builder.subcommand(vec!["python".to_owned(), "find".to_owned()]),
&cache,
printer,
globals.preview,
Expand All @@ -1671,7 +1688,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.global,
args.rm,
args.install_mirrors,
client_builder,
client_builder.subcommand(vec!["python".to_owned(), "pin".to_owned()]),
&cache,
printer,
globals.preview,
Expand Down Expand Up @@ -1727,7 +1744,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
trusted_publishing,
keyring_provider,
&environment,
&client_builder,
&client_builder.subcommand(vec!["publish".to_owned()]),
username,
password,
check_url,
Expand Down Expand Up @@ -1869,7 +1886,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.no_workspace,
&client_builder,
&client_builder.subcommand(vec!["init".to_owned()]),
globals.python_preference,
globals.python_downloads,
no_config,
Expand Down Expand Up @@ -1930,7 +1947,7 @@ async fn run_project(
args.python_platform,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["run".to_owned()]),
globals.python_preference,
globals.python_downloads,
globals.installer_metadata,
Expand Down Expand Up @@ -1981,7 +1998,7 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
args.settings,
client_builder,
client_builder.subcommand(vec!["sync".to_owned()]),
script,
globals.installer_metadata,
globals.concurrency,
Expand Down Expand Up @@ -2027,7 +2044,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["lock".to_owned()]),
script,
globals.python_preference,
globals.python_downloads,
Expand Down Expand Up @@ -2154,7 +2171,7 @@ async fn run_project(
args.workspace,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["add".to_owned()]),
script,
globals.python_preference,
globals.python_downloads,
Expand Down Expand Up @@ -2198,7 +2215,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["remove".to_owned()]),
script,
globals.python_preference,
globals.python_downloads,
Expand Down Expand Up @@ -2239,7 +2256,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["version".to_owned()]),
globals.python_preference,
globals.python_downloads,
globals.installer_metadata,
Expand Down Expand Up @@ -2284,7 +2301,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.resolver,
&client_builder,
&client_builder.subcommand(vec!["tree".to_owned()]),
script,
globals.python_preference,
globals.python_downloads,
Expand Down Expand Up @@ -2331,7 +2348,7 @@ async fn run_project(
args.python,
args.install_mirrors,
args.settings,
client_builder,
client_builder.subcommand(vec!["export".to_owned()]),
globals.python_preference,
globals.python_downloads,
globals.concurrency,
Expand All @@ -2358,7 +2375,7 @@ async fn run_project(
args.diff,
args.extra_args,
args.version,
client_builder,
client_builder.subcommand(vec!["format".to_owned()]),
cache,
printer,
globals.preview,
Expand Down
Loading