Skip to content

Commit

Permalink
Single-sourcing the package version: Add instructions for setuptools …
Browse files Browse the repository at this point in the history
…using pyproject.toml (#1167)

* Add instructions for setuptools using pyproject.toml

* Copy-edit __version__ note

Co-authored-by: Brian Rutledge <brian@bhrutledge.com>
  • Loading branch information
justinchuby and bhrutledge authored Dec 6, 2022
1 parent 88ee23e commit 0b2d1bc
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions source/guides/single-sourcing-package-version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,30 @@ number of your project:
.. note::

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

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

Also, please be aware that declarative config indicators, including the
``attr:`` directive, are not supported in parameters to ``setup.py``.
.. code-block:: toml
[project]
name = "package"
dynamic = ["version"]
[tool.setuptools.dynamic]
version = {attr = "package.__version__"}
Please be aware that declarative config indicators, including the
``attr:`` directive, are not supported in parameters to
:file:`setup.py`.

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

0 comments on commit 0b2d1bc

Please sign in to comment.