Skip to content

Commit

Permalink
Add uv pip show --files
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Oct 19, 2024
1 parent e980c1b commit 5b1dbd3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,10 @@ pub struct PipShowArgs {
#[arg(long, overrides_with("strict"), hide = true)]
pub no_strict: bool,

/// Show the full list of installed files for each package.
#[arg(short, long)]
pub files: bool,

/// The Python interpreter to find the package in.
///
/// By default, uv looks for packages in a virtual environment but will look
Expand Down
13 changes: 13 additions & 0 deletions crates/uv/src/commands/pip/show.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::fmt::Write;

use anyhow::Result;
use fs_err::File;
use itertools::{Either, Itertools};
use owo_colors::OwoColorize;
use rustc_hash::FxHashMap;

use uv_cache::Cache;
use uv_distribution_types::{Diagnostic, Name};
use uv_fs::Simplified;
use uv_install_wheel::read_record_file;
use uv_installer::SitePackages;
use uv_normalize::PackageName;
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonRequest};
Expand All @@ -22,6 +24,7 @@ pub(crate) fn pip_show(
strict: bool,
python: Option<&str>,
system: bool,
files: bool,
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
Expand Down Expand Up @@ -184,6 +187,16 @@ pub(crate) fn pip_show(
)?;
}
}

// If requests, show the list of installed files.
if files {
let path = distribution.path().join("RECORD");
let record = read_record_file(&mut File::open(path)?)?;
writeln!(printer.stdout(), "Files:")?;
for entry in record {
writeln!(printer.stdout(), " {}", entry.path)?;
}
}
}

// Validate that the environment is consistent.
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.strict,
args.settings.python.as_deref(),
args.settings.system,
args.files,
&cache,
printer,
)
Expand Down
3 changes: 3 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,7 @@ impl PipListSettings {
#[derive(Debug, Clone)]
pub(crate) struct PipShowSettings {
pub(crate) package: Vec<PackageName>,
pub(crate) files: bool,
pub(crate) settings: PipSettings,
}

Expand All @@ -1638,6 +1639,7 @@ impl PipShowSettings {
package,
strict,
no_strict,
files,
python,
system,
no_system,
Expand All @@ -1646,6 +1648,7 @@ impl PipShowSettings {

Self {
package,
files,
settings: PipSettings::combine(
PipOptions {
python: python.and_then(Maybe::into_option),
Expand Down
48 changes: 48 additions & 0 deletions crates/uv/tests/it/pip_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,51 @@ fn show_required_by_multiple() -> Result<()> {

Ok(())
}

#[test]
fn show_files() {
let context = TestContext::new("3.12");

uv_snapshot!(context
.pip_install()
.arg("MarkupSafe==2.1.3")
.arg("--strict"), @r#"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ markupsafe==2.1.3
"#
);

uv_snapshot!(context.pip_show().arg("markupsafe").arg("--files"), @r#"
success: true
exit_code: 0
----- stdout -----
Name: markupsafe
Version: 2.1.3
Location: /Users/Jo/.local/share/uv/tests/.tmpxusOsE/temp/.venv/lib/python3.12/site-packages
Requires:
Required-by:
Files:
MarkupSafe-2.1.3.dist-info/INSTALLER
MarkupSafe-2.1.3.dist-info/LICENSE.rst
MarkupSafe-2.1.3.dist-info/METADATA
MarkupSafe-2.1.3.dist-info/RECORD
MarkupSafe-2.1.3.dist-info/REQUESTED
MarkupSafe-2.1.3.dist-info/WHEEL
MarkupSafe-2.1.3.dist-info/top_level.txt
markupsafe/__init__.py
markupsafe/_native.py
markupsafe/_speedups.c
markupsafe/_speedups.cpython-312-darwin.so
markupsafe/_speedups.pyi
markupsafe/py.typed
----- stderr -----
"#);
}
2 changes: 2 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -6440,6 +6440,8 @@ uv pip show [OPTIONS] [PACKAGE]...

<p>See <code>--project</code> to only change the project root directory.</p>

</dd><dt><code>--files</code>, <code>-f</code></dt><dd><p>Show the full list of installed files for each package</p>

</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>

</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
Expand Down

0 comments on commit 5b1dbd3

Please sign in to comment.