Skip to content

Commit 26a6a45

Browse files
authored
Merge branch 'main' into patch-1
2 parents 86dd60f + 48ad6bf commit 26a6a45

File tree

8 files changed

+143
-21
lines changed

8 files changed

+143
-21
lines changed

source/discussions/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ specific topic. If you're just trying to get stuff done, see
1616
package-formats
1717
src-layout-vs-flat-layout
1818
setup-py-deprecated
19+
single-source-version
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. _`Single sourcing the version discussion`:
2+
3+
===================================
4+
Single-sourcing the Project Version
5+
===================================
6+
7+
:Page Status: Complete
8+
:Last Reviewed: 2024-08-24
9+
10+
One of the challenges in building packages is that the version string can be required in multiple places.
11+
12+
* It needs to be specified when building the package (e.g. in :file:`pyproject.toml`)
13+
This will make it available in the installed package’s metadata, from where it will be accessible at runtime using ``importlib.metadata.version("distribution_name")``.
14+
15+
* A package may set a module attribute (e.g., ``__version__``) to provide an alternative means of runtime access to the version of the imported package. If this is done, the value of the attribute and that used by the build system to set the distribution's version should be kept in sync in :ref:`the build systems's recommended way <Build system version handling>`.
16+
17+
* If the code is in in a version control system (VCS), e.g. Git, the version may appear in a *tag* such as ``v1.2.3``.
18+
19+
To ensure that version numbers do not get out of sync, it is recommended that there is a single source of truth for the version number.
20+
21+
In general, the options are:
22+
23+
1) If the code is in a version control system (VCS), e.g. Git, then the version can be extracted from the VCS.
24+
25+
2) The version can be hard-coded into the :file:`pyproject.toml` file -- and the build system can copy it into other locations it may be required.
26+
27+
3) The version string can be hard-coded into the source code -- either in a special purpose file, such as :file:`_version.txt`, or as a attribute in a module, such as :file:`__init__.py`, and the build system can extract it at build time.
28+
29+
30+
Consult your build system's documentation for their recommended method.
31+
32+
.. _Build system version handling:
33+
34+
Build System Version Handling
35+
-----------------------------
36+
37+
The following are links to some build system's documentation for handling version strings.
38+
39+
* `Flit <https://flit.pypa.io/en/stable/>`_
40+
41+
* `Hatchling <https://hatch.pypa.io/1.9/version/>`_
42+
43+
* `PDM <https://pdm-project.org/en/latest/reference/pep621/#__tabbed_1_2>`_
44+
45+
* `Setuptools <https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata>`_
46+
47+
- `setuptools_scm <https://setuptools-scm.readthedocs.io/en/latest/>`_

source/guides/creating-command-line-tools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ in :file:`cli.py`:
7878
7979
import typer
8080
81-
from .hello import greet
81+
from .greet import greet
8282
8383
8484
app = typer.Typer()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Build a binary wheel and a source tarball
2323
run: python3 -m build
2424
- name: Store the distribution packages
25-
uses: actions/upload-artifact@v3
25+
uses: actions/upload-artifact@v4
2626
with:
2727
name: python-package-distributions
2828
path: dist/
@@ -42,7 +42,7 @@ jobs:
4242

4343
steps:
4444
- name: Download all the dists
45-
uses: actions/download-artifact@v3
45+
uses: actions/download-artifact@v4
4646
with:
4747
name: python-package-distributions
4848
path: dist/
@@ -63,7 +63,7 @@ jobs:
6363

6464
steps:
6565
- name: Download all the dists
66-
uses: actions/download-artifact@v3
66+
uses: actions/download-artifact@v4
6767
with:
6868
name: python-package-distributions
6969
path: dist/
@@ -107,7 +107,7 @@ jobs:
107107

108108
steps:
109109
- name: Download all the dists
110-
uses: actions/download-artifact@v3
110+
uses: actions/download-artifact@v4
111111
with:
112112
name: python-package-distributions
113113
path: dist/

