Skip to content

Instantly share code, notes, and snippets.

@roadkell
Last active October 8, 2022 14:49
Show Gist options
  • Save roadkell/235255ed43adb782a76e345da2451dc9 to your computer and use it in GitHub Desktop.
Save roadkell/235255ed43adb782a76e345da2451dc9 to your computer and use it in GitHub Desktop.
Python Packaging Quirks (as of 08.2022)

Python Packaging Quirks (as of 08.2022)

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment