Skip to content

Commit

Permalink
make Package.all_classifiers unique even if classfiers in pyproje…
Browse files Browse the repository at this point in the history
…ct.toml has python_classifiers (#578)
  • Loading branch information
yuji38kwmt authored May 8, 2023
1 parent c87a764 commit 1493c48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def all_classifiers(self) -> list[str]:
# it like this so that 3.10 is sorted after 3.9.
sorted_classifiers = []
python_classifiers_inserted = False
for classifier in sorted(set(classifiers)):
for classifier in sorted(set(classifiers) - set(python_classifiers)):
if (
not python_classifiers_inserted
and classifier > python_classifier_prefix
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/project_with_duplicated_classifiers/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "project_with_duplicated_classifiers"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"

classifiers = [
# Duplicated classifiers
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Build Tools",
# The following classifiers are automatically generated
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]

[tool.poetry.dependencies]
python = "^3.8"
16 changes: 16 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,19 @@ def test_create_dependency_marker_variants(
assert dep.python_versions == exp_python
assert dep.python_constraint == parse_constraint(exp_python)
assert str(dep.marker) == exp_marker


def test_all_classifiers_unique_even_if_classifiers_is_duplicated() -> None:
poetry = Factory().create_poetry(
fixtures_dir / "project_with_duplicated_classifiers"
)
package = poetry.package
assert package.all_classifiers == [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Build Tools",
]

0 comments on commit 1493c48

Please sign in to comment.