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 committed Jun 14, 2024
1 parent b7fb0b4 commit 9a25c44
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 164 deletions.
6 changes: 3 additions & 3 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub struct GlobalOptions {
pub offline: Option<bool>,
pub no_cache: Option<bool>,
pub cache_dir: Option<PathBuf>,
pub concurrent_downloads: Option<NonZeroUsize>,
pub concurrent_builds: Option<NonZeroUsize>,
pub concurrent_installs: Option<NonZeroUsize>,
pub preview: Option<bool>,
}

Expand Down Expand Up @@ -189,7 +192,4 @@ pub struct PipOptions {
pub upgrade_package: Option<Vec<PackageName>>,
pub reinstall: Option<bool>,
pub reinstall_package: Option<Vec<PackageName>>,
pub concurrent_downloads: Option<NonZeroUsize>,
pub concurrent_builds: Option<NonZeroUsize>,
pub concurrent_installs: Option<NonZeroUsize>,
}
6 changes: 4 additions & 2 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub(crate) async fn venv(
seed: bool,
allow_existing: bool,
exclude_newer: Option<ExcludeNewer>,
concurrency: Concurrency,
native_tls: bool,
preview: PreviewMode,
cache: &Cache,
Expand All @@ -68,6 +69,7 @@ pub(crate) async fn venv(
preview,
allow_existing,
exclude_newer,
concurrency,
native_tls,
cache,
printer,
Expand Down Expand Up @@ -117,6 +119,7 @@ async fn venv_impl(
preview: PreviewMode,
allow_existing: bool,
exclude_newer: Option<ExcludeNewer>,
concurrency: Concurrency,
native_tls: bool,
cache: &Cache,
printer: Printer,
Expand Down Expand Up @@ -206,9 +209,8 @@ async fn venv_impl(
// Track in-flight downloads, builds, etc., across resolutions.
let in_flight = InFlight::default();

// For seed packages, assume the default settings and concurrency is sufficient.
// For seed packages, assume the default settings is sufficient.
let config_settings = ConfigSettings::default();
let concurrency = Concurrency::default();

// Do not allow builds
let build_options = BuildOptions::new(NoBinary::None, NoBuild::All);
Expand Down
40 changes: 15 additions & 25 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tracing::{debug, instrument};

use cli::{ToolCommand, ToolNamespace, ToolchainCommand, ToolchainNamespace};
use uv_cache::Cache;
use uv_configuration::Concurrency;
use uv_distribution::Workspace;
use uv_requirements::RequirementsSource;
use uv_settings::Combine;
Expand Down Expand Up @@ -188,6 +187,11 @@ async fn run() -> 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 @@ -220,11 +224,6 @@ async fn run() -> 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 @@ -280,7 +279,7 @@ async fn run() -> Result<ExitStatus> {
args.settings.link_mode,
args.settings.python,
args.settings.system,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
globals.quiet,
globals.preview,
Expand All @@ -298,11 +297,6 @@ async fn run() -> 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 @@ -341,7 +335,7 @@ async fn run() -> Result<ExitStatus> {
args.settings.break_system_packages,
args.settings.target,
args.settings.prefix,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
globals.preview,
cache,
Expand All @@ -359,11 +353,6 @@ async fn run() -> 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);
let requirements = args
Expand Down Expand Up @@ -419,7 +408,7 @@ async fn run() -> Result<ExitStatus> {
args.settings.break_system_packages,
args.settings.target,
args.settings.prefix,
args.settings.concurrency,
globals.concurrency,
globals.native_tls,
globals.preview,
cache,
Expand Down Expand Up @@ -595,6 +584,7 @@ async fn run() -> Result<ExitStatus> {
args.seed,
args.allow_existing,
args.settings.exclude_newer,
globals.concurrency,
globals.native_tls,
globals.preview,
&cache,
Expand Down Expand Up @@ -628,7 +618,7 @@ async fn run() -> Result<ExitStatus> {
globals.isolated,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand All @@ -650,7 +640,7 @@ async fn run() -> Result<ExitStatus> {
args.settings,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand All @@ -670,7 +660,7 @@ async fn run() -> Result<ExitStatus> {
args.settings,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand All @@ -690,7 +680,7 @@ async fn run() -> Result<ExitStatus> {
args.python,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand All @@ -710,7 +700,7 @@ async fn run() -> Result<ExitStatus> {
args.python,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down Expand Up @@ -749,7 +739,7 @@ async fn run() -> Result<ExitStatus> {
globals.isolated,
globals.preview,
globals.connectivity,
Concurrency::default(),
globals.concurrency,
globals.native_tls,
&cache,
printer,
Expand Down
45 changes: 15 additions & 30 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub(crate) struct GlobalSettings {
pub(crate) connectivity: Connectivity,
pub(crate) isolated: bool,
pub(crate) show_settings: bool,
pub(crate) concurrency: Concurrency,
pub(crate) preview: PreviewMode,
}

Expand Down Expand Up @@ -82,6 +83,20 @@ impl GlobalSettings {
},
isolated: args.isolated,
show_settings: args.show_settings,
concurrency: Concurrency {
downloads: env(env::CONCURRENT_DOWNLOADS)
.combine(workspace.and_then(|workspace| workspace.globals.concurrent_downloads))
.map(NonZeroUsize::get)
.unwrap_or(Concurrency::DEFAULT_DOWNLOADS),
builds: env(env::CONCURRENT_BUILDS)
.combine(workspace.and_then(|workspace| workspace.globals.concurrent_builds))
.map(NonZeroUsize::get)
.unwrap_or_else(Concurrency::threads),
installs: env(env::CONCURRENT_INSTALLS)
.combine(workspace.and_then(|workspace| workspace.globals.concurrent_installs))
.map(NonZeroUsize::get)
.unwrap_or_else(Concurrency::threads),
},
preview: PreviewMode::from(
flag(args.preview, args.no_preview)
.combine(workspace.and_then(|workspace| workspace.globals.preview))
Expand Down Expand Up @@ -500,9 +515,6 @@ impl PipCompileSettings {
emit_marker_expression: flag(emit_marker_expression, no_emit_marker_expression),
emit_index_annotation: flag(emit_index_annotation, no_emit_index_annotation),
annotation_style,
concurrent_builds: env(env::CONCURRENT_BUILDS),
concurrent_downloads: env(env::CONCURRENT_DOWNLOADS),
concurrent_installs: env(env::CONCURRENT_INSTALLS),
..PipOptions::from(resolver)
},
filesystem,
Expand Down Expand Up @@ -581,9 +593,6 @@ impl PipSyncSettings {
python_version,
python_platform,
require_hashes: flag(require_hashes, no_require_hashes),
concurrent_builds: env(env::CONCURRENT_BUILDS),
concurrent_downloads: env(env::CONCURRENT_DOWNLOADS),
concurrent_installs: env(env::CONCURRENT_INSTALLS),
..PipOptions::from(installer)
},
filesystem,
Expand Down Expand Up @@ -693,9 +702,6 @@ impl PipInstallSettings {
python_version,
python_platform,
require_hashes: flag(require_hashes, no_require_hashes),
concurrent_builds: env(env::CONCURRENT_BUILDS),
concurrent_downloads: env(env::CONCURRENT_DOWNLOADS),
concurrent_installs: env(env::CONCURRENT_INSTALLS),
..PipOptions::from(installer)
},
filesystem,
Expand Down Expand Up @@ -1296,7 +1302,6 @@ pub(crate) struct PipSettings {
pub(crate) require_hashes: bool,
pub(crate) upgrade: Upgrade,
pub(crate) reinstall: Reinstall,
pub(crate) concurrency: Concurrency,
}

impl PipSettings {
Expand Down Expand Up @@ -1352,9 +1357,6 @@ impl PipSettings {
upgrade_package,
reinstall,
reinstall_package,
concurrent_builds,
concurrent_downloads,
concurrent_installs,
} = pip.unwrap_or_default();

let ResolverInstallerOptions {
Expand Down Expand Up @@ -1515,23 +1517,6 @@ impl PipSettings {
.combine(reinstall_package)
.unwrap_or_default(),
),
concurrency: Concurrency {
downloads: args
.concurrent_downloads
.combine(concurrent_downloads)
.map(NonZeroUsize::get)
.unwrap_or(Concurrency::DEFAULT_DOWNLOADS),
builds: args
.concurrent_builds
.combine(concurrent_builds)
.map(NonZeroUsize::get)
.unwrap_or_else(Concurrency::threads),
installs: args
.concurrent_installs
.combine(concurrent_installs)
.map(NonZeroUsize::get)
.unwrap_or_else(Concurrency::threads),
},
build_options: BuildOptions::new(
NoBinary::from_pip_args(args.no_binary.combine(no_binary).unwrap_or_default())
.combine(NoBinary::from_args(
Expand Down
Loading

0 comments on commit 9a25c44

Please sign in to comment.