Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,14 @@ pub struct PipFreezeArgs {
#[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool,

/// List packages from the specified `--target` directory.
#[arg(long, conflicts_with_all = ["prefix", "paths"])]
pub target: Option<PathBuf>,

/// List packages from the specified `--prefix` directory.
#[arg(long, conflicts_with_all = ["target", "paths"])]
pub prefix: Option<PathBuf>,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}
Expand Down Expand Up @@ -2557,6 +2565,14 @@ pub struct PipListArgs {
#[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool,

/// List packages from the specified `--target` directory.
#[arg(long, conflicts_with = "prefix")]
pub target: Option<PathBuf>,

/// List packages from the specified `--prefix` directory.
#[arg(long, conflicts_with = "target")]
pub prefix: Option<PathBuf>,

#[command(flatten)]
pub compat_args: compat::PipListCompatArgs,
}
Expand Down Expand Up @@ -2672,6 +2688,14 @@ pub struct PipShowArgs {
#[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool,

/// Show a package from the specified `--target` directory.
#[arg(long, conflicts_with = "prefix")]
pub target: Option<PathBuf>,

/// Show a package from the specified `--prefix` directory.
#[arg(long, conflicts_with = "target")]
pub prefix: Option<PathBuf>,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}
Expand Down
23 changes: 22 additions & 1 deletion crates/uv/src/commands/pip/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use std::path::PathBuf;
use anyhow::Result;
use itertools::Itertools;
use owo_colors::OwoColorize;
use tracing::debug;

use uv_cache::Cache;
use uv_distribution_types::{Diagnostic, InstalledDistKind, Name};
use uv_fs::Simplified;
use uv_installer::SitePackages;
use uv_preview::Preview;
use uv_python::PythonPreference;
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonRequest};
use uv_python::{EnvironmentPreference, Prefix, PythonEnvironment, PythonRequest, Target};

use crate::commands::ExitStatus;
use crate::commands::pip::operations::report_target_environment;
Expand All @@ -22,6 +24,8 @@ pub(crate) fn pip_freeze(
strict: bool,
python: Option<&str>,
system: bool,
target: Option<Target>,
prefix: Option<Prefix>,
paths: Option<Vec<PathBuf>>,
cache: &Cache,
printer: Printer,
Expand All @@ -36,6 +40,23 @@ pub(crate) fn pip_freeze(
preview,
)?;

// Apply any `--target` or `--prefix` directories.
let environment = if let Some(target) = target {
debug!(
"Using `--target` directory at {}",
target.root().user_display()
);
environment.with_target(target)?
} else if let Some(prefix) = prefix {
debug!(
"Using `--prefix` directory at {}",
prefix.root().user_display()
);
environment.with_prefix(prefix)?
} else {
environment
};

report_target_environment(&environment, cache, printer)?;

// Collect all the `site-packages` directories.
Expand Down
22 changes: 21 additions & 1 deletion crates/uv/src/commands/pip/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use owo_colors::OwoColorize;
use rustc_hash::FxHashMap;
use serde::Serialize;
use tokio::sync::Semaphore;
use tracing::debug;
use unicode_width::UnicodeWidthStr;

use uv_cache::{Cache, Refresh};
Expand All @@ -25,7 +26,7 @@ use uv_normalize::PackageName;
use uv_pep440::Version;
use uv_preview::Preview;
use uv_python::PythonRequest;
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonPreference};
use uv_python::{EnvironmentPreference, Prefix, PythonEnvironment, PythonPreference, Target};
use uv_resolver::{ExcludeNewer, PrereleaseMode};

use crate::commands::ExitStatus;
Expand All @@ -51,6 +52,8 @@ pub(crate) async fn pip_list(
exclude_newer: ExcludeNewer,
python: Option<&str>,
system: bool,
target: Option<Target>,
prefix: Option<Prefix>,
cache: &Cache,
printer: Printer,
preview: Preview,
Expand All @@ -69,6 +72,23 @@ pub(crate) async fn pip_list(
preview,
)?;

// Apply any `--target` or `--prefix` directories.
let environment = if let Some(target) = target {
debug!(
"Using `--target` directory at {}",
target.root().user_display()
);
environment.with_target(target)?
} else if let Some(prefix) = prefix {
debug!(
"Using `--prefix` directory at {}",
prefix.root().user_display()
);
environment.with_prefix(prefix)?
} else {
environment
};

report_target_environment(&environment, cache, printer)?;

// Build the installed index.
Expand Down
24 changes: 23 additions & 1 deletion crates/uv/src/commands/pip/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use fs_err::File;
use itertools::{Either, Itertools};
use owo_colors::OwoColorize;
use rustc_hash::FxHashMap;
use tracing::debug;

use uv_cache::Cache;
use uv_distribution_types::{Diagnostic, Name};
Expand All @@ -13,7 +14,9 @@ use uv_install_wheel::read_record_file;
use uv_installer::SitePackages;
use uv_normalize::PackageName;
use uv_preview::Preview;
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonPreference, PythonRequest};
use uv_python::{
EnvironmentPreference, Prefix, PythonEnvironment, PythonPreference, PythonRequest, Target,
};

