Rename `--raw-sources` to `--raw` (#13348)

This also omits bounds on constraints, and is useful for that. This
retains `--raw-sources` as an alias. I've had this on my mind for a
while, but https://github.com/astral-sh/uv/pull/12946 reminded me of it
again.
This commit is contained in:
Zanie Blue 2025-05-08 15:05:03 -05:00 committed by GitHub
parent 9a15240147
commit 26e37f3a1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 24 deletions

View File

@ -3481,19 +3481,24 @@ pub struct AddArgs {
#[arg(long, overrides_with = "editable", hide = true)] #[arg(long, overrides_with = "editable", hide = true)]
pub no_editable: bool, pub no_editable: bool,
/// Add source requirements to `project.dependencies`, rather than `tool.uv.sources`. /// Add a dependency as provided.
/// ///
/// By default, uv will use the `tool.uv.sources` section to record source information for Git, /// By default, uv will use the `tool.uv.sources` section to record source information for Git,
/// local, editable, and direct URL requirements. /// local, editable, and direct URL requirements. When `--raw` is provided, uv will add source
/// requirements to `project.dependencies`, rather than `tool.uv.sources`.
///
/// Additionally, by default, uv will add bounds to your dependency, e.g., `foo>=1.0.0`. When
/// `--raw` is provided, uv will add the dependency without bounds.
#[arg( #[arg(
long, long,
conflicts_with = "editable", conflicts_with = "editable",
conflicts_with = "no_editable", conflicts_with = "no_editable",
conflicts_with = "rev", conflicts_with = "rev",
conflicts_with = "tag", conflicts_with = "tag",
conflicts_with = "branch" conflicts_with = "branch",
alias = "raw-sources"
)] )]
pub raw_sources: bool, pub raw: bool,
/// Commit to use when adding a dependency from Git. /// Commit to use when adding a dependency from Git.
#[arg(long, group = "git-ref", action = clap::ArgAction::Set)] #[arg(long, group = "git-ref", action = clap::ArgAction::Set)]

View File

