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

tolerate missing project name in validation #8691

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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