Building and Distributing Packages with Setuptools (original) (raw)

View this page

Edit this page

Toggle table of contents sidebar

Setuptools is a collection of enhancements to the Python distutilsthat allow developers to more easily build and distribute Python packages, especially ones that have dependencies on other packages.

Packages built and distributed using setuptools look to the user like ordinary Python packages based on the distutils.

Feature Highlights:

Developer’s Guide

The developer’s guide has been updated. See the most recent version.

TRANSITIONAL NOTE

Setuptools automatically calls declare_namespace() for you at runtime, but future versions may not. This is because the automatic declaration feature has some negative side effects, such as needing to import all namespace packages during the initialization of the pkg_resources runtime, and also the need for pkg_resources to be explicitly imported before any namespace packages work at all. In some future releases, you’ll be responsible for including your own declaration lines, and the automatic declaration feature will be dropped to get rid of the negative side effects.

During the remainder of the current development cycle, therefore, setuptools will warn you about missing declare_namespace() calls in your__init__.py files, and you should correct these as soon as possible before the compatibility support is removed. Namespace packages without declaration lines will not work correctly once a user has upgraded to a later version, so it’s important that you make this change now in order to avoid having your code break in the field. Our apologies for the inconvenience, and thank you for your patience.

setup.cfg-only projects

Added in version 40.9.0.

If setup.py is missing from the project directory when a PEP 517build is invoked, setuptools emulates a dummy setup.py file containing only a setuptools.setup() call.

Note

PEP 517 doesn’t support editable installs so this is currently incompatible with pip install -e ..

This means that you can have a Python project with all build configuration specified in setup.cfg, without a setup.py file, if you can rely on your project always being built by a PEP 517/PEP 518 compatible frontend.

To use this feature:

Configuration API

Some automation tools may wish to access data from a configuration file.

Setuptools exposes a read_configuration() function for parsing metadata and options sections into a dictionary.

from setuptools.config import read_configuration

conf_dict = read_configuration("/home/user/dev/package/setup.cfg")

By default, read_configuration() will read only the file provided in the first argument. To include values from other configuration files which could be in various places, set the find_others keyword argument to True.

If you have only a configuration file but not the whole package, you can still try to get data out of it with the help of the ignore_option_errors keyword argument. When it is set to True, all options with errors possibly produced by directives, such as attr: and others, will be silently ignored. As a consequence, the resulting dictionary will include no such options.

Forum and Bug Tracker

Please use GitHub Discussions for questions and discussion about setuptools, and the setuptools bug tracker ONLY for issues you have confirmed via the forum are actual bugs, and which you have reduced to a minimal set of steps to reproduce.