Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-sourcing the package version: Add instructions for setuptools using pyproject.toml #1167

Merged
merged 5 commits into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__"}
bhrutledge marked this conversation as resolved.
Show resolved Hide resolved

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