Skip to content

Commit

Permalink
tolerate missing project name in validation (#8691)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Nov 19, 2023
1 parent 31540a8 commit 05f5f6c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,10 @@ def validate(

dependencies = {canonicalize_name(d) for d in dependencies}

if canonicalize_name(config["name"]) in dependencies:
project_name = config.get("name")
if project_name is not None and canonicalize_name(project_name) in dependencies:
results["errors"].append(
f"Project name ({config['name']}) is same as one of its dependencies"
f"Project name ({project_name}) is same as one of its dependencies"
)

return results
8 changes: 8 additions & 0 deletions tests/fixtures/nameless_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.poetry]
version = "0.1.0"
description = ""
authors = ["Foo <foo@bar.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
27 changes: 17 additions & 10 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,27 @@ def test_create_poetry_fails_on_invalid_configuration(
with pytest.raises(RuntimeError) as e:
Factory().create_poetry(fixture_dir("invalid_pyproject") / "pyproject.toml")

jsonschema_error = "'description' is a required property"
fastjsonschema_error = "data must contain ['description'] properties"

expected_template = """\
expected = """\
The Poetry configuration is invalid:
- {schema_error}
- data must contain ['description'] properties
- Project name (invalid) is same as one of its dependencies
"""
expected = {
expected_template.format(schema_error=schema_error)
for schema_error in (jsonschema_error, fastjsonschema_error)
}

assert str(e.value) in expected
assert str(e.value) == expected


def test_create_poetry_fails_on_nameless_project(
fixture_dir: FixtureDirGetter,
) -> None:
with pytest.raises(RuntimeError) as e:
Factory().create_poetry(fixture_dir("nameless_pyproject") / "pyproject.toml")

expected = """\
The Poetry configuration is invalid:
- data must contain ['name'] properties
"""

assert str(e.value) == expected


def test_create_poetry_with_local_config(fixture_dir: FixtureDirGetter) -> None:
Expand Down

0 comments on commit 05f5f6c

Please sign in to comment.