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

Add a lint check to ensure classifiers (and other metadata values) are valid #9499

Open
pfmoore opened this issue Jan 23, 2021 · 6 comments
Open
Labels
S: needs triage Issues/PRs that need to be triaged

Comments

@pfmoore
Copy link
Member

pfmoore commented Jan 23, 2021

Pip 21.0 has now been released.

One issue, around the classifiers (a previous commit had left them incorrect). We should probably have a lint check that the classifiers are valid, to avoid this sort of issue in the future.

Originally posted by @pfmoore in #9282 (comment)

@uranusjr
Copy link
Member

Is there a tool for this?

@pradyunsg
Copy link
Member

Hmm... Maybe @di would know.

@hugovk
Copy link
Contributor

hugovk commented Jan 29, 2021

I don't know if there's a tool, but it's planned for twine check: see pypa/twine#430 and
pypa/packaging#147


In the meantime, Trove classifiers can be checked using https://pypi.org/project/trove-classifiers/

Something along the lines of:

from trove_classifiers import classifiers  # pip install trove-classifiers

BAD_CLASSIFIERS = {
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "License :: OSI Approved :: MIT License",
    "Topic :: Software Development :: Build Tools",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only"  # missing comma!
    "Programming Language :: Python :: 3.6",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: Implementation :: CPython",
    "Programming Language :: Python :: Implementation :: PyPy",
}

GOOD_CLASSIFIERS = {
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "License :: OSI Approved :: MIT License",
    "Topic :: Software Development :: Build Tools",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only",  # fixed comma
    "Programming Language :: Python :: 3.6",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: Implementation :: CPython",
    "Programming Language :: Python :: Implementation :: PyPy",
}


print(BAD_CLASSIFIERS <= classifiers)  # False

print(GOOD_CLASSIFIERS <= classifiers)  # True

Alternatively, python -m trove_classifiers lists the valid ones, and python setup.py --classifiers lists ours.

For example, using some Unix subset piping:

$ python -m trove_classifiers > all.txt
$ python setup.py --classifiers > ours.txt
$ comm -23 <(sort -n ours.txt|uniq) <(sort -n all.txt|uniq) | head -1
Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.6
$ # Now fix setup.py
$ edit setup.py
$ python setup.py --classifiers > ours.txt
$ comm -23 <(sort -n ours.txt|uniq) <(sort -n all.txt|uniq) | head -1
$

And put a test to ensure the subset output is empty.

(Could probably ditch the sort and uniq too.)

@uranusjr
Copy link
Member

uranusjr commented Jan 29, 2021

It should not be too difficult to write a pre-commit hook wrapping trove-classifiers. I wonder if someone has done it already.

@di
Copy link
Member

di commented Jan 29, 2021

Yes, eventually twine --check should do what you want here. Probably worth including that in your CI anyways (right now it just verifies that a long_description will render.

@pradyunsg
Copy link
Member

We do run twine check in our artifact build pipeline, and that is run in the CI as well.

pip/noxfile.py

Line 312 in e17ddea

session.run("twine", "check", *produced_dists, silent=True)

- bash: nox -s build-release -- 99.9

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants