Skip to content

Commit 9dfbeb0

Browse files
authored
Merge pull request #818 from henryiii/chore/cfg
chore: use setup.cfg as main config file
2 parents 212f0c1 + 01c433b commit 9dfbeb0

4 files changed

Lines changed: 192 additions & 85 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sphinx==3.2.0
22
sphinx-autobuild==0.7.1
3+
sphinx-inline-tabs==2020.10.19b4
34
git+https://github.com/python/python-docs-theme.git#egg=python-docs-theme
45
git+https://github.com/pypa/pypa-docs-theme.git#egg=pypa-docs-theme

source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'sphinx.ext.extlinks',
3535
'sphinx.ext.intersphinx',
3636
'sphinx.ext.todo',
37+
'sphinx_inline_tabs',
3738
]
3839

3940
# Add any paths that contain templates here, relative to this directory.

source/index.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Get started
3838
Essential tools and concepts for working within the Python
3939
development ecosystem are covered in our :doc:`tutorials/index` section:
4040

41-
* to learn how to install packages, see the
41+
* To learn how to install packages, see the
4242
:doc:`tutorial on installing packages <tutorials/installing-packages>`.
43-
* to learn how to manage dependencies in a version controlled project, see the
43+
* To learn how to manage dependencies in a version controlled project, see the
4444
:doc:`tutorial on managing application dependencies <tutorials/managing-dependencies>`.
45-
* to learn how to package and distribute your projects, see the
46-
:doc:`tutorial on packaging and distributing <tutorials/packaging-projects>`
47-
* to get an overview of packaging options for Python libraries and
45+
* To learn how to package and distribute your projects, see the
46+
:doc:`tutorial on packaging and distributing <tutorials/packaging-projects>`.
47+
* To get an overview of packaging options for Python libraries and
4848
applications, see the :doc:`Overview of Python Packaging <overview>`.
4949

5050

@@ -53,11 +53,11 @@ Learn more
5353

5454
Beyond our :doc:`tutorials/index`, this guide has several other resources:
5555

56-
* the :doc:`guides/index` section for walk throughs, such as
57-
:doc:`guides/installing-using-linux-tools` or :doc:`guides/packaging-binary-extensions`
58-
* the :doc:`discussions/index` section for in-depth references on topics such as
59-
:doc:`discussions/deploying-python-applications` or :doc:`discussions/pip-vs-easy-install`
60-
* the :doc:`specifications/index` section for packaging interoperability specifications
56+
* The :doc:`guides/index` section for walk throughs, such as
57+
:doc:`guides/installing-using-linux-tools` or :doc:`guides/packaging-binary-extensions`.
58+
* The :doc:`discussions/index` section for in-depth references on topics such as
59+
:doc:`discussions/deploying-python-applications` or :doc:`discussions/pip-vs-easy-install`.
60+
* The :doc:`specifications/index` section for packaging interoperability specifications.
6161

6262
Additionally, there is a list of :doc:`other projects <key_projects>` maintained
6363
by members of the Python Packaging Authority.

source/tutorials/packaging-projects.rst

Lines changed: 180 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -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,82 +94,186 @@ always include it. If you were to use a different build system, such as
9394
would be completely different than the setuptools configuration described
9495
below. See :pep:`517` and :pep:`518` for background and details.
9596

96-
Creating setup.py
97-
-----------------
98-
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.
102-
103-
Open :file:`setup.py` and enter the following content. Update the package name
104-
to include your username (for example, ``example-pkg-theacodes``), this ensures
105-
that you have a unique package name and that your package doesn't conflict with
106-
packages uploaded by other people following this tutorial.
107-
108-
.. code-block:: python
109-
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:
136-
137-
- ``name`` is the *distribution name* of your package. This can be any name as
138-
long as only contains letters, numbers, ``_`` , and ``-``. It also must not
139-
already be taken on pypi.org. **Be sure to update this with your username,**
140-
as this ensures you won't try to upload a package with the same name as one
141-
which already exists when you upload the package.
142-
- ``version`` is the package version see :pep:`440` for more details on
143-
versions.
144-
- ``author`` and ``author_email`` are used to identify the author of the
145-
package.
146-
- ``description`` is a short, one-sentence summary of the package.
147-
- ``long_description`` is a detailed description of the package. This is
148-
shown on the package detail page on the Python Package Index. In
149-
this case, the long description is loaded from :file:`README.md` which is
150-
a common pattern.
151-
- ``long_description_content_type`` tells the index what type of markup is
152-
used for the long description. In this case, it's Markdown.
153-
- ``url`` is the URL for the homepage of the project. For many projects, this
154-
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
155-
service.
156-
- ``packages`` is a list of all Python :term:`import packages <Import
157-
Package>` that should be included in the :term:`Distribution Package`.
158-
Instead of listing each package manually, we can use :func:`find_packages`
159-
to automatically discover all packages and subpackages. In this case, the
160-
list of packages will be ``example_pkg`` as that's the only package present.
161-
- ``classifiers`` gives the index and :ref:`pip` some additional metadata
162-
about your package. In this case, the package is only compatible with Python
163-
3, is licensed under the MIT license, and is OS-independent. You should
164-
always include at least which version(s) of Python your package works on,
165-
which license your package is available under, and which operating systems
166-
your package will work on. For a complete list of classifiers, see
167-
https://pypi.org/classifiers/.
168-
169-
There are many more than the ones mentioned here. See
170-
:doc:`/guides/distributing-packages-using-setuptools` for more details.
17197

