Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

UI Expand
expandedtrue
titlesetup.cfg - options description
  • name is the distribution name of project package. This can be any name as long as it only contains letters, numbers, _ , and -.

  • 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. In this case, the long description is loaded from README.md (which is a common pattern) using the file: directive.

  • long_description_content_type tells what type of markup is used for the long description. In this case, it’s Markdown.

  • url is the URL for the repository homepage of the project.

  • project_urls lets list any number of extra links related to project. Generally this could be to documentation, issue trackers, etc.

  • classifiers gives the PIP some additional metadata about package. In this case, the package is only compatible with Python 3, is licensed under the MIT license, and is OS-independent.

In the options category, there are controls for setuptools itself:

  • package_dir is a mapping of package names and directories. An empty package name represents the “root package” — the directory in the project that contains all Python source files for the package — so in this case the project_name directory is designated the root package.

  • packages is a list of all Python import packages that should be included in the distribution package. Instead of listing each package manually, the find: directive can be used to automatically discover all packages and subpackages and options.packages.find to specify the package_dir to use. In the present example, the package list will be empty because there are no subpackages in the package.

  • python_requires gives the versions of Python supported by project. Installers like pip will look back through older versions of packages until it finds one that has a matching Python version.


Markdown
##### setup.py file - dynamic metadata
```console
├── setup.py
```
- setup.py is a build script for setuptools and setup.cfg. However, it works dynamically to provide setuptools with information about your package (such as name and version) as well as code files that need to be included.
- Minimal content:
```python
import setuptools

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

setuptools.setup(
    name="project_name",
    version="0.0.1",
    author="Example Author",
    author_email="author@example.com",
    description="Sample short description of the package",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/author/project_name",
    project_urls={
        "Bug Tracker": "https://github.com/author/project_name/issues",
    },
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    package_dir={"": "project_name"},
    packages=setuptools.find_packages(where="project_name"),
    python_requires=">=3.6",
)
```


UI Expand
expandedtrue
titlesetup.py - options description

setup() takes several arguments. This example package uses a relatively minimal set:

  • name is the distribution name of project package. This can be any name as long as it only contains letters, numbers, _ , and -.

  • 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. In this case, the long description is loaded from README.md, which is a common pattern.

  • long_description_content_type tells what type of markup is used for the long description. In this case, it’s Markdown.

  • url is the URL for the repository homepage of the project.

  • project_urls lets list any number of extra links related to project. Generally this could be to documentation, issue trackers, etc.

  • classifiers gives the PIP some additional metadata about package. In this case, the package is only compatible with Python 3, is licensed under the MIT license, and is OS-independent.
  • package_dir is a dictionary with package names for keys and directories for values. An empty package name represents the “root package” — the directory in the project that contains all Python source files for the package — so in this case the project_name directory is designated the root package.

  • packages is a list of all Python import packages that should be included in the distribution package. Instead of listing each package manually, a find_packages() can be used to automatically discover all packages and subpackages under package_dir. In this case, the list of packages will be empty as there's no subpackages present in the package directory.

  • python_requires gives the versions of Python supported by project. Installers like pip will look back though older versions of packages until it finds one that has a matching Python version.