Python - setup.py

Card Puncher Data Processing

About

setup.py is a file found at the root directory of your project and serves two primary functions:

Format

Setup

The primary feature of setup.py is that it contains a global setup() function

It contains a global setup() function and properties.

Properties

Default properties: setup.cfg

See example

See also: Configuring setup() using setup.cfg files

Basic

from setuptools import setup, find_packages
setup(
    name="HelloWorld",
    version="0.1",
    packages=find_packages(),
)

Management

Cli

setup.py is a cli. See https://setuptools.readthedocs.io/en/latest/setuptools.html#command-reference

cd your/project/path
python setup.py --help
Common commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package

Global options:
  --verbose (-v)      run verbosely (default)
  --quiet (-q)        run quietly (turns verbosity off)
  --dry-run (-n)      don't actually do anything
  --help (-h)         show detailed help message
  --no-user-cfg       ignore pydistutils.cfg in your home directory
  --command-packages  list of packages that provide distutils commands

Information display options (just display information, ignore any commands)
  --help-commands     list all available commands
  --name              print package name
  --version (-V)      print package version
  --fullname          print <package name>-<version>
  --author            print the author's name
  --author-email      print the author's email address
  --maintainer        print the maintainer's name
  --maintainer-email  print the maintainer's email address
  --contact           print the maintainer's name if known, else the author's
  --contact-email     print the maintainer's email address if known, else the
                      author's
  --url               print the URL for this package
  --license           print the license of the package
  --licence           alias for --license
  --description       print the package description
  --long-description  print the long package description
  --platforms         print the list of platforms
  --classifiers       print the list of classifiers
  --keywords          print the list of keywords
  --provides          print the list of packages/modules provided
  --requires          print the list of packages/modules required
  --obsoletes         print the list of packages/modules made obsolete

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

Example

"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
"""

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="example_pkg",
    version="0.0.1",
    author="Example Author",
    author_email="[email protected]",
    description="A small example package",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/pypa/sampleproject",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)

where:

  • name is the name of the package. This can be any name as long as only contains letters, numbers, _ , and -. It also must not already taken on pypi.org.
  • version is the package version
  • author and author_email are used to identify the author of the package.
  • description is a short, one-sentence summary of the package.
  • long_description is a detailed description of the package. This is shown on the package detail package on the Python Package Index. In this case, the long description is loaded from README.md which is a common pattern.
  • long_description_content_type tells the index what type of markup is used for the long description. In this case, it’s Markdown.
  • url is the URL for the homepage of the project.
  • packages is a list of all Python import packages that should be included in the distribution package. Instead of listing each package manually, we can use find_packages() to automatically discover all packages and subpackages.
  • classifiers tell the index and pip some additional metadata about your package. https://pypi.org/classifiers/.
  • namespace_packages see Python - Namespace Package

See specification at: https://packaging.python.org/specifications/#

Documentation / Reference





Discover More
Card Puncher Data Processing
Python - (Shipping|Packaging)

in Python Shipping in Python is defined in the setuptools framework, that uses pip and to distribute code in the wheel format See
Card Puncher Data Processing
Python - Dependency Management

See: syntax When you install a package, or declaring a dependency, you need to specify an package id that's known...
Card Puncher Data Processing
Python - Main (Entry Point)

In Python. In the . Example: To provide executable scripts,...
Card Puncher Data Processing
Python - Namespace Package

Namespace packages allow you to split the sub-packages and modules within a single package across multiple, separate distribution packages And you use this package in your code like so: Then you...
Card Puncher Data Processing
Python - Package

in Python Physically, package are the directories and modules are the files within this directories. Logically, a package is a module (parent module): which can contain: modules (submodules)...
Card Puncher Data Processing
Python - Packages (Archive, Distribution)

in Python Packages (or better Distribution package) are the result of the packaging of a project that may contains one or more (regular) package regular packageregular package A package is a compressed...
Card Puncher Data Processing
Python - Project

Project in Python as describe by The project name is specified in the name properties in the setup function of the setup.py file Project are a set of file to package a package.: one package...
Python Build Artifact Setup Py
Python - Regular Package (Shipping | Packaging)

and in Python How to release regular package adapted from (they are using the setuptools framework) With python 3. where: setup.py...
Card Puncher Data Processing
Python - Script

in Python are source file that can be run. On Linux, begin your scripts with your interpreter. See or You can find them by executing the whereis commando: sys.argv[0] is the script name...
Card Puncher Data Processing
Python - Source Distribution (sdists)

in Python. Source distributions are also known as sdists for short. With and its's script. Some projects use a src or lib subdirectory as the source root In , find-packages...



Share this page:
Follow us:
Task Runner