Build System Support¶
What is it?¶
Python packaging has come a long way.
setuptools way of packaging Python modules
setup() function within the
setup.py script. Commands such as
python setup.py bdist or
python setup.py bdist_wheel generate a
distribution bundle and
python setup.py install installs the distribution.
This interface makes it difficult to choose other packaging tools without an
setup.py scripts allowed for arbitrary execution, it
proved difficult to provide a reliable user experience across environments
PEP 517 therefore came to rescue and specified a new standard to package and distribute Python modules. Under PEP 517:
pyproject.tomlfile is used to specify what program to use for generating distribution.
Then, two functions provided by the program,
build_sdist(directory: str)create the distribution bundle at the specified
directory. The program is free to use its own configuration script or extend the
pip install *.whlor
pip install *.tar.gzdoes the actual installation. If
pipwill go ahead and copy the files into
site-packagesdirectory. If not,
pipwill look at
pyproject.tomland decide what program to use to ‘build from source’ (the default is
With this standard, switching between packaging tools becomes a lot easier.
setuptools’ build system support.
How to use it?¶
Starting with a package that you want to distribute. You will need your source
pyproject.toml file and a
~/meowpkg/ pyproject.toml setup.cfg meowpkg/__init__.py
The pyproject.toml file is required to specify the build system (i.e. what is being used to package your scripts and install from source). To use it with setuptools, the content would be:
[build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta"
setuptools package implements the
command and the
wheel package implements the
command; both are required to be compliant with PEP 517.
setuptools’ declarative config to
specify the package information:
[metadata] name = meowpkg version = 0.0.1 description = a package that meows [options] packages = find:
Now generate the distribution. To build the package, use PyPA build:
$ pip install -q build $ python -m build
And now it’s done! The
.whl file and
.tar.gz can then be distributed
dist/ meowpkg-0.0.1.whl meowpkg-0.0.1.tar.gz $ pip install dist/meowpkg-0.0.1.whl
$ pip install dist/meowpkg-0.0.1.tar.gz