use crate::commands::ExitStatus;
use crate::commands::pip::operations::report_target_environment;
Expand All @@ -25,6 +28,8 @@ pub(crate) fn pip_show(
strict: bool,
python: Option<&str>,
system: bool,
target: Option<Target>,
prefix: Option<Prefix>,
files: bool,
cache: &Cache,
printer: Printer,
Expand Down Expand Up @@ -52,6 +57,23 @@ pub(crate) fn pip_show(
preview,
)?;

// Apply any `--target` or `--prefix` directories.
let environment = if let Some(target) = target {
debug!(
"Using `--target` directory at {}",
target.root().user_display()
);
environment.with_target(target)?
} else if let Some(prefix) = prefix {
debug!(
"Using `--prefix` directory at {}",
prefix.root().user_display()
);
environment.with_prefix(prefix)?
} else {
environment
};

report_target_environment(&environment, cache, printer)?;

// Build the installed index.
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.strict,
args.settings.python.as_deref(),
args.settings.system,
args.settings.target,
args.settings.prefix,
args.paths,
&cache,
printer,
Expand Down Expand Up @@ -974,6 +976,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.exclude_newer,
args.settings.python.as_deref(),
args.settings.system,
args.settings.target,
args.settings.prefix,
&cache,
printer,
globals.preview,
Expand All @@ -995,6 +999,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.strict,
args.settings.python.as_deref(),
args.settings.system,
args.settings.target,
args.settings.prefix,
args.files,
&cache,
printer,
Expand Down
12 changes: 12 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,8 @@ impl PipFreezeSettings {
paths,
system,
no_system,
target,
prefix,
compat_args: _,
} = args;

Expand All @@ -2782,6 +2784,8 @@ impl PipFreezeSettings {
python: python.and_then(Maybe::into_option),
system: flag(system, no_system, "system"),
strict: flag(strict, no_strict, "strict"),
target,
prefix,
..PipOptions::default()
},
filesystem,
Expand Down Expand Up @@ -2821,6 +2825,8 @@ impl PipListSettings {
python,
system,
no_system,
target,
prefix,
compat_args: _,
} = args;

Expand All @@ -2834,6 +2840,8 @@ impl PipListSettings {
python: python.and_then(Maybe::into_option),
system: flag(system, no_system, "system"),
strict: flag(strict, no_strict, "strict"),
target,
prefix,
..PipOptions::from(fetch)
},
filesystem,
Expand Down Expand Up @@ -2866,6 +2874,8 @@ impl PipShowSettings {
python,
system,
no_system,
target,
prefix,
compat_args: _,
} = args;

Expand All @@ -2877,6 +2887,8 @@ impl PipShowSettings {
python: python.and_then(Maybe::into_option),
system: flag(system, no_system, "system"),
strict: flag(strict, no_strict, "strict"),
target,
prefix,
..PipOptions::default()
},
filesystem,
Expand Down
92 changes: 92 additions & 0 deletions crates/uv/tests/it/pip_freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,95 @@ fn freeze_with_quiet_flag() -> Result<()> {

Ok(())
}

#[test]
fn freeze_target() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;

let target = context.temp_dir.child("target");

// Install packages to a target directory.
context
.pip_install()
.arg("-r")
.arg("requirements.txt")
.arg("--target")
.arg(target.path())
.assert()
.success();

// Freeze packages in the target directory.
uv_snapshot!(context.filters(), context.pip_freeze()
.arg("--target")
.arg(target.path()), @r###"
success: true
exit_code: 0
----- stdout -----
markupsafe==2.1.3
tomli==2.0.1

----- stderr -----
"###
);

// Without --target, the packages should not be visible.
uv_snapshot!(context.pip_freeze(), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
"###
);

Ok(())
}

#[test]
fn freeze_prefix() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;

let prefix = context.temp_dir.child("prefix");

// Install packages to a prefix directory.
context
.pip_install()
.arg("-r")
.arg("requirements.txt")
.arg("--prefix")
.arg(prefix.path())
.assert()
.success();

// Freeze packages in the prefix directory.
uv_snapshot!(context.filters(), context.pip_freeze()
.arg("--prefix")
.arg(prefix.path()), @r###"
success: true
exit_code: 0
----- stdout -----
markupsafe==2.1.3
tomli==2.0.1

----- stderr -----
"###
);

// Without --prefix, the packages should not be visible.
uv_snapshot!(context.pip_freeze(), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
"###
);

Ok(())
}
Loading
Loading