Skip to content

Commit 51ebaa6

Browse files
authored
Merge branch 'main' into section-on-file-paths
2 parents 17ec57f + 537d055 commit 51ebaa6

22 files changed

+347
-72
lines changed

noxfile.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66
import shutil
77
import nox
88

9-
@nox.session(py="3")
9+
10+
nox.options.sessions = []
11+
12+
13+
@nox.session()
1014
def translation(session):
15+
"""
16+
Build the gettext .pot files.
17+
"""
1118
session.install("-r", "requirements.txt")
1219
target_dir = "locales"
1320
session.run(
@@ -18,8 +25,11 @@ def translation(session):
1825
target_dir, # where to put the .pot file
1926
)
2027

21-
@nox.session(py="3")
28+
@nox.session()
2229
def build(session, autobuild=False):
30+
"""
31+
Make the website.
32+
"""
2333
session.install("-r", "requirements.txt")
2434

2535
target_build_dir = "build"
@@ -49,14 +59,20 @@ def build(session, autobuild=False):
4959
)
5060

5161

52-
@nox.session(py="3")
62+
@nox.session()
5363
def preview(session):
64+
"""
65+
Make and preview the website.
66+
"""
5467
session.install("sphinx-autobuild")
5568
build(session, autobuild=True)
5669

5770

