@@ -50,6 +50,7 @@ project's root directory - you will add content to them in the following steps.
5050 ├── example_pkg
5151 │ └── __init__.py
5252 ├── pyproject.toml
53+ ├── setup.cfg
5354 ├── setup.py
5455 └── tests
5556
@@ -93,12 +94,14 @@ always include it. If you were to use a different build system, such as
9394would be completely different than the setuptools configuration described
9495below. See :pep: `517 ` and :pep: `518 ` for background and details.
9596
96- Creating setup.py
97- -----------------
9897
99- :file: `setup.py ` is the build script for :ref: `setuptools `. It tells setuptools
100- about your package (such as the name and version) as well as which code files
101- to include.
98+ Creating setup.cfg
99+ ------------------
100+
101+ :file: `setup.cfg ` is the configuration file for :ref: `setuptools `. It tells
102+ setuptools about your package (such as the name and version) as well as which
103+ code files to include. Eventually much of this configuration may be able to move
104+ to :file: `pyproject.toml `.
102105
103106Open :file: `setup.py ` and enter the following content. Update the package name
104107to include your username (for example, ``example-pkg-theacodes ``), this ensures
@@ -107,55 +110,53 @@ packages uploaded by other people following this tutorial.
107110
108111.. code-block :: python
109112
110- import setuptools
111-
112- with open (" README.md" , " r" , encoding = " utf-8" ) as fh:
113- long_description = fh.read()
114-
115- setuptools.setup(
116- name = " example-pkg-YOUR-USERNAME-HERE" , # Replace with your own username
117- version = " 0.0.1" ,
118- author = " Example Author" ,
119- author_email = " author@example.com" ,
120- description = " A small example package" ,
121- long_description = long_description,
122- long_description_content_type = " text/markdown" ,
123- url = " https://github.com/pypa/sampleproject" ,
124- packages = setuptools.find_packages(),
125- classifiers = [
126- " Programming Language :: Python :: 3" ,
127- " License :: OSI Approved :: MIT License" ,
128- " Operating System :: OS Independent" ,
129- ],
130- python_requires = ' >=3.6' ,
131- )
132-
133-
134- :func: `setup ` takes several arguments. This example package uses a relatively
135- minimal set:
113+ [metadata]
114+ # replace with your username:
115+ name = example- pkg- YOUR - USERNAME - HERE
116+ version = 0.0 .1
117+ url = https:// github.com/ pypa/ sampleproject
118+ author = Example Author
119+ author_email = author@ example.com
120+ classifiers =
121+ Programming Language :: Python :: 3
122+ License :: OSI Approved :: MIT License
123+ Operating System :: OS Independent
124+ description = A small example package
125+ long_description = file : README .md
126+ long_description_content_type = text/ markdown
127+
128+ [options]
129+ python_requires = >= 3.6
130+
131+
132+ There are a `variety of metadata and options
133+ <https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html> `_
134+ supported here. This is in configparser format; do not place quotes around values.
135+ This example package uses a relatively minimal set of options:
136136
137137- ``name `` is the *distribution name * of your package. This can be any name as
138138 long as only contains letters, numbers, ``_ `` , and ``- ``. It also must not
139139 already be taken on pypi.org. **Be sure to update this with your username, **
140140 as this ensures you won't try to upload a package with the same name as one
141141 which already exists when you upload the package.
142142- ``version `` is the package version see :pep: `440 ` for more details on
143- versions.
143+ versions. You can use ``file: `` or ``attr: `` directives to read from a file or
144+ package attribute (simple attributes do not require import).
144145- ``author `` and ``author_email `` are used to identify the author of the
145146 package.
146147- ``description `` is a short, one-sentence summary of the package.
147148- ``long_description `` is a detailed description of the package. This is
148149 shown on the package detail page on the Python Package Index. In
149150 this case, the long description is loaded from :file: `README.md ` which is
150- a common pattern.
151+ a common pattern, using the `` file: `` directive .
151152- ``long_description_content_type `` tells the index what type of markup is
152153 used for the long description. In this case, it's Markdown.
153154- ``url `` is the URL for the homepage of the project. For many projects, this
154155 will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
155156 service.
156157- ``packages `` is a list of all Python :term: `import packages <Import
157158 Package> ` that should be included in the :term: `Distribution Package `.
158- Instead of listing each package manually, we can use :func: ` find_packages `
159+ Instead of listing each package manually, we can use the `` find: `` directive
159160 to automatically discover all packages and subpackages. In this case, the
160161 list of packages will be ``example_pkg `` as that's the only package present.
161162- ``classifiers `` gives the index and :ref: `pip ` some additional metadata
@@ -169,6 +170,22 @@ minimal set:
169170There are many more than the ones mentioned here. See
170171:doc: `/guides/distributing-packages-using-setuptools ` for more details.
171172
173+ Creating setup.py (optional)
174+ ----------------------------
175+
176+ If you create a setup.py file, this will enable direct interaction with
177+ :file: `setup.py ` (which generally should be avoided), and editable installs. This file
178+ used to be required, but can be omitted in modern setuptools.
179+
180+ Anything you set in setup.cfg can instead be set via keyword argument to
181+ :func: `setup() `; this enables computed values to be used. You will also need
182+ :func: `setup() ` for setting up extension modules for compilation.
183+
184+ .. code-block :: python
185+
186+ import setuptools
187+
188+ setuptools.setup()
172189
173190 Creating README.md
174191------------------
0 commit comments