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

make Package.all_classifiers unique even if classfiers in pyproject.toml has python_classifiers #578

Merged
merged 2 commits into from
May 8, 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
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 <[email protected]>"]
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",
]