-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve static metadata extraction for Poetry projects (#4182)
## Summary Adds handling for a few cases to improve interoperability with Poetry: - If the `project` schema is invalid, we now raise a hard error, rather than treating the metadata as dynamic and then falling back to the build backend. This could cause problems, I'm not sure. It's stricter than before. - If the project contains `tool.poetry` but omits `project.dependencies`, we now treat it as dynamic. We could go even further and treat _any_ Poetry project as dynamic, but then we'd be ignoring user-declared dependencies, which is also confusing. Closes #4142.
- Loading branch information
1 parent
c6da4f1
commit 125a4b2
Showing
4 changed files
with
166 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -615,6 +615,110 @@ build-backend = "poetry.core.masonry.api" | |
Ok(()) | ||
} | ||
|
||
/// Compile a `pyproject.toml` file with a `poetry` section and a `project` section without a | ||
/// `dependencies` field, which should be treated as an empty list. | ||
#[test] | ||
fn compile_pyproject_toml_poetry_empty_dependencies() -> Result<()> { | ||
let context = TestContext::new("3.12"); | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str( | ||
r#"[project] | ||
name = "poetry-editable" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Astral Software Inc. <[email protected]>"] | ||
[tool.poetry] | ||
name = "poetry-editable" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Astral Software Inc. <[email protected]>"] | ||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
anyio = "^3" | ||
[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 via the following command: | ||
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z pyproject.toml | ||
anyio==3.7.1 | ||
# via poetry-editable (pyproject.toml) | ||
idna==3.6 | ||
# via anyio | ||
sniffio==1.3.1 | ||
# via anyio | ||
----- stderr ----- | ||
Resolved 3 packages in [TIME] | ||
"### | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Compile a `pyproject.toml` file with a `poetry` section and a `project` section with an invalid | ||
/// `dependencies` field. | ||
#[test] | ||
fn compile_pyproject_toml_poetry_invalid_dependencies() -> Result<()> { | ||
let context = TestContext::new("3.12"); | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str( | ||
r#"[project] | ||
name = "poetry-editable" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Astral Software Inc. <[email protected]>"] | ||
[tool.poetry] | ||
name = "poetry-editable" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Astral Software Inc. <[email protected]>"] | ||
[project.dependencies] | ||
python = "^3.12" | ||
msgspec = "^0.18.4" | ||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
anyio = "^3" | ||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
"#, | ||
)?; | ||
|
||
uv_snapshot!(context.compile() | ||
.arg("pyproject.toml"), @r###" | ||
success: false | ||
exit_code: 2 | ||
----- stdout ----- | ||
----- stderr ----- | ||
error: Failed to extract static metadata from `pyproject.toml` | ||
Caused by: TOML parse error at line 13, column 1 | ||
| | ||
13 | [project.dependencies] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
invalid type: map, expected a sequence | ||
"### | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Compile a `pyproject.toml` file that uses setuptools as the build backend. | ||
#[test] | ||
fn compile_pyproject_toml_setuptools() -> Result<()> { | ||
|