Skip to content

Commit 7f39c1d

Browse files
Merge pull request #789 from kwinkunks/patch-1
Adding note about dynamic versioning to README, fixes #756
2 parents a70d44b + 0431f4e commit 7f39c1d

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

README.rst

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
setuptools_scm
22
==============
33

4-
``setuptools_scm`` extract Python package versions from ``git`` or
4+
``setuptools_scm`` extracts Python package versions from ``git`` or
55
``hg`` metadata instead of declaring them as the version argument
66
or in a SCM managed file.
77

8-
Additionally ``setuptools_scm`` provides setuptools with a list of files that are managed by the SCM
9-
(i.e. it automatically adds all of the SCM-managed files to the sdist).
10-
Unwanted files must be excluded by discarding them via ``MANIFEST.in``.
8+
Additionally ``setuptools_scm`` provides setuptools with a list of
9+
files that are managed by the SCM (i.e. it automatically adds all of
10+
the SCM-managed files to the sdist). Unwanted files must be excluded
11+
by discarding them via ``MANIFEST.in``.
1112

12-
``setuptools_scm`` support the following scm out of the box:
13+
``setuptools_scm`` supports the following scm out of the box:
1314

1415
* git
1516
* mercurial
1617

17-
18-
1918
.. image:: https://github.com/pypa/setuptools_scm/workflows/python%20tests+artifacts+release/badge.svg
2019
:target: https://github.com/pypa/setuptools_scm/actions
2120

@@ -43,7 +42,6 @@ built step by specifying it as one of the build requirements.
4342
[build-system]
4443
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
4544
46-
4745
That will be sufficient to require ``setuptools_scm`` for projects
4846
that support PEP 518 (`pip <https://pypi.org/project/pip>`_ and
4947
`pep517 <https://pypi.org/project/pep517/>`_). Many tools,
@@ -52,7 +50,17 @@ continue to rely on ``setup_requires``. For maximum compatibility
5250
with those uses, consider also including a ``setup_requires`` directive
5351
(described below in ``setup.py usage`` and ``setup.cfg``).
5452

55-
To enable version inference, add this section to your ``pyproject.toml``:
53+
To enable version inference, you need to set the version
54+
dynamically in the ``project`` section of ``pyproject.toml``:
55+
56+
.. code:: toml
57+
58+
# pyproject.toml
59+
[project]
60+
# version = "0.0.1" # Remove any existing version parameter.
61+
dynamic = ["version"]
62+
63+
Then add this section to your ``pyproject.toml``:
5664

5765
.. code:: toml
5866
@@ -67,10 +75,10 @@ to be supplied to ``get_version()``. For example:
6775
.. code:: toml
6876
6977
# pyproject.toml
70-
7178
[tool.setuptools_scm]
7279
write_to = "pkg/_version.py"
7380
81+
Where ``pkg`` is the name of your package.
7482

7583
If you need to confirm which version string is being generated
7684
or debug the configuration, you can install
@@ -152,6 +160,7 @@ as ``setup_requires`` is deprecated in favour of ``pyproject.toml``
152160
usage in ``setup.cfg`` is considered deprecated,
153161
please use ``pyproject.toml`` whenever possible.
154162

163+
155164
Programmatic usage
156165
------------------
157166

@@ -222,6 +231,7 @@ The underlying reason is, that services like *Read the Docs* sometimes change
222231
the working directory for good reasons and using the installed metadata
223232
prevents using needless volatile data there.
224233

234+
225235
Usage from Docker
226236
-----------------
227237

@@ -255,6 +265,7 @@ To avoid BuildKit and mounting of the .git folder altogether, one can also pass
255265
version as a build argument. Note that ``SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME}``
256266
is preferred over ``SETUPTOOLS_SCM_PRETEND_VERSION``.
257267

268+
258269
Default versioning scheme
259270
-------------------------
260271

@@ -278,10 +289,10 @@ distance and not clean:
278289
The next version is calculated by adding ``1`` to the last numeric component of
279290
the tag.
280291

281-
282292
For Git projects, the version relies on `git describe <https://git-scm.com/docs/git-describe>`_,
283293
so you will see an additional ``g`` prepended to the ``{revision hash}``.
284294

295+
285296
Semantic Versioning (SemVer)
286297
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287298

@@ -306,6 +317,7 @@ Builtin mechanisms for obtaining version numbers
306317
3. ``.git_archival.txt`` files (git archives, see subsection below)
307318
4. ``PKG-INFO``
308319

320+
309321
Git archives
310322
~~~~~~~~~~~~
311323

@@ -328,6 +340,9 @@ Finally, don't forget to commit those two files::
328340

329341
git add .git_archival.txt .gitattributes && git commit
330342

343+
Note that if you are creating a ``_version.py`` file, note that it should not
344+
be kept in version control.
345+
331346

332347
File finders hook makes most of MANIFEST.in unnecessary
333348
-------------------------------------------------------
@@ -453,7 +468,6 @@ The currently supported configuration keys are:
453468
that setuptools will still normalize it to create the final distribution,
454469
so as to stay compliant with the python packaging standards.
455470

456-
457471
To use ``setuptools_scm`` in other Python code you can use the ``get_version``
458472
function:
459473

@@ -479,6 +493,7 @@ Example configuration in ``setup.py`` format:
479493
}
480494
)
481495
496+
482497
Environment variables
483498
---------------------
484499

@@ -487,15 +502,13 @@ Environment variables
487502
its used as the primary source for the version number
488503
in which case it will be a unparsed string
489504

490-
491505
:SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME}:
492506
when defined and not empty,
493507
its used as the primary source for the version number
494508
in which case it will be a unparsed string
495509

496510
it takes precedence over ``SETUPTOOLS_SCM_PRETEND_VERSION``
497511

498-
499512
:SETUPTOOLS_SCM_DEBUG:
500513
when defined and not empty,
501514
a lot of debug information will be printed as part of ``setuptools_scm``
@@ -507,17 +520,18 @@ Environment variables
507520
derived, otherwise the current time is used
508521
(https://reproducible-builds.org/docs/source-date-epoch/)
509522

510-
511523
:SETUPTOOLS_SCM_IGNORE_VCS_ROOTS:
512524
when defined, a ``os.pathsep`` separated list
513525
of directory names to ignore for root finding
514526

527+
515528
Extending setuptools_scm
516529
------------------------
517530

518531
``setuptools_scm`` ships with a few ``setuptools`` entrypoints based hooks to
519532
extend its default capabilities.
520533

534+
521535
Adding a new SCM
522536
~~~~~~~~~~~~~~~~
523537

@@ -539,6 +553,7 @@ Adding a new SCM
539553

540554
Also use then name of your SCM control directory as name of the entrypoint.
541555

556+
542557
Version number construction
543558
~~~~~~~~~~~~~~~~~~~~~~~~~~~
544559

@@ -594,7 +609,6 @@ is supported.
594609
Within that callable, ``setuptools_scm`` is available for import.
595610
The callable must return the configuration.
596611

597-
598612
.. code:: python
599613
600614
# content of setup.py
@@ -641,7 +655,6 @@ its still possible to install a more recent version of setuptools in order to ha
641655
and/or install the package by using wheels or eggs.
642656

643657

644-
645658
Code of Conduct
646659
---------------
647660

@@ -651,6 +664,7 @@ trackers, chat rooms, and mailing lists is expected to follow the
651664

652665
.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md
653666

667+
654668
Security Contact
655669
================
656670

0 commit comments

Comments
 (0)