9. API Reference

See also

New and changed setup.py arguments in setuptools

The setuptools project adds new capabilities to the setup function and other APIs, makes the API consistent across different Python versions, and is hence recommended over using distutils directly.

Note

This document is being retained solely until the setuptools documentation at https://setuptools.readthedocs.io/en/latest/setuptools.html independently covers all of the relevant information currently included here.

9.1. distutils.core — Core Distutils functionality

The distutils.core module is the only module that needs to be installed to use the Distutils. It provides the setup() (which is called from the setup script). Indirectly provides the distutils.dist.Distribution and distutils.cmd.Command class.

distutils.core.setup(arguments)

The basic do-everything function that does most everything you could ever ask for from a Distutils method.

The setup function takes a large number of arguments. These are laid out in the following table.

argument name

value

type

name

The name of the package

a string

version

The version number of the package; see distutils.version

a string

description

A single line describing the package

a string

long_description

Longer description of the package

a string

author

The name of the package author

a string

author_email

The email address of the package author

a string

maintainer

The name of the current maintainer, if different from the author. Note that if the maintainer is provided, distutils will use it as the author in PKG-INFO

a string

maintainer_email

The email address of the current maintainer, if different from the author

a string

url

A URL for the package (homepage)

a string

download_url

A URL to download the package

a string

packages

A list of Python packages that distutils will manipulate

a list of strings

py_modules

A list of Python modules that distutils will manipulate

a list of strings

scripts

A list of standalone script files to be built and installed

a list of strings

ext_modules

A list of Python extensions to be built

a list of instances of distutils.core.Extension

classifiers

A list of categories for the package

a list of strings; valid classifiers are listed on PyPI.

distclass

the Distribution class to use

a subclass of distutils.core.Distribution

script_name

The name of the setup.py script - defaults to sys.argv[0]

a string

script_args

Arguments to supply to the setup script

a list of strings

options

default options for the setup script

a dictionary

license

The license for the package

a string

keywords

Descriptive meta-data, see PEP 314

a list of strings or a comma-separated string

platforms

a list of strings or a comma-separated string

cmdclass

A mapping of command names to Command subclasses

a dictionary

data_files

A list of data files to install

a list

package_dir

A mapping of package to directory names

a dictionary

distutils.core.run_setup(script_name[, script_args=None, stop_after='run'])

Run a setup script in a somewhat controlled environment, and return the distutils.dist.Distribution instance that drives things. This is useful if you need to find out the distribution meta-data (passed as keyword args from script to setup()), or the contents of the config files or command-line.

script_name is a file that will be read and run with exec(). sys.argv[0] will be replaced with script for the duration of the call. script_args is a list of strings; if supplied, sys.argv[1:] will be replaced by script_args for the duration of the call.

stop_after tells setup() when to stop processing; possible values:

value

description

init

Stop after the Distribution instance has been created and populated with the keyword arguments to setup()

config

Stop after config files have been parsed (and their data stored in the Distribution instance)

commandline

Stop after the command-line (sys.argv[1:] or script_args) have been parsed (and the data stored in the Distribution instance.)

run

Stop after all commands have been run (the same as if setup() had been called in the usual way). This is the default value.

In addition, the distutils.core module exposed a number of classes that live elsewhere.

  • Extension from