Skip to content

Commit

Permalink
Move all classifier validation code into a helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Jun 24, 2022
1 parent d940d24 commit 89eba1e
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

from pathlib import Path

from trove_classifiers import classifiers
from trove_classifiers import deprecated_classifiers

from poetry.console.commands.command import Command


Expand All @@ -13,25 +10,20 @@ class CheckCommand(Command):
name = "check"
description = "Checks the validity of the <comment>pyproject.toml</comment> file."

def handle(self) -> int:
from poetry.core.pyproject.toml import PyProjectTOML
def validate_classifiers(
self, project_classifiers: set[str]
) -> tuple[list[str], list[str]]:
from trove_classifiers import classifiers
from trove_classifiers import deprecated_classifiers

from poetry.factory import Factory

# Load poetry config and display errors, if any
poetry_file = Factory.locate(Path.cwd())
config = PyProjectTOML(poetry_file).poetry_config
check_result = Factory.validate(config, strict=True)

project_classifiers = set(config.get("classifiers", []))
errors = []
warnings = []

unrecognized = sorted(
project_classifiers - set(classifiers) - set(deprecated_classifiers)
)
if unrecognized:
check_result["errors"].append(
f"Unrecognized classifiers: {unrecognized!r}."
)
errors.append(f"Unrecognized classifiers: {unrecognized!r}.")

deprecated = sorted(
project_classifiers.intersection(set(deprecated_classifiers))
Expand All @@ -46,10 +38,27 @@ def handle(self) -> int:
)
else:
message = (
f"Deprecated classifier {old_classifier!r}. "
"Must be removed."
f"Deprecated classifier {old_classifier!r}. Must be removed."
)
check_result["warnings"].append(message)
warnings.append(message)

return errors, warnings

def handle(self) -> int:
from poetry.core.pyproject.toml import PyProjectTOML

from poetry.factory import Factory

# Load poetry config and display errors, if any
poetry_file = Factory.locate(Path.cwd())
config = PyProjectTOML(poetry_file).poetry_config
check_result = Factory.validate(config, strict=True)

# Validate trove classifiers
project_classifiers = set(config.get("classifiers", []))
errors, warnings = self.validate_classifiers(project_classifiers)
check_result["errors"].extend(errors)
check_result["warnings"].extend(warnings)

if not check_result["errors"] and not check_result["warnings"]:
self.info("All set!")
Expand Down

0 comments on commit 89eba1e

Please sign in to comment.