Packaging and distributing Python modules is a bad joke (and a stale one). Documentation even more so. Here are some undocumented quirks I've learned while trying to make a package out of a console script and upload it to PyPI.
If your license is a non-standard one (like Hippocratic License in my case), don't write
license = { file = "LICENSE" }
in your pyproject.toml
- PyPI will display your whole LICENSE
file contents in the side pane! Use
license = { text = "Your License Name" }
instead.
To make an entry point for a flat-layout project, with the startup script (the one with main()
) resting in project_root/myproject/myproject.py
, put this in pyproject.toml
:
[project.scripts]
myproject = "myproject.myproject:main"
To include all *.txt
files in your project recursively:
[tool.setuptools.package-data]
myproject.data" = ["**/*.txt"]
(Here we use a "data as subpackage" approach)
If you use setuptools-scm
to get version numbers from git, then, depending on the git state of your project, it may generate long complicated version names like 0.1.dev116+gec79494.d20220806
, which are incompatible with PyPI. You may either clean your repo up, or set config keys for setuptools-scm
, or try setuptools-git-versioning
instead (it has saner naming defaults).
Some tools still require a setup.py
file, even if the configuration is supplied through pyproject.toml
. A minimal setup.py
is sufficient:
#!/usr/bin/env python3
from setuptools import setup
setup()
More is likely to come...