source/guides/packaging-binary-extensions.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,15 @@ a Debian system, see the following articles:
403403
* `What are (c)python extension modules? <https://thomasnyberg.com/what_are_extension_modules.html>`_
404404
* `Releasing the gil <https://thomasnyberg.com/releasing_the_gil.html>`_
405405
* `Writing cpython extension modules using C++ <https://thomasnyberg.com/cpp_extension_modules.html>`_
406+
407+
Additional considerations for binary wheels
408+
-------------------------------------------
409+
410+
The `pypackaging-native <https://pypackaging-native.github.io/>`_ website has
411+
additional coverage of packaging Python packages with native code. It aims to
412+
provide an overview of the most important packaging issues for such projects,
413+
with in-depth explanations and references.
414+
415+
Examples of topics covered are non-Python compiled dependencies ("native
416+
dependencies"), the importance of the ABI (Application Binary Interface) of
417+
native code, dependency on SIMD code and cross compilation.

source/guides/writing-pyproject-toml.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ three possible TOML tables in this file.
2222

2323
.. note::
2424

25-
There is a significant difference between the ``[build-system]`` and
26-
``[project]`` tables. The former should always be present, regardless of
27-
which build backend you use (since it *defines* the tool you use). The latter
28-
is understood by *most* build backends, but some build backends use a
29-
different format.
25+
The ``[build-system]`` table should always be present,
26+
regardless of which build backend you use (``[build-system]`` *defines* the
27+
build tool you use).
3028

31-
At the time of writing this (November 2023), Poetry_ is a notable build
32-
backend that does not use the ``[project]`` table (it uses the
33-
``[tool.poetry]`` table instead).
29+
On the other hand, the ``[project]`` table is understood by *most* build
30+
backends, but some build backends use a different format.
3431

32+
As of August 2024, Poetry_ is a notable build backend that does not use
33+
the ``[project]`` table, it uses the ``[tool.poetry]`` table instead.
3534
Also, the setuptools_ build backend supports both the ``[project]`` table,
36-
and the older format in ``setup.cfg`` or ``setup.py``. For new projects, it
37-
is recommended to use the ``[project]`` table, and keep ``setup.py`` only if
35+
and the older format in ``setup.cfg`` or ``setup.py``.
36+
37+
For new projects, use the ``[project]`` table, and keep ``setup.py`` only if
3838
some programmatic configuration is needed (such as building C extensions),
3939
but the ``setup.cfg`` and ``setup.py`` formats are still valid. See
4040
:ref:`setup-py-deprecated`.
@@ -130,7 +130,7 @@ only field that cannot be marked as dynamic.
130130
[project]
131131
name = "spam-eggs"
132132
133-
The project name must consists of ASCII letters, digits, underscores "``_``",
133+
The project name must consist of ASCII letters, digits, underscores "``_``",
134134
hyphens "``-``" and periods "``.``". It must not start or end with an
135135
underscore, hyphen or period.
136136

source/specifications/core-metadata.rst

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Metadata-Version
4848
.. versionadded:: 1.0
4949

5050
Version of the file format; legal values are "1.0", "1.1", "1.2", "2.1",
51-
"2.2", and "2.3".
51+
"2.2", "2.3", and "2.4".
5252

5353
Automated tools consuming metadata SHOULD warn if ``metadata_version`` is
5454
greater than the highest version they support, and MUST fail if
@@ -63,7 +63,7 @@ all of the needed fields.
6363

6464
Example::
6565

66-
Metadata-Version: 2.3
66+
Metadata-Version: 2.4
6767

6868

6969
.. _core-metadata-name:
@@ -460,6 +460,14 @@ License
460460
=======
461461

462462
.. versionadded:: 1.0
463+
.. deprecated:: 2.4
464+
in favour of ``License-Expression``.
465+
466+
.. warning::
467+
As of Metadata 2.4, ``License`` and ``License-Expression`` are mutually
468+
exclusive. If both are specified, tools which parse metadata will disregard
469+
``License`` and PyPI will reject uploads.
470+
See `PEP 639 <https://peps.python.org/pep-0639/#deprecate-license-field>`__.
463471

464472
Text indicating the license covering the distribution where the license
465473
is not a selection from the "License" Trove classifiers. See
@@ -477,6 +485,50 @@ Examples::
477485
License: GPL version 3, excluding DRM provisions
478486

479487

488+
.. _license-expression-optional:
489+
.. _core-metadata-license-expression:
490+
491+
License-Expression
492+
==================
493+
494+
.. versionadded:: 2.4
495+
496+
Text string that is a valid SPDX
497+
`license expression <https://peps.python.org/pep-0639/#term-license-expression>`__
498+
as `defined in PEP 639 <https://peps.python.org/pep-0639/#spdx>`__.
499+
500+
Examples::
501+
502+
License-Expression: MIT
503+
License-Expression: BSD-3-Clause
504+
License-Expression: MIT AND (Apache-2.0 OR BSD-2-Clause)
505+
License-Expression: MIT OR GPL-2.0-or-later OR (FSFUL AND BSD-2-Clause)
506+
License-Expression: GPL-3.0-only WITH Classpath-Exception-2.0 OR BSD-3-Clause
507+
License-Expression: LicenseRef-Special-License OR CC0-1.0 OR Unlicense
508+
License-Expression: LicenseRef-Proprietary
509+
510+
511+
.. _license-file-optional:
512+
.. _core-metadata-license-file:
513+
514+
License-File (multiple use)
515+
===========================
516+
517+
.. versionadded:: 2.4
518+
519+
Each entry is a string representation of the path of a license-related file.
520+
The path is located within the project source tree, relative to the project
521+
root directory. For details see :pep:`639`.
522+
523+
Examples::
524+
525+
License-File: LICENSE
526+
License-File: AUTHORS
527+
License-File: LICENSE.txt
528+
License-File: licenses/LICENSE.MIT
529+
License-File: licenses/LICENSE.CC0
530+
531+
480532
.. _metadata-classifier:
481533
.. _core-metadata-classifier:
482534

@@ -490,6 +542,11 @@ for the distribution. Classifiers are described in :pep:`301`,
490542
and the Python Package Index publishes a dynamic list of
491543
`currently defined classifiers <https://pypi.org/classifiers/>`__.
492544

545+
.. note::
546+
The use of ``License ::`` classifiers is deprecated as of Metadata 2.4,
547+
use ``License-Expression`` instead. See
548+
`PEP 639 <https://peps.python.org/pep-0639/#deprecate-license-classifiers>`_.
549+
493550
This field may be followed by an environment marker after a semicolon.
494551

495552
Examples::
@@ -725,7 +782,7 @@ This field may be followed by an environment marker after a semicolon.
725782
Examples::
726783

727784
Provides-Dist: OtherProject
728-
Provides-Dist: AnotherProject (3.4)
785+
Provides-Dist: AnotherProject==3.4
729786
Provides-Dist: virtual_package; python_version >= "3.4"
730787

731788
.. _core-metadata-obsoletes-dist:
@@ -864,6 +921,11 @@ History
864921

865922
- Restricted extra names to be normalized.
866923

924+
- August 2024: Core metadata 2.4 was approved through :pep:`639`.
925+
926+
- Added the ``License-Expression`` field.
927+
- Added the ``License-File`` field.
928+
867929
----
868930

869931
.. [1] reStructuredText markup:

source/specifications/platform-compatibility-tags.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ The full list of simple tags is::
256256

257257
for x in pytag.split('.'):
258258
for y in abitag.split('.'):
259-
for z in archtag.split('.'):
259+
for z in platformtag.split('.'):
260260
yield '-'.join((x, y, z))
261261

262262
A bdist format that implements this scheme should include the expanded
@@ -343,5 +343,5 @@ History
343343

344344

345345
.. _musl: https://musl.libc.org
346-
.. _ldd: https://www.unix.com/man-page/posix/1/ldd/
346+
.. _ldd: https://www.man7.org/linux/man-pages/man1/ldd.1.html
347347
.. _elf: https://refspecs.linuxfoundation.org/elf/elf.pdf

0 commit comments

Comments
 (0)