Skip to content

Commit 715412f

Browse files
committed
feat: tabbed setup
1 parent e48584f commit 715412f

4 files changed

Lines changed: 189 additions & 101 deletions

File tree

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
sphinx==3.2.0
22
sphinx-autobuild==0.7.1
3+
sphinx-tabs==2.0.0
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
6+

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_tabs.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: 176 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -95,97 +95,182 @@ would be completely different than the setuptools configuration described
9595
below. See :pep:`517` and :pep:`518` for background and details.
9696

9797

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

190275
Creating README.md
191276
------------------

0 commit comments

Comments
 (0)