Python uses a list of “Trove classifiers
” to add some structured meta data to projects.
It can be a bit tedius to add these manually.
Combining the ease of uvx
with a Python package, we can simplify this.
add
While I have brainstormed about a script to automate some of this, a post from adamghill informed me there is a trove-classifiers project that has all the classifiers already included. If I could combine this with something like peco for interactive filtering, this could work!
After a brief search, I found the pzp
project which was the missing part I need.
While recent Python versions have tomllib built in, I decided to go with tomlkit
so that I could write it back.
With these two pieces, uvx add-classifiers add
was created.
With this command, you can easily get a list of classifiers as an interactive filtered list that you can easily add to your pyproject.toml
suggest
From the same thread Ash_Crow made a futher great suggestion.
a useful one could be checking that the classifiers in [project] are consistent with the versions actually supported by what is declared in [dependencies] (for Django) or [requires-python] (for Python)
From this uvx add-classifiers suggest
was born.
From the packaging
library, we can use the Requirement
class and SpecifierSet
class to more easily and more reliabilly parse anything in project.python-requires
and project.dependencies
.
With these two classes, it was not much additional work to process a set of suggested_addition
and suggested_removal
that can automatally be applied to our pyproject.toml
summary
With these existing packages, the filter + add method ends up being fairly simple.
https://codeberg.org/kfdm/add-classifiers/src/tag/v0.2.0/src/add_classifiers/__init__.py#L48-L68
The suggest method has to do a bit more but it is also not significantly more complex.
https://codeberg.org/kfdm/add-classifiers/src/tag/v0.2.0/src/add_classifiers/__init__.py#L71-L126
I will probably continue to poke around and make some small improvements, but the intial version already seems like it will work well and works about as good as my initial brainstorm hoped.
https://codeberg.org/kfdm/add-classifiers/issues https://pypi.org/project/add-classifiers/