Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when dependencies are empty with Poetry metadata #1650

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 13 additions & 0 deletions crates/uv/src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use uv_normalize::{ExtraName, PackageName};

use crate::confirm;

use uv_warnings::warn_user;

#[derive(Debug)]
pub(crate) enum RequirementsSource {
/// A package was provided on the command line (e.g., `pip install flask`).
Expand Down Expand Up @@ -234,6 +236,17 @@ impl RequirementsSpecification {
})?);
}

if requirements.is_empty() {
if pyproject_toml.build_system.is_some_and(|build_system| {
build_system
.requires
.iter()
.any(|v| v.name.as_dist_info_name().starts_with("poetry"))
}) {
warn_user!("`{}` does not contain any dependencies (hint: Poetry's format is not supported for now)", path.normalized_display());
Copy link
Contributor

@hauntsaninja hauntsaninja Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be more specific, e.g. hint: specify dependencies in project.dependencies section, tool.poetry.dependencies is not currently supported. I can imagine users taking "Poetry's format" to mean all kinds of things, like literally the use of pyproject.toml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea: #1730

}
}

Self {
project: project_name,
requirements,
Expand Down
40 changes: 40 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,46 @@ optional-dependencies.foo = [
Ok(())
}

/// Show a dedicated warning if the user tries to compile a `pyproject.toml` file with a `poetry`
/// section.
#[test]
fn compile_empty_pyproject_toml_poetry() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"[tool.poetry]
name = "poetry-editable"
version = "0.1.0"
description = ""
authors = ["Astral Software Inc. <hey@astral.sh>"]

[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
"#,
)?;

uv_snapshot!(context.compile()
.arg("pyproject.toml"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv v[VERSION] via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z pyproject.toml

----- stderr -----
warning: `pyproject.toml` does not contain any dependencies (hint: Poetry's format is not supported for now)
Resolved 0 packages in [TIME]
"###
);

Ok(())
}

/// Request multiple extras that do not exist as a dependency group in a `pyproject.toml` file.
#[test]
fn compile_pyproject_toml_extras_missing() -> Result<()> {
Expand Down
Loading