Skip to content

Commit

Permalink
Don't warn when --output-file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 25, 2024
1 parent a17c047 commit 94f13e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
11 changes: 0 additions & 11 deletions crates/uv-requirements-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ use uv_distribution_types::{UnresolvedRequirement, UnresolvedRequirementSpecific
use uv_fs::Simplified;
use uv_pep508::{expand_env_vars, Pep508Error, RequirementOrigin, VerbatimUrl};
use uv_pypi_types::{Requirement, VerbatimParsedUrl};
use uv_warnings::warn_user;

use crate::requirement::EditableError;
pub use crate::requirement::RequirementsTxtRequirement;
Expand Down Expand Up @@ -219,16 +218,6 @@ impl RequirementsTxt {
file: requirements_txt.to_path_buf(),
error: err,
})?;
if data == Self::default() {
if requirements_txt == Path::new("-") {
warn_user!("No dependencies found in stdin");
} else {
warn_user!(
"Requirements file {} does not contain any dependencies",
requirements_txt.user_display()
);
}
}

Ok(data)
}
Expand Down
13 changes: 13 additions & 0 deletions crates/uv-requirements/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use uv_pep508::{MarkerTree, UnnamedRequirement, UnnamedRequirementUrl};
use uv_pypi_types::Requirement;
use uv_pypi_types::VerbatimParsedUrl;
use uv_requirements_txt::{RequirementsTxt, RequirementsTxtRequirement};
use uv_warnings::warn_user;
use uv_workspace::pyproject::PyProjectToml;

use crate::RequirementsSource;
Expand Down Expand Up @@ -113,6 +114,18 @@ impl RequirementsSpecification {
}

let requirements_txt = RequirementsTxt::parse(path, &*CWD, client_builder).await?;

if requirements_txt == RequirementsTxt::default() {
if path == Path::new("-") {
warn_user!("No dependencies found in stdin");
} else {
warn_user!(
"Requirements file `{}` does not contain any dependencies",
path.user_display()
);
}
}

Self {
requirements: requirements_txt
.requirements
Expand Down
33 changes: 32 additions & 1 deletion crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn missing_venv() -> Result<()> {
# uv pip compile --cache-dir [CACHE_DIR] requirements.in
----- stderr -----
warning: Requirements file requirements.in does not contain any dependencies
warning: Requirements file `requirements.in` does not contain any dependencies
Resolved in [TIME]
"###
);
Expand All @@ -142,6 +142,37 @@ fn missing_venv() -> Result<()> {
Ok(())
}

#[test]
fn empty_output() -> Result<()> {
let context = TestContext::new("3.12");
context
.temp_dir
.child("requirements.in")
.write_str("iniconfig==1.1.1")?;
context.temp_dir.child("requirements.txt").touch()?;

uv_snapshot!(context.filters(), context.pip_compile()
.arg("requirements.in")
.arg("--output-file")
.arg("requirements.txt"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --output-file requirements.txt
iniconfig==1.1.1
# via -r requirements.in
----- stderr -----
Resolved 1 package in [TIME]
"###
);

context.venv.assert(predicates::path::missing());

Ok(())
}

/// Resolve a specific version of `anyio` from a `pyproject.toml` file.
#[test]
fn compile_pyproject_toml() -> Result<()> {
Expand Down

0 comments on commit 94f13e2

Please sign in to comment.