Skip to content

Commit 0b2d1bc

Browse files
Single-sourcing the package version: Add instructions for setuptools using pyproject.toml (#1167)
* Add instructions for setuptools using pyproject.toml * Copy-edit __version__ note Co-authored-by: Brian Rutledge <[email protected]>
1 parent 88ee23e commit 0b2d1bc

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

source/guides/single-sourcing-package-version.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,30 @@ number of your project:
3636
.. note::
3737

3838
As of the release of setuptools 46.4.0, one can accomplish the same
39-
thing by instead placing the following in the project's ``setup.cfg``
40-
file (replacing "package" with the import name of the package):
39+
thing by instead placing the following in the project's
40+
:file:`setup.cfg` file (replacing "package" with the import name of the
41+
package):
4142

4243
.. code-block:: ini
4344
4445
[metadata]
4546
version = attr: package.__version__
4647
47-
Earlier versions of setuptools implemented the ``attr:`` directive by
48-
importing the module, but setuptools 46.4.0 added rudimentary AST
49-
analysis so that ``attr:`` can function without having to import any of
50-
the package's dependencies.
48+
As of the release of setuptools 61.0.0, one can specify the
49+
version dynamically in the project's :file:`pyproject.toml` file.
5150

52-
Also, please be aware that declarative config indicators, including the
53-
``attr:`` directive, are not supported in parameters to ``setup.py``.
51+
.. code-block:: toml
52+
53+
[project]
54+
name = "package"
55+
dynamic = ["version"]
56+
57+
[tool.setuptools.dynamic]
58+
version = {attr = "package.__version__"}
59+
60+
Please be aware that declarative config indicators, including the
61+
``attr:`` directive, are not supported in parameters to
62+
:file:`setup.py`.
5463

5564
#. Use an external build tool that either manages updating both locations, or
5665
offers an API that both locations can use.

0 commit comments

Comments
 (0)