Skip to content

Commit

Permalink
Remove overrides and constraints support
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 23, 2024
1 parent a0fa37f commit 6fb27cf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 335 deletions.
38 changes: 8 additions & 30 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,14 @@ pub struct RunArgs {
#[arg(long)]
pub with: Vec<String>,

/// Run with all packages listed in the given `requirements.txt` files.
///
/// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
///
/// If `-` is provided, then requirements will be read from stdin.
#[arg(long, value_parser = parse_maybe_file_path)]
pub with_requirements: Vec<Maybe<PathBuf>>,

/// Assert that the `uv.lock` will remain unchanged.
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
Expand Down Expand Up @@ -1867,36 +1875,6 @@ pub struct RunArgs {
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, env = "UV_PYTHON", verbatim_doc_comment)]
pub python: Option<String>,

/// Require all packages listed in the given `requirements.txt` files.
///
/// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
///
/// If `-` is provided, then requirements will be read from stdin.
#[arg(long, short, value_parser = parse_maybe_file_path)]
pub requirements: Vec<Maybe<PathBuf>>,

/// Constrain versions using the given requirements files.
///
/// Constraints files are `requirements.txt`-like files that only control the _version_ of a
/// requirement that's installed. However, including a package in a constraints file will _not_
/// trigger the installation of that package.
///
/// This is equivalent to pip's `--constraint` option.
#[arg(long, short, env = "UV_CONSTRAINTS", value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraints: Vec<Maybe<PathBuf>>,

/// Override versions using the given requirements files.
///
/// Overrides files are `requirements.txt`-like files that force a specific version of a
/// requirement to be installed, regardless of the requirements declared by any constituent
/// package, and regardless of whether this would be considered an invalid resolution.
///
/// While constraints are _additive_, in that they're combined with the requirements of the
/// constituent packages, overrides are _absolute_, in that they completely replace the
/// requirements of the constituent packages.
#[arg(long, env = "UV_OVERRIDES", value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub r#overrides: Vec<Maybe<PathBuf>>,
}

#[derive(Args)]
Expand Down
57 changes: 23 additions & 34 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use uv_python::{
request_from_version_file, EnvironmentPreference, Interpreter, PythonEnvironment, PythonFetch,
PythonInstallation, PythonPreference, PythonRequest, VersionRequest,
};
use uv_requirements::RequirementsSource;
use uv_requirements::{RequirementsSource, RequirementsSpecification};
use uv_warnings::warn_user_once;
use uv_workspace::{VirtualProject, Workspace, WorkspaceError};

