Improve the CLI documentation for uv remove (#5916)

Also, renames a `requirements` variable to `packages` for clarity and
fixes the definition of `frozen` for `uv add`.
This commit is contained in:
Zanie Blue 2024-08-08 13:12:49 -05:00 committed by GitHub
parent dc3f498f58
commit d2681320d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 31 deletions

View file

@ -2362,13 +2362,9 @@ pub struct AddArgs {
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
/// Run without updating the `uv.lock` file.
/// Add dependencies without re-locking the project.
///
/// Instead of checking if the lockfile is up-to-date, uses the versions in
/// the lockfile as the source of truth. If the lockfile is missing, uv will
/// exit with an error. If the `pyproject.toml` includes new dependencies
/// that have not been included in the lockfile yet, they will not be
/// present in the environment.
/// The project environment will not be synced.
#[arg(long, conflicts_with = "locked")]
pub frozen: bool,
@ -2402,15 +2398,15 @@ pub struct AddArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct RemoveArgs {
/// The names of the packages to remove (e.g., `ruff`).
/// The names of the dependencies to remove (e.g., `ruff`).
#[arg(required = true)]
pub requirements: Vec<PackageName>,
pub packages: Vec<PackageName>,
/// Remove the requirements from development dependencies.
/// Remove the packages from the development dependencies.
#[arg(long, conflicts_with("optional"))]
pub dev: bool,
/// Remove the requirements from the specified optional dependency group.
/// Remove the packages from the specified optional dependency group.
#[arg(long, conflicts_with("dev"))]
pub optional: Option<ExtraName>,
@ -2419,10 +2415,15 @@ pub struct RemoveArgs {
pub no_sync: bool,
/// Assert that the `uv.lock` will remain unchanged.
///
/// Requires that the lockfile is up-to-date. If the lockfile is missing, or
/// if it needs to be updated, uv will exit with an error.
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
/// Remove the requirements without updating the `uv.lock` file.
/// Remove dependencies without re-locking the project.
///
/// The project environment will not be synced.
#[arg(long, conflicts_with = "locked")]
pub frozen: bool,
@ -2435,7 +2436,7 @@ pub struct RemoveArgs {
#[command(flatten)]
pub refresh: RefreshArgs,
/// Remove the dependency from a specific package in the workspace.
/// Remove the dependencies from a specific package in the workspace.
#[arg(long, conflicts_with = "isolated")]
pub package: Option<PackageName>,

View file

@ -23,7 +23,7 @@ pub(crate) async fn remove(
locked: bool,
frozen: bool,
no_sync: bool,
requirements: Vec<PackageName>,
packages: Vec<PackageName>,
dependency_type: DependencyType,
package: Option<PackageName>,
python: Option<String>,
@ -52,30 +52,32 @@ pub(crate) async fn remove(
};
let mut pyproject = PyProjectTomlMut::from_toml(project.current_project().pyproject_toml())?;
for req in requirements {
for package in packages {
match dependency_type {
DependencyType::Production => {
let deps = pyproject.remove_dependency(&req)?;
let deps = pyproject.remove_dependency(&package)?;
if deps.is_empty() {
warn_if_present(&req, &pyproject);
anyhow::bail!("The dependency `{req}` could not be found in `dependencies`");
warn_if_present(&package, &pyproject);
anyhow::bail!(
"The dependency `{package}` could not be found in `dependencies`"
);
}
}
DependencyType::Dev => {
let deps = pyproject.remove_dev_dependency(&req)?;
let deps = pyproject.remove_dev_dependency(&package)?;
if deps.is_empty() {
warn_if_present(&req, &pyproject);
warn_if_present(&package, &pyproject);
anyhow::bail!(
"The dependency `{req}` could not be found in `dev-dependencies`"
"The dependency `{package}` could not be found in `dev-dependencies`"
);
}
}
DependencyType::Optional(ref group) => {
let deps = pyproject.remove_optional_dependency(&req, group)?;
let deps = pyproject.remove_optional_dependency(&package, group)?;
if deps.is_empty() {
warn_if_present(&req, &pyproject);
warn_if_present(&package, &pyproject);
anyhow::bail!(
"The dependency `{req}` could not be found in `optional-dependencies`"
"The dependency `{package}` could not be found in `optional-dependencies`"
);
}
}

View file

@ -1108,7 +1108,7 @@ async fn run_project(
args.locked,
args.frozen,
args.no_sync,
args.requirements,
args.packages,
args.dependency_type,
args.package,
args.python,

View file

@ -722,7 +722,7 @@ pub(crate) struct RemoveSettings {
pub(crate) locked: bool,
pub(crate) frozen: bool,
pub(crate) no_sync: bool,
pub(crate) requirements: Vec<PackageName>,
pub(crate) packages: Vec<PackageName>,
pub(crate) dependency_type: DependencyType,
pub(crate) package: Option<PackageName>,
pub(crate) python: Option<String>,
@ -737,7 +737,7 @@ impl RemoveSettings {
let RemoveArgs {
dev,
optional,
requirements,
packages,
no_sync,
locked,
frozen,
@ -760,7 +760,7 @@ impl RemoveSettings {
locked,
frozen,
no_sync,
requirements,
packages,
dependency_type,
package,
python,

View file

@ -555,18 +555,18 @@ uv will search for a project in the current directory or any parent directory. I
<h3 class="cli-reference">Usage</h3>
```
uv remove [OPTIONS] <REQUIREMENTS>...
uv remove [OPTIONS] <PACKAGES>...
```
<h3 class="cli-reference">Arguments</h3>
<dl class="cli-reference"><dt><code>REQUIREMENTS</code></dt><dd><p>The names of the packages to remove (e.g., <code>ruff</code>)</p>
<dl class="cli-reference"><dt><code>PACKAGES</code></dt><dd><p>The names of the dependencies to remove (e.g., <code>ruff</code>)</p>
</dd></dl>
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt><code>--optional</code> <i>optional</i></dt><dd><p>Remove the requirements from the specified optional dependency group</p>
<dl class="cli-reference"><dt><code>--optional</code> <i>optional</i></dt><dd><p>Remove the packages from the specified optional dependency group</p>
</dd><dt><code>--index-url</code>, <code>-i</code> <i>index-url</i></dt><dd><p>The URL of the Python package index (by default: &lt;https://pypi.org/simple&gt;).</p>
@ -677,7 +677,7 @@ uv remove [OPTIONS] <REQUIREMENTS>...
</dd><dt><code>--refresh-package</code> <i>refresh-package</i></dt><dd><p>Refresh cached data for a specific package</p>
</dd><dt><code>--package</code> <i>package</i></dt><dd><p>Remove the dependency from a specific package in the workspace</p>
</dd><dt><code>--package</code> <i>package</i></dt><dd><p>Remove the dependencies from a specific package in the workspace</p>
</dd><dt><code>--python</code>, <code>-p</code> <i>python</i></dt><dd><p>The Python interpreter to use for resolving and syncing.</p>