Skip to content

Commit

Permalink
Make --offline a global argument (#3729)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored May 22, 2024
1 parent 285adae commit d33577f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 129 deletions.
2 changes: 1 addition & 1 deletion crates/uv-workspace/src/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Combine for Options {
fn combine(self, other: Options) -> Options {
Options {
native_tls: self.native_tls.combine(other.native_tls),
offline: self.offline.combine(other.offline),
no_cache: self.no_cache.combine(other.no_cache),
preview: self.preview.combine(other.preview),
cache_dir: self.cache_dir.combine(other.cache_dir),
Expand All @@ -68,7 +69,6 @@ impl Combine for PipOptions {
.break_system_packages
.combine(other.break_system_packages),
target: self.target.combine(other.target),
offline: self.offline.combine(other.offline),
index_url: self.index_url.combine(other.index_url),
extra_index_url: self.extra_index_url.combine(other.extra_index_url),
no_index: self.no_index.combine(other.no_index),
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-workspace/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub(crate) struct Tools {
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Options {
pub native_tls: Option<bool>,
pub offline: Option<bool>,
pub no_cache: Option<bool>,
pub preview: Option<bool>,
pub cache_dir: Option<PathBuf>,
Expand All @@ -48,7 +49,6 @@ pub struct PipOptions {
pub system: Option<bool>,
pub break_system_packages: Option<bool>,
pub target: Option<PathBuf>,
pub offline: Option<bool>,
pub index_url: Option<IndexUrl>,
pub extra_index_url: Option<Vec<IndexUrl>>,
pub no_index: Option<bool>,
Expand Down
97 changes: 28 additions & 69 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ pub(crate) struct GlobalArgs {
#[arg(global = true, long, overrides_with("native_tls"), hide = true)]
pub(crate) no_native_tls: bool,

/// Disable network access, relying only on locally cached data and locally available files.
#[arg(global = true, long, overrides_with("no_offline"))]
pub(crate) offline: bool,

#[arg(global = true, long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// Whether to enable experimental, preview features.
#[arg(global = true, long, hide = true, env = "UV_PREVIEW", value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_preview"))]
pub(crate) preview: bool,
Expand Down Expand Up @@ -366,23 +373,17 @@ pub(crate) struct PipCompileArgs {
pub(crate) custom_compile_command: Option<String>,

/// Run offline, i.e., without accessing the network.
#[arg(
global = true,
long,
conflicts_with = "refresh",
conflicts_with = "refresh_package",
overrides_with("no_offline")
)]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,
/// Refresh all cached data.
#[arg(long, overrides_with("no_refresh"))]
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,

#[arg(long, overrides_with("refresh"), hide = true)]
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,

/// Refresh cached data for a specific package.
Expand Down Expand Up @@ -649,23 +650,16 @@ pub(crate) struct PipSyncArgs {
#[arg(long)]
pub(crate) reinstall_package: Vec<PackageName>,

#[arg(
global = true,
long,
conflicts_with = "refresh",
conflicts_with = "refresh_package",
overrides_with("no_offline")
)]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// Refresh all cached data.
#[arg(long, overrides_with("no_refresh"))]
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,

#[arg(long, overrides_with("refresh"), hide = true)]
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,

/// Refresh cached data for a specific package.
Expand Down Expand Up @@ -1013,23 +1007,16 @@ pub(crate) struct PipInstallArgs {
#[arg(long)]
pub(crate) reinstall_package: Vec<PackageName>,

#[arg(
global = true,
long,
conflicts_with = "refresh",
conflicts_with = "refresh_package",
overrides_with("no_offline")
)]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// Refresh all cached data.
#[arg(long, overrides_with("no_refresh"))]
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,

#[arg(long, overrides_with("refresh"), hide = true)]
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,

/// Refresh cached data for a specific package.
Expand Down Expand Up @@ -1430,13 +1417,6 @@ pub(crate) struct PipUninstallArgs {
/// or system Python interpreter.
#[arg(long)]
pub(crate) target: Option<PathBuf>,

/// Run offline, i.e., without accessing the network.
#[arg(long, overrides_with("no_offline"))]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,
}

#[derive(Args)]
Expand Down Expand Up @@ -1808,13 +1788,6 @@ pub(crate) struct VenvArgs {
#[arg(long, value_enum, env = "UV_KEYRING_PROVIDER")]
pub(crate) keyring_provider: Option<KeyringProviderType>,

/// Run offline, i.e., without accessing the network.
#[arg(long, overrides_with("no_offline"))]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
Expand All @@ -1840,13 +1813,6 @@ pub(crate) struct RunArgs {
#[arg(long)]
pub(crate) with: Vec<String>,

/// Run offline, i.e., without accessing the network.
#[arg(global = true, long, overrides_with("no_offline"))]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
Expand Down Expand Up @@ -1961,11 +1927,4 @@ pub(crate) struct ToolRunArgs {
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Run offline, i.e., without accessing the network.
#[arg(global = true, long, overrides_with("no_offline"))]
pub(crate) offline: bool,

#[arg(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,
}
22 changes: 8 additions & 14 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use anstream::eprintln;
use anyhow::Result;
use clap::error::{ContextKind, ContextValue};
use clap::{CommandFactory, Parser};
use cli::{ToolCommand, ToolNamespace};
use owo_colors::OwoColorize;
use tracing::instrument;

use cli::{ToolCommand, ToolNamespace};
use uv_cache::Cache;
use uv_client::Connectivity;
use uv_requirements::RequirementsSource;
use uv_workspace::Combine;

Expand Down Expand Up @@ -227,7 +226,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.keyring_provider,
args.shared.setup_py,
args.shared.config_setting,
args.shared.connectivity,
globals.connectivity,
args.shared.no_build_isolation,
args.shared.no_build,
args.shared.python_version,
Expand Down Expand Up @@ -277,7 +276,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.index_strategy,
args.shared.keyring_provider,
args.shared.setup_py,
args.shared.connectivity,
globals.connectivity,
&args.shared.config_setting,
args.shared.no_build_isolation,
args.shared.no_build,
Expand Down Expand Up @@ -350,7 +349,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.compile_bytecode,
args.shared.require_hashes,
args.shared.setup_py,
args.shared.connectivity,
globals.connectivity,
&args.shared.config_setting,
args.shared.no_build_isolation,
args.shared.no_build,
Expand Down Expand Up @@ -399,7 +398,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.break_system_packages,
args.shared.target,
cache,
args.shared.connectivity,
globals.connectivity,
globals.native_tls,
globals.preview,
args.shared.keyring_provider,
Expand Down Expand Up @@ -522,7 +521,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.keyring_provider,
uv_virtualenv::Prompt::from_args(prompt),
args.system_site_packages,
args.shared.connectivity,
globals.connectivity,
args.seed,
args.allow_existing,
args.shared.exclude_newer,
Expand Down Expand Up @@ -566,7 +565,7 @@ async fn run() -> Result<ExitStatus> {
args.python,
globals.isolated,
globals.preview,
args.connectivity,
globals.connectivity,
&cache,
printer,
)
Expand Down Expand Up @@ -605,18 +604,13 @@ async fn run() -> Result<ExitStatus> {
Commands::Tool(ToolNamespace {
command: ToolCommand::Run(args),
}) => {
let connectivity = if args.offline {
Connectivity::Offline
} else {
Connectivity::Online
};
commands::run_tool(
args.target,
args.args,
args.python,
globals.isolated,
globals.preview,
connectivity,
globals.connectivity,
&cache,
printer,
)
Expand Down
Loading

0 comments on commit d33577f

Please sign in to comment.