Skip to content

Commit

Permalink
Move concurrency settings to top-level
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored and zanieb committed Aug 19, 2024
1 parent 5eadbf9 commit 1cf59d1
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 311 deletions.
66 changes: 33 additions & 33 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,39 @@ pub struct GlobalOptions {
possible_values = true
)]
pub python_downloads: Option<PythonDownloads>,
/// The maximum number of in-flight concurrent downloads that uv will perform at any given
/// time.
#[option(
default = "50",
value_type = "int",
example = r#"
concurrent-downloads = 4
"#
)]
pub concurrent_downloads: Option<NonZeroUsize>,
/// The maximum number of source distributions that uv will build concurrently at any given
/// time.
///
/// Defaults to the number of available CPU cores.
#[option(
default = "None",
value_type = "int",
example = r#"
concurrent-builds = 4
"#
)]
pub concurrent_builds: Option<NonZeroUsize>,
/// The number of threads used when installing and unzipping packages.
///
/// Defaults to the number of available CPU cores.
#[option(
default = "None",
value_type = "int",
example = r#"
concurrent-installs = 4
"#
)]
pub concurrent_installs: Option<NonZeroUsize>,
}

/// Settings relevant to all installer operations.
Expand Down Expand Up @@ -1172,39 +1205,6 @@ pub struct PipOptions {
"#
)]
pub reinstall_package: Option<Vec<PackageName>>,
/// The maximum number of in-flight concurrent downloads that uv will perform at any given
/// time.
#[option(
default = "50",
value_type = "int",
example = r#"
concurrent-downloads = 4
"#
)]
pub concurrent_downloads: Option<NonZeroUsize>,
/// The maximum number of source distributions that uv will build concurrently at any given
/// time.
///
/// Defaults to the number of available CPU cores.
#[option(
default = "None",
value_type = "int",
example = r#"
concurrent-builds = 4
"#
)]
pub concurrent_builds: Option<NonZeroUsize>,
/// The number of threads used when installing and unzipping packages.
///
/// Defaults to the number of available CPU cores.
#[option(
default = "None",
value_type = "int",
example = r#"
concurrent-installs = 4
"#
)]
pub concurrent_installs: Option<NonZeroUsize>,
}

impl From<ResolverInstallerOptions> for ResolverOptions {
Expand Down
6 changes: 4 additions & 2 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(crate) async fn venv(
seed: bool,
allow_existing: bool,
exclude_newer: Option<ExcludeNewer>,
concurrency: Concurrency,
native_tls: bool,
cache: &Cache,
printer: Printer,
Expand All @@ -75,6 +76,7 @@ pub(crate) async fn venv(
python_downloads,
allow_existing,
exclude_newer,
concurrency,
native_tls,
cache,
printer,
Expand Down Expand Up @@ -126,6 +128,7 @@ async fn venv_impl(
python_downloads: PythonDownloads,
allow_existing: bool,
exclude_newer: Option<ExcludeNewer>,
concurrency: Concurrency,
native_tls: bool,
cache: &Cache,
printer: Printer,
Expand Down Expand Up @@ -268,9 +271,8 @@ async fn venv_impl(
// Initialize any shared state.
let state = SharedState::default();

// For seed packages, assume a bunch of default settings and concurrency are sufficient.
// For seed packages, assume a bunch of default settings are sufficient.
let build_constraints = [];
let concurrency = Concurrency::default();
let config_settings = ConfigSettings::default();
let setup_py = SetupPyStrategy::default();
let sources = SourceStrategy::Disabled;
Expand Down
50 changes: 20 additions & 30 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use uv_cli::{
use uv_cli::{PythonCommand, PythonNamespace, ToolCommand, ToolNamespace};
#[cfg(feature = "self-update")]
use uv_cli::{SelfCommand, SelfNamespace};
use uv_configuration::Concurrency;
use uv_fs::CWD;
use uv_requirements::RequirementsSource;
use uv_scripts::Pep723Script;
Expand Down Expand Up @@ -209,6 +208,11 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
)
}))?;

rayon::ThreadPoolBuilder::new()
.num_threads(globals.concurrency.installs)
.build_global()
.expect("failed to initialize global rayon pool");

debug!("uv {}", version::version());

// Write out any resolved settings.
Expand Down Expand Up @@ -246,11 +250,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
let args = PipCompileSettings::resolve(args, filesystem);
show_settings!(args);

rayon::ThreadPoolBuilder::new()
.num_threads(args.settings.concurrency.installs)
.build_global()
.expect("failed to initialize global rayon pool");

// Initialize the cache.
let cache = cache.init()?.with_refresh(
args.refresh
Expand Down Expand Up @@ -323,7 +322,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.settings.python,
args.settings.system,
globals.python_preference,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
globals.quiet,
cache,
Expand All @@ -340,11 +339,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
let args = PipSyncSettings::resolve(args, filesystem);
show_settings!(args);

rayon::ThreadPoolBuilder::new()
.num_threads(args.settings.concurrency.installs)
.build_global()
.expect("failed to initialize global rayon pool");

// Initialize the cache.
let cache = cache.init()?.with_refresh(
args.refresh
Expand Down Expand Up @@ -396,7 +390,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.settings.target,
args.settings.prefix,
args.settings.sources,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
cache,
args.dry_run,
Expand All @@ -413,11 +407,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
let args = PipInstallSettings::resolve(args, filesystem);
show_settings!(args);

rayon::ThreadPoolBuilder::new()
.num_threads(args.settings.concurrency.installs)
.build_global()
.expect("failed to initialize global rayon pool");

// Initialize the cache.
let cache = cache.init()?.with_refresh(
args.refresh
Expand Down Expand Up @@ -488,7 +477,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.settings.break_system_packages,
args.settings.target,
args.settings.prefix,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
cache,
args.dry_run,
Expand Down Expand Up @@ -693,6 +682,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.seed,
args.allow_existing,
args.settings.exclude_newer,
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -762,7 +752,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
cache,
printer,
Expand Down Expand Up @@ -806,7 +796,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -840,7 +830,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
globals.connectivity,
args.args,
args.filesystem,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -1048,7 +1038,7 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -1079,7 +1069,7 @@ async fn run_project(
globals.python_downloads,
args.settings,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand All @@ -1102,7 +1092,7 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -1142,7 +1132,7 @@ async fn run_project(
)
.collect::<Vec<_>>();

commands::add(
Box::pin(commands::add(
args.locked,
args.frozen,
args.no_sync,
Expand All @@ -1161,11 +1151,11 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
)
))
.await
}
ProjectCommand::Remove(args) => {
Expand Down Expand Up @@ -1193,7 +1183,7 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -1224,7 +1214,7 @@ async fn run_project(
globals.python_preference,
globals.python_downloads,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down
Loading

0 comments on commit 1cf59d1

Please sign in to comment.