58-
@nox.session(py="3")
71+
@nox.session()
5972
def linkcheck(session):
73+
"""
74+
Check for broken links.
75+
"""
6076
session.install("-r", "requirements.txt")
6177
session.run(
6278
"sphinx-build",

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
sphinx==4.3.1
1+
sphinx==4.5.0
22
sphinx-autobuild==0.7.1
33
sphinx-inline-tabs==2021.4.11b9
4-
python-docs-theme==2021.5
5-
sphinx-copybutton==0.4.0
4+
python-docs-theme==2022.1
5+
sphinx-copybutton==0.5.0
66
git+https://github.com/pypa/pypa-docs-theme.git#egg=pypa-docs-theme

source/_static/overrides.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

source/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@
187187
# Add any paths that contain custom static files (such as style sheets) here,
188188
# relative to this directory. They are copied after the builtin static files,
189189
# so a file named "default.css" will overwrite the builtin "default.css".
190-
html_static_path = ['_static']
191-
192-
html_css_files = ['overrides.css']
190+
# html_static_path = ['_static']
193191

194192
# Add any extra paths that contain custom files (such as robots.txt or
195193
# .htaccess) here, relative to this directory. These files are copied

source/discussions/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ specific topic. If you're just trying to get stuff done, see
1212
pip-vs-easy-install
1313
install-requires-vs-requirements
1414
wheel-vs-egg
15+
src-layout-vs-flat-layout
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
=========================
2+
src layout vs flat layout
3+
=========================
4+
5+
The "flat layout" refers to organising a project's files in a folder or
6+
repository, such that the various configuration files and
7+
:term:`import packages <Import Package>` are all in the top-level directory.
8+
9+
::
10+
11+
.
12+
├── README.md
13+
├── noxfile.py
14+
├── pyproject.toml
15+
├── setup.py
16+
├── awesome_package/
17+
│ ├── __init__.py
18+
│ └── module.py
19+
└── tools/
20+
├── generate_awesomeness.py
21+
└── decrease_world_suck.py
22+
23+
The "src layout" deviates from the flat layout by moving the code that is
24+
intended to be importable (i.e. ``import awesome_package``, also known as
25+
:term:`import packages <Import Package>`) into a subdirectory. This
26+
subdirectory is typically named ``src/``, hence "src layout".
27+
28+
::
29+
30+
.
31+
├── README.md
32+
├── noxfile.py
33+
├── pyproject.toml
34+
├── setup.py
35+
├── src/
36+
│ └── awesome_package/
37+
│ ├── __init__.py
38+
│ └── module.py
39+
└── tools/
40+
├── generate_awesomeness.py
41+
└── decrease_world_suck.py
42+
43+
Here's a breakdown of the important behaviour differences between the src
44+
layout and the flat layout:
45+
46+
* The src layout requires installation of the project to be able to run its
47+
code, and the flat layout does not.
48+
49+
This means that the src layout involves an additional step in the
50+
development workflow of a project (typically, an
51+
:doc:`editable installation <setuptools:userguide/development_mode>`
52+
is used for development and a regular installation is used for testing).
53+
54+
* The src layout helps prevent accidental usage of the in-development copy of
55+
the code.
56+
57+
This is relevant since the Python interpreter includes the current working
58+
directory as the first item on the import path. This means that if an import
59+
package exists in the current working directory with the same name as an
60+
installed import package, the variant from the current working directory will
61+
be used. This can lead to subtle misconfiguration of the project's packaging
62+
tooling, which could result in files not being included in a distribution.
63+
64+
The src layout helps avoid this by keeping import packages in a directory
65+
separate from the root directory of the project, ensuring that the installed
66+
copy is used.
67+
68+
* The src layout helps enforce that an
69+
:doc:`editable installation <setuptools:userguide/development_mode>` is only
70+
able to import files that were meant to be importable.
71+
72+
This is especially relevant when the editable installation is implemented
73+
using a `path configuration file <https://docs.python.org/3/library/site.html#index-2>`_
74+
that adds the directory to the import path.
75+
76+
The flat layout would add the other project files (eg: ``README.md``,
77+
``tox.ini``) and packaging/tooling configuration files (eg: ``setup.py``,
78+
``noxfile.py``) on the import path. This would make certain imports work
79+
in editable installations but not regular installations.

source/flow.rst

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
==================
2+
The Packaging Flow
3+
==================
4+
5+
The document aims to outline the flow involved in publishing/distributing a
6+
:term:`distribution package <Distribution Package>`, usually to the `Python
7+
Package Index (PyPI)`_. It is written for package publishers, who are assumed
8+
to be the package author.
9+
10+
.. _Python Package Index (PyPI): https://pypi.org/
11+
12+
While the :doc:`tutorial <tutorials/packaging-projects>` walks through the
13+
process of preparing a simple package for release, it does not fully enumerate
14+
what steps and files are required, and for what purpose.
15+
16+
Publishing a package requires a flow from the author's source code to an end
17+
user's Python environment. The steps to achieve this are:
18+
19+
- Have a source tree containing the package. This is typically a checkout from
20+
a version control system (VCS).
21+
22+
- Prepare a configuration file describing the package metadata (name, version
23+
and so forth) and how to create the build artifacts. For most packages, this
24+
will be a :file:`pyproject.toml` file, maintained manually in the source
25+
tree.
26+
27+
- Create build artifacts to be sent to the package distribution service
28+
(usually PyPI); these will normally be a
29+
:term:`source distribution ("sdist") <Source Distribution (or "sdist")>`
30+
and one or more :term:`built distributions ("wheels") <Built Distribution>`.
31+
These are made by a build tool using the configuration file from the
32+
previous step. Often there is just one generic wheel for a pure Python
33+
package.
34+
35+
- Upload the build artifacts to the package distribution service.
36+
37+
At that point, the package is present on the package distribution service.
38+
To use the package, end users must:
39+
40+
- Download one of the package's build artifacts from the package distribution
41+
service.
42+
43+
- Install it in their Python environment, usually in its ``site-packages``
44+
directory. This step may involve a build/compile step which, if needed, must
45+
be described by the package metadata.
46+
47+
These last 2 steps are typically performed by :ref:`pip` when an end user runs
48+
``pip install``.
49+
50+
The steps above are described in more detail below.
51+
52+
The source tree
53+
===============
54+
55+
The source tree contains the package source code, usually a checkout from a
56+
VCS. The particular version of the code used to create the build artifacts
57+
will typically be a checkout based on a tag associated with the version.
58+
59+
The configuration file
60+
======================
61+
62+
The configuration file depends on the tool used to create the build artifacts.
63+
The standard practice is to use a :file:`pyproject.toml` file in the `TOML
64+
format`_.
65+
66+
.. _TOML format: https://github.com/toml-lang/toml
67+
68+
At a minimum, the :file:`pyproject.toml` file needs a ``[build-system]`` table
69+
specifying your build tool. There are many build tools available, including
70+
but not limited to :ref:`flit`, :ref:`hatch`, :ref:`pdm`, :ref:`poetry`,
71+
:ref:`setuptools`, `trampolim`_, and `whey`_. Each tool's documentation will
72+
show what to put in the ``[build-system]`` table.
73+
74+
.. _trampolim: https://pypi.org/project/trampolim/
75+
.. _whey: https://pypi.org/project/whey/
76+
77+
For example, here is a table for using :ref:`hatch`:
78+
79+
.. code-block:: toml
80+
81+
[build-system]
82+
requires = ["hatchling"]
83+
build-backend = "hatchling.build"
84+
85+
With such a table in the :file:`pyproject.toml` file, a "frontend" tool like
86+
:ref:`build` can run your chosen build tool's "backend" to create the build
87+
artifacts. Your build tool may also provide its own frontend. An install tool
88+
like :ref:`pip` also acts as a frontend when it runs your build tool's backend
89+
to install from a source distribution.
90+
91+
The particular build tool you choose dictates what additional information is
92+
required in the :file:`pyproject.toml` file. For example, you might specify:
93+
94+
* a ``[project]`` table containing project
95+
:doc:`Core Metadata </specifications/core-metadata/>`
96+
(name, version, author and so forth); see
97+
:doc:`Declaring project metadata </specifications/declaring-project-metadata/>`
98+
for more detail
99+
100+
* a ``[tool]`` table containing tool-specific configuration options
101+
102+
Build artifacts
103+
===============
104+
105+
The source distribution (sdist)
106+
-------------------------------
107+
108+
A source distribution contains enough to install the package from source in an
109+
end user's Python environment. As such, it needs the package source, and may
110+
also include tests and documentation. These are useful for end users wanting
111+
to develop your sources, and for end user systems where some local compilation
112+
step is required (such as a C extension).
113+
114+
The :ref:`build` package knows how to invoke your build tool to create one of
115+
these:
116+
117+
.. code-block:: bash
118+
119+
python3 -m build --sdist source-tree-directory
120+
121+
Or, your build tool may provide its own interface for creating an sdist.
122+
123+
124+
The built distributions (wheels)
125+
--------------------------------
126+
127+
A built distribution contains only the files needed for an end user's Python
128+
environment. No compilation steps are required during the install, and the
129+
wheel file can simply be unpacked into the ``site-packages`` directory. This
130+
makes the install faster and more convenient for end users.
131+
132+
A pure Python package typically needs only one "generic" wheel. A package with
133+
compiled binary extensions needs a wheel for each supported combination of
134+
Python interpreter, operating system, and CPU architecture that it supports.
135+
If a suitable wheel file is not available, tools like :ref:`pip` will fall
136+
back to installing the source distribution.
137+
138+
The :ref:`build` package knows how to invoke your build tool to create one of
139+
these:
140+
141+
.. code-block:: bash
142+
143+
python3 -m build --wheel source-tree-directory
144+
145+
Or, your build tool may provide its own interface for creating a wheel.
146+
147+
.. note::
148+
149+
The default behaviour of :ref:`build` is to make both an sdist and a wheel
150+
from the source in the current directory; the above examples are
151+
deliberately specific.
152+
153+
Upload to the package distribution service
154+
==========================================
155+
156+
The :ref:`twine` tool can upload build artifacts to PyPI for distribution,
157+
using a command like:
158+
159+
.. code-block:: bash
160+
161+
twine upload dist/package-name-version.tar.gz dist/package-name-version-py3-none-any.whl
162+
163+
Or, your build tool may provide its own interface for uploading.
164+
165+
Download and install
166+
====================
167+
168+
Now that the package is published, end users can download and install the
169+
package into their Python environment. Typically this is done with :ref:`pip`,
170+
using a command like:
171+
172+
.. code-block:: bash
173+
174+
python3 -m pip install package-name
175+
176+
End users may also use other tools like :ref:`pipenv`, :ref:`poetry`, or
177+
:ref:`pdm`.

source/guides/analyzing-pypi-package-downloads.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ limited resources.
4242
Public dataset
4343
==============
4444

45-
As an alternative, the `Linehaul project <https://github.com/pypa/linehaul>`__
45+
As an alternative, the `Linehaul project <https://github.com/pypa/linehaul-cloud-function/>`__
4646
streams download logs from PyPI to `Google BigQuery`_ [#]_, where they are
4747
stored as a public dataset.
4848

source/guides/distributing-packages-using-setuptools.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ work of turning these interfaces into actual scripts [2]_. The scripts will be
542542
generated during the install of your :term:`distribution <Distribution
543543
Package>`.
544544

545-
For more information, see `Automatic Script Creation
546-
<https://setuptools.readthedocs.io/en/latest/userguide/quickstart.html#entry-points-and-automatic-script-creation>`_
545+
For more information, see :doc:`Entry Points <setuptools:userguide/entry_point>`
547546
from the :doc:`setuptools docs <setuptools:index>`.
548547

549548
.. _`Choosing a versioning scheme`:

source/guides/github-actions-ci-cd-sample/publish-to-test-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
.
3030
# Actually publish to PyPI/TestPyPI
3131
- name: Publish distribution 📦 to Test PyPI
32-
uses: pypa/gh-action-pypi-publish@master
32+
uses: pypa/gh-action-pypi-publish@release/v1
3333
with:
3434
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
3535
repository_url: https://test.pypi.org/legacy/
3636
- name: Publish distribution 📦 to PyPI
3737
if: startsWith(github.ref, 'refs/tags')
38-
uses: pypa/gh-action-pypi-publish@master
38+
uses: pypa/gh-action-pypi-publish@release/v1
3939
with:
4040
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)