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

Validate Trove classifiers in twine check #1166

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

browniebroke
Copy link

@browniebroke browniebroke commented Oct 12, 2024

I've been bitten by #976 today while trying to use Framework :: Django :: 5 as classifier. It used to work with earlier versions of Django (e.g. Framework :: Django :: 4) and the package in question was using these, so it wasn't clear that just 5 wouldn't work.

Reading the conversation in the issue, it sems like folks are happy to add this feature to Twine so I went ahead a tried to do it.

  • Add new tests to cover pass/fail behaviour
  • Implement new check in command
  • Update documentation

Fix #976

@browniebroke browniebroke force-pushed the twine-check-classifiers branch 3 times, most recently from 6530e6d to 933a503 Compare October 12, 2024 18:15
@browniebroke browniebroke force-pushed the twine-check-classifiers branch from 933a503 to 1beae6c Compare October 12, 2024 18:19
@browniebroke browniebroke marked this pull request as ready for review October 12, 2024 18:27
twine/commands/check.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@@ -76,14 +77,15 @@ def _parse_content_type(value: str) -> Tuple[str, Dict[str, str]]:

def _check_file(
filename: str, render_warning_stream: _WarningStream
) -> Tuple[List[str], bool]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That we're changing this signature is a sign that we need to do more here.

Check file previously just cared about the readme and to a lesser extent the metadata version.

I'd argue we should instead have check readme and check classifiers functions. I'd also argue for a structured data object for representing a finding, the severity and confidence instead of returning lists of strings.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, _check_file takes the whole distribution file name as argument (e.g. dist/test-package-0.0.1.tar.gz), extracts the metadata from it, and run some check on these. AFAIU, it does not seem to read the readme file, the description comes from the metadata as RestructuredText/Markdown, and it tries to render it as HTML.

Wouldn't a function called _check_readme be misleading? Can the description be inlined? I need to read more about the spec...

A structured data object representing the result makes sense to me, I'm not a big fan of returning tuples, even less tuples of list/dict. Sounds like a good candidate would be a dataclass or typing.NamedTuple, I think either can be used here as Twine currently supports Python 3.8+. Any preference?

@sigmavirus24
Copy link
Member

I don't believe this is the reusable library referenced in the original issue. Maybe I'm wrong though

@browniebroke
Copy link
Author

browniebroke commented Oct 13, 2024

I don't believe this is the reusable library referenced in the original issue

I took it from this comment, which links to https://github.com/pypa/trove-classifiers, which is under the @pypa org - let me know if I'm missing anything?

@browniebroke
Copy link
Author

I don't believe this is the reusable library referenced in the original issue

I took it from this comment, which links to pypa/trove-classifiers, which is under the @pypa org - let me know if I'm missing anything?

Oh, did you mean that last comment:

The current plan is to externalize them into a reusable library, it just hasn't happened yet: pypa/packaging#147

@browniebroke
Copy link
Author

Ok, I didn't pay enough attention to the time line of all the events across issue comments and PRs merge.

It seems like the packaging library is now ready and is effectively a higher level package that has all the checks built-in, meaning that we could simplify a lot twine check command by calling the relevant logic.

@browniebroke
Copy link
Author

Tried to use packaging to run validations #1167

I don't think it validates classifiers (yet?), and the description rendering problem aren't caught, so it looks like we won't be able to strip out so much from twine after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Twine check fails to warn on invalid classifier
2 participants