@ -72,7 +72,7 @@ pub(crate) async fn add(
marker: Option<MarkerTree>, marker: Option<MarkerTree>,
editable: Option<bool>, editable: Option<bool>,
dependency_type: DependencyType, dependency_type: DependencyType,
raw_sources: bool, raw: bool,
indexes: Vec<Index>, indexes: Vec<Index>,
rev: Option<String>, rev: Option<String>,
tag: Option<String>, tag: Option<String>,
@ -444,7 +444,7 @@ pub(crate) async fn add(
&target, &target,
editable, editable,
&dependency_type, &dependency_type,
raw_sources, raw,
rev.as_deref(), rev.as_deref(),
tag.as_deref(), tag.as_deref(),
branch.as_deref(), branch.as_deref(),
@ -454,7 +454,7 @@ pub(crate) async fn add(
)?; )?;
// Add any indexes that were provided on the command-line, in priority order. // Add any indexes that were provided on the command-line, in priority order.
if !raw_sources { if !raw {
let urls = IndexUrls::from_indexes(indexes); let urls = IndexUrls::from_indexes(indexes);
for index in urls.defined_indexes() { for index in urls.defined_indexes() {
toml.add_index(index)?; toml.add_index(index)?;
@ -519,7 +519,7 @@ pub(crate) async fn add(
sync_state, sync_state,
locked, locked,
&dependency_type, &dependency_type,
raw_sources, raw,
constraints, constraints,
&settings, &settings,
&network_settings, &network_settings,
@ -551,7 +551,7 @@ fn edits(
target: &AddTarget, target: &AddTarget,
editable: Option<bool>, editable: Option<bool>,
dependency_type: &DependencyType, dependency_type: &DependencyType,
raw_sources: bool, raw: bool,
rev: Option<&str>, rev: Option<&str>,
tag: Option<&str>, tag: Option<&str>,
branch: Option<&str>, branch: Option<&str>,
@ -569,7 +569,7 @@ fn edits(
requirement.extras = ex.into_boxed_slice(); requirement.extras = ex.into_boxed_slice();
let (requirement, source) = match target { let (requirement, source) = match target {
AddTarget::Script(_, _) | AddTarget::Project(_, _) if raw_sources => { AddTarget::Script(_, _) | AddTarget::Project(_, _) if raw => {
(uv_pep508::Requirement::from(requirement), None) (uv_pep508::Requirement::from(requirement), None)
} }
AddTarget::Script(ref script, _) => { AddTarget::Script(ref script, _) => {
@ -743,7 +743,7 @@ async fn lock_and_sync(
sync_state: PlatformState, sync_state: PlatformState,
locked: bool, locked: bool,
dependency_type: &DependencyType, dependency_type: &DependencyType,
raw_sources: bool, raw: bool,
constraints: Vec<NameRequirementSpecification>, constraints: Vec<NameRequirementSpecification>,
settings: &ResolverInstallerSettings, settings: &ResolverInstallerSettings,
network_settings: &NetworkSettings, network_settings: &NetworkSettings,
@ -774,7 +774,7 @@ async fn lock_and_sync(
.into_lock(); .into_lock();
// Avoid modifying the user request further if `--raw-sources` is set. // Avoid modifying the user request further if `--raw-sources` is set.
if !raw_sources { if !raw {
// Extract the minimum-supported version for each dependency. // Extract the minimum-supported version for each dependency.
let mut minimum_version = let mut minimum_version =
FxHashMap::with_capacity_and_hasher(lock.packages().len(), FxBuildHasher); FxHashMap::with_capacity_and_hasher(lock.packages().len(), FxBuildHasher);

View File

@ -1869,7 +1869,7 @@ async fn run_project(
args.marker, args.marker,
args.editable, args.editable,
args.dependency_type, args.dependency_type,
args.raw_sources, args.raw,
args.indexes, args.indexes,
args.rev, args.rev,
args.tag, args.tag,

View File

@ -1252,7 +1252,7 @@ pub(crate) struct AddSettings {
pub(crate) dependency_type: DependencyType, pub(crate) dependency_type: DependencyType,
pub(crate) editable: Option<bool>, pub(crate) editable: Option<bool>,
pub(crate) extras: Vec<ExtraName>, pub(crate) extras: Vec<ExtraName>,
pub(crate) raw_sources: bool, pub(crate) raw: bool,
pub(crate) rev: Option<String>, pub(crate) rev: Option<String>,
pub(crate) tag: Option<String>, pub(crate) tag: Option<String>,
pub(crate) branch: Option<String>, pub(crate) branch: Option<String>,
@ -1280,7 +1280,7 @@ impl AddSettings {
editable, editable,
no_editable, no_editable,
extra, extra,
raw_sources, raw,
rev, rev,
tag, tag,
branch, branch,
@ -1371,7 +1371,7 @@ impl AddSettings {
.collect(), .collect(),
marker, marker,
dependency_type, dependency_type,
raw_sources, raw,
rev, rev,
tag, tag,
branch, branch,

View File

@ -799,18 +799,18 @@ fn add_raw_error() -> Result<()> {
"#})?; "#})?;
// Provide a tag without a Git source. // Provide a tag without a Git source.
uv_snapshot!(context.filters(), context.add().arg("uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage").arg("--tag").arg("0.0.1").arg("--raw-sources"), @r###" uv_snapshot!(context.filters(), context.add().arg("uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage").arg("--tag").arg("0.0.1").arg("--raw-sources"), @r"
success: false success: false
exit_code: 2 exit_code: 2
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
error: the argument '--tag <TAG>' cannot be used with '--raw-sources' error: the argument '--tag <TAG>' cannot be used with '--raw'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>> Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
For more information, try '--help'. For more information, try '--help'.
"###); ");
Ok(()) Ok(())
} }
@ -3959,7 +3959,7 @@ fn add_lower_bound_existing() -> Result<()> {
Ok(()) Ok(())
} }
/// Avoid setting a lower bound with `--raw-sources`. /// Avoid setting a lower bound with `--raw`.
#[test] #[test]
fn add_lower_bound_raw() -> Result<()> { fn add_lower_bound_raw() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
@ -3973,8 +3973,8 @@ fn add_lower_bound_raw() -> Result<()> {
dependencies = ["anyio"] dependencies = ["anyio"]
"#})?; "#})?;
// Adding `anyio` should _not_ set a lower-bound when using `--raw-sources`. // Adding `anyio` should _not_ set a lower-bound when using `--raw`.
uv_snapshot!(context.filters(), context.add().arg("anyio").arg("--raw-sources"), @r" uv_snapshot!(context.filters(), context.add().arg("anyio").arg("--raw"), @r"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----

View File

@ -1068,9 +1068,11 @@ uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which uv will write no output to stdout.</p> <p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which uv will write no output to stdout.</p>
</dd><dt id="uv-add--raw-sources"><a href="#uv-add--raw-sources"><code>--raw-sources</code></a></dt><dd><p>Add source requirements to <code>project.dependencies</code>, rather than <code>tool.uv.sources</code>.</p> </dd><dt id="uv-add--raw"><a href="#uv-add--raw"><code>--raw</code></a>, <code>--raw-sources</code></dt><dd><p>Add a dependency as provided.</p>
<p>By default, uv will use the <code>tool.uv.sources</code> section to record source information for Git, local, editable, and direct URL requirements.</p> <p>By default, uv will use the <code>tool.uv.sources</code> section to record source information for Git, local, editable, and direct URL requirements. When <code>--raw</code> is provided, uv will add source requirements to <code>project.dependencies</code>, rather than <code>tool.uv.sources</code>.</p>
<p>Additionally, by default, uv will add bounds to your dependency, e.g., <code>foo&gt;=1.0.0</code>. When <code>--raw</code> is provided, uv will add the dependency without bounds.</p>
</dd><dt id="uv-add--refresh"><a href="#uv-add--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p> </dd><dt id="uv-add--refresh"><a href="#uv-add--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>