Skip to content

Commit

Permalink
Fix console_scripts validation. (#1056)
Browse files Browse the repository at this point in the history
Old validation was looking for `scripts` inside the
[entry-points] table. But the forbidden name is
`console_scripts`.

Issue #1055
  • Loading branch information
Wim-De-Clercq authored Nov 23, 2023
1 parent a0f2bd6 commit d666ae7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/src/hatchling/metadata/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,10 @@ def entry_points(self) -> dict[str, dict[str, str]]:
message = 'Field `project.entry-points` must be a table'
raise TypeError(message)

for forbidden_field in ('scripts', 'gui-scripts'):
for forbidden_field, expected_field in (('console_scripts', 'scripts'), ('gui-scripts', 'gui-scripts')):
if forbidden_field in defined_entry_point_groups:
message = (
f'Field `{forbidden_field}` must be defined as `project.{forbidden_field}` '
f'Field `{forbidden_field}` must be defined as `project.{expected_field}` '
f'instead of in the `project.entry-points` table'
)
raise ValueError(message)
Expand Down
7 changes: 4 additions & 3 deletions tests/backend/metadata/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,14 +1075,15 @@ def test_not_table(self, isolation):
with pytest.raises(TypeError, match='Field `project.entry-points` must be a table'):
_ = metadata.core.entry_points

@pytest.mark.parametrize('field', ['scripts', 'gui-scripts'])
def test_forbidden_fields(self, isolation, field):
@pytest.mark.parametrize(('field', 'expected'), [('console_scripts', 'scripts'), ('gui-scripts', 'gui-scripts')])
def test_forbidden_fields(self, isolation, field, expected):
metadata = ProjectMetadata(str(isolation), None, {'project': {'entry-points': {field: 'foo'}}})

with pytest.raises(
ValueError,
match=(
f'Field `{field}` must be defined as `project.{field}` instead of in the `project.entry-points` table'
f'Field `{field}` must be defined as `project.{expected}` instead of '
f'in the `project.entry-points` table'
),
):
_ = metadata.core.entry_points
Expand Down

0 comments on commit d666ae7

Please sign in to comment.