use crate::commands::pip::operations::{self, Modifications};
use crate::commands::pip::operations::Modifications;
use crate::commands::project::environment::CachedEnvironment;
use crate::commands::project::ProjectError;
use crate::commands::reporters::PythonDownloadReporter;
Expand All @@ -38,8 +38,6 @@ use crate::settings::ResolverInstallerSettings;
pub(crate) async fn run(
command: ExternalCommand,
requirements: Vec<RequirementsSource>,
constraints: &[RequirementsSource],
overrides: &[RequirementsSource],
locked: bool,
frozen: bool,
package: Option<PackageName>,
Expand All @@ -63,23 +61,19 @@ pub(crate) async fn run(

// These cases seem quite complex because (in theory) they should change the "current package".
// Let's ban them entirely for now.
if requirements
.iter()
.any(|source| matches!(source, RequirementsSource::PyprojectToml(_)))
{
bail!("Adding requirements from a `pyproject.toml` is not supported in `uv run`");
}
if requirements
.iter()
.any(|source| matches!(source, RequirementsSource::SetupCfg(_)))
{
bail!("Adding requirements from a `setup.cfg` is not supported in `uv run`");
}
if requirements
.iter()
.any(|source| matches!(source, RequirementsSource::SetupCfg(_)))
{
bail!("Adding requirements from a `setup.py` is not supported in `uv run`");
for source in &requirements {
match source {
RequirementsSource::PyprojectToml(_) => {
bail!("Adding requirements from a `pyproject.toml` is not supported in `uv run`");
}
RequirementsSource::SetupPy(_) => {
bail!("Adding requirements from a `setup.py` is not supported in `uv run`");
}
RequirementsSource::SetupCfg(_) => {
bail!("Adding requirements from a `setup.cfg` is not supported in `uv run`");
}
_ => {}
}
}

// Parse the input command.
Expand Down Expand Up @@ -286,21 +280,15 @@ pub(crate) async fn run(
}

// Read the requirements.
let spec = if requirements.is_empty() && constraints.is_empty() && overrides.is_empty() {
let spec = if requirements.is_empty() {
None
} else {
let client_builder = BaseClientBuilder::new()
.connectivity(connectivity)
.native_tls(native_tls);

let spec = operations::read_requirements(
&requirements,
constraints,
overrides,
&extras,
&client_builder,
)
.await?;
let spec =
RequirementsSpecification::from_simple_sources(&requirements, &client_builder).await?;

Some(spec)
};
Expand All @@ -309,7 +297,7 @@ pub(crate) async fn run(
// any `--with` requirements, and we already have a base environment, then there's no need to
// create an additional environment.
let skip_ephemeral = base_interpreter.as_ref().is_some_and(|base_interpreter| {
// No additional requrements
// No additional requirements.
let Some(spec) = spec.as_ref() else {
return true;
};
Expand All @@ -322,9 +310,10 @@ pub(crate) async fn run(
return false;
}

// `SitePackages::satisfies` handle overrides yet and constraints are only enforced on `--with`
// requirements instead of the project requirements so we perform a full resolution
// to ensure things are up to date
// `SitePackages::satisfies` doesn't handle overrides yet, and constraints are only enforced
// on `--with` requirements instead of the project requirements, so we perform a full
// resolution to ensure things are up-to-date.
// TODO(charlie): Support constraints and overrides in `uv run`.
if !(spec.constraints.is_empty() && spec.overrides.is_empty()) {
return false;
}
Expand Down
14 changes: 1 addition & 13 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,27 +853,15 @@ async fn run_project(
.into_iter()
.map(RequirementsSource::from_package)
.chain(
args.requirements
args.with_requirements
.into_iter()
.map(RequirementsSource::from_requirements_file),
)
.collect::<Vec<_>>();
let constraints = args
.constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
let overrides = args
.r#overrides
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Vec<_>>();

commands::run(
args.command,
requirements,
&constraints,
&overrides,
args.locked,
args.frozen,
args.package,
Expand Down
24 changes: 6 additions & 18 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,9 @@ pub(crate) struct RunSettings {
pub(crate) dev: bool,
pub(crate) command: ExternalCommand,
pub(crate) with: Vec<String>,
pub(crate) with_requirements: Vec<PathBuf>,
pub(crate) package: Option<PackageName>,
pub(crate) python: Option<String>,
pub(crate) requirements: Vec<PathBuf>,
pub(crate) constraints: Vec<PathBuf>,
pub(crate) r#overrides: Vec<PathBuf>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
}
Expand All @@ -207,14 +205,12 @@ impl RunSettings {
no_dev,
command,
with,
with_requirements,
installer,
build,
refresh,
package,
python,
requirements,
constraints,
r#overrides,
} = args;

Self {
Expand All @@ -227,21 +223,13 @@ impl RunSettings {
dev: flag(dev, no_dev).unwrap_or(true),
command,
with,
package,
python,
refresh: Refresh::from(refresh),
requirements: requirements
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
constraints: constraints
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
r#overrides: r#overrides
with_requirements: with_requirements
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
package,
python,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
resolver_installer_options(installer, build),
filesystem,
Expand Down
Loading

0 comments on commit 6fb27cf

Please sign in to comment.