98+
Configuring metadata
99+
--------------------
100+
101+
There are two types of metadata: static and dynamic.
102+
103+
* Static metadata (:file:`setup.cfg`): guaranteed to be the same every time. This is
104+
simpler, easier to read, and avoids many common errors, like encoding errors.
105+
* Dynamic metadata (:file:`setup.py`): possibly non-deterministic. Any items that are
106+
dynamic or determined at install-time, as well as extension modules or
107+
extensions to setuptools, need to go into :file:`setup.py`.
108+
109+
Static metadata should be preferred and dynamic metadata should be used only as
110+
an escape hatch when absolutely necessary.
111+
112+
113+
.. tab:: setup.cfg (static)
114+
115+
:file:`setup.cfg` is the configuration file for :ref:`setuptools`. It tells
116+
setuptools about your package (such as the name and version) as well as which
117+
code files to include. Eventually much of this configuration may be able to move
118+
to :file:`pyproject.toml`.
119+
120+
Open :file:`setup.py` and enter the following content. Update the package name
121+
to include your username (for example, ``example-pkg-theacodes``), this ensures
122+
that you have a unique package name and that your package doesn't conflict with
123+
packages uploaded by other people following this tutorial.
124+
125+
.. code-block:: python
126+
127+
[metadata]
128+
# replace with your username:
129+
name = example-pkg-YOUR-USERNAME-HERE
130+
version = 0.0.1
131+
url = https://github.com/pypa/sampleproject
132+
author = Example Author
133+
author_email = author@example.com
134+
classifiers =
135+
Programming Language :: Python :: 3
136+
License :: OSI Approved :: MIT License
137+
Operating System :: OS Independent
138+
description = A small example package
139+
long_description = file: README.md
140+
long_description_content_type = text/markdown
141+
142+
[options]
143+
python_requires = >=3.6
144+
145+
146+
There are a `variety of metadata and options
147+
<https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html>`_
148+
supported here. This is in configparser format; do not place quotes around values.
149+
This example package uses a relatively minimal set of options:
150+
151+
- ``name`` is the *distribution name* of your package. This can be any name as
152+
long as only contains letters, numbers, ``_`` , and ``-``. It also must not
153+
already be taken on pypi.org. **Be sure to update this with your username,**
154+
as this ensures you won't try to upload a package with the same name as one
155+
which already exists when you upload the package.
156+
- ``version`` is the package version see :pep:`440` for more details on
157+
versions. You can use ``file:`` or ``attr:`` directives to read from a file or
158+
package attribute (simple attributes do not require import).
159+
- ``author`` and ``author_email`` are used to identify the author of the
160+
package.
161+
- ``description`` is a short, one-sentence summary of the package.
162+
- ``long_description`` is a detailed description of the package. This is
163+
shown on the package detail page on the Python Package Index. In
164+
this case, the long description is loaded from :file:`README.md` which is
165+
a common pattern, using the ``file:`` directive.
166+
- ``long_description_content_type`` tells the index what type of markup is
167+
used for the long description. In this case, it's Markdown.
168+
- ``url`` is the URL for the homepage of the project. For many projects, this
169+
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
170+
service.
171+
- ``packages`` is a list of all Python :term:`import packages <Import
172+
Package>` that should be included in the :term:`Distribution Package`.
173+
Instead of listing each package manually, we can use the ``find:`` directive
174+
to automatically discover all packages and subpackages. In this case, the
175+
list of packages will be ``example_pkg`` as that's the only package present.
176+
- ``classifiers`` gives the index and :ref:`pip` some additional metadata
177+
about your package. In this case, the package is only compatible with Python
178+
3, is licensed under the MIT license, and is OS-independent. You should
179+
always include at least which version(s) of Python your package works on,
180+
which license your package is available under, and which operating systems
181+
your package will work on. For a complete list of classifiers, see
182+
https://pypi.org/classifiers/.
183+
184+
There are many more than the ones mentioned here. See
185+
:doc:`/guides/distributing-packages-using-setuptools` for more details.
186+
187+
188+
If you create a :file:`setup.py` file, this will enable direct interaction
189+
with :file:`setup.py` (which generally should be avoided), and editable
190+
installs. This file used to be required, but can be omitted in modern
191+
setuptools.
192+
193+
Anything you set in :file:`setup.cfg` can instead be set via keyword argument to
194+
:func:`setup()`; this enables computed values to be used. You will also need
195+
:func:`setup()` for setting up extension modules for compilation.
196+
197+
.. code-block:: python
198+
199+
import setuptools
200+
201+
setuptools.setup()
202+
203+
.. tab:: setup.py (dynamic)
204+
205+
:file:`setup.py` is the build script for :ref:`setuptools`. It tells setuptools
206+
about your package (such as the name and version) as well as which code files
207+
to include.
208+
209+
Open :file:`setup.py` and enter the following content. Update the package name
210+
to include your username (for example, ``example-pkg-theacodes``), this ensures
211+
that you have a unique package name and that your package doesn't conflict with
212+
packages uploaded by other people following this tutorial.
213+
214+
.. code-block:: python
215+
216+
import setuptools
217+
218+
with open("README.md", "r", encoding="utf-8") as fh:
219+
long_description = fh.read()
220+
221+
setuptools.setup(
222+
name="example-pkg-YOUR-USERNAME-HERE", # Replace with your own username
223+
version="0.0.1",
224+
author="Example Author",
225+
author_email="author@example.com",
226+
description="A small example package",
227+
long_description=long_description,
228+
long_description_content_type="text/markdown",
229+
url="https://github.com/pypa/sampleproject",
230+
packages=setuptools.find_packages(),
231+
classifiers=[
232+
"Programming Language :: Python :: 3",
233+
"License :: OSI Approved :: MIT License",
234+
"Operating System :: OS Independent",
235+
],
236+
python_requires='>=3.6',
237+
)
238+
239+
240+
:func:`setup` takes several arguments. This example package uses a relatively
241+
minimal set:
242+
243+
- ``name`` is the *distribution name* of your package. This can be any name as
244+
long as only contains letters, numbers, ``_`` , and ``-``. It also must not
245+
already be taken on pypi.org. **Be sure to update this with your username,**
246+
as this ensures you won't try to upload a package with the same name as one
247+
which already exists when you upload the package.
248+
- ``version`` is the package version see :pep:`440` for more details on
249+
versions.
250+
- ``author`` and ``author_email`` are used to identify the author of the
251+
package.
252+
- ``description`` is a short, one-sentence summary of the package.
253+
- ``long_description`` is a detailed description of the package. This is
254+
shown on the package detail page on the Python Package Index. In
255+
this case, the long description is loaded from :file:`README.md` which is
256+
a common pattern.
257+
- ``long_description_content_type`` tells the index what type of markup is
258+
used for the long description. In this case, it's Markdown.
259+
- ``url`` is the URL for the homepage of the project. For many projects, this
260+
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
261+
service.
262+
- ``packages`` is a list of all Python :term:`import packages <Import
263+
Package>` that should be included in the :term:`Distribution Package`.
264+
Instead of listing each package manually, we can use :func:`find_packages`
265+
to automatically discover all packages and subpackages. In this case, the
266+
list of packages will be ``example_pkg`` as that's the only package present.
267+
- ``classifiers`` gives the index and :ref:`pip` some additional metadata
268+
about your package. In this case, the package is only compatible with Python
269+
3, is licensed under the MIT license, and is OS-independent. You should
270+
always include at least which version(s) of Python your package works on,
271+
which license your package is available under, and which operating systems
272+
your package will work on. For a complete list of classifiers, see
273+
https://pypi.org/classifiers/.
274+
275+
There are many more than the ones mentioned here. See
276+
:doc:`/guides/distributing-packages-using-setuptools` for more details.
172277

173278
Creating README.md
174279
------------------

0 commit comments

Comments
 (0)