11setuptools_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
66or 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
4846that 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
5250with 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
7583If you need to confirm which version string is being generated
7684or debug the configuration, you can install
@@ -152,6 +160,7 @@ as ``setup_requires`` is deprecated in favour of ``pyproject.toml``
152160usage in ``setup.cfg `` is considered deprecated,
153161please use ``pyproject.toml `` whenever possible.
154162
163+
155164Programmatic usage
156165------------------
157166
@@ -222,6 +231,7 @@ The underlying reason is, that services like *Read the Docs* sometimes change
222231the working directory for good reasons and using the installed metadata
223232prevents using needless volatile data there.
224233
234+
225235Usage from Docker
226236-----------------
227237
@@ -255,6 +265,7 @@ To avoid BuildKit and mounting of the .git folder altogether, one can also pass
255265version as a build argument. Note that ``SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME} ``
256266is preferred over ``SETUPTOOLS_SCM_PRETEND_VERSION ``.
257267
268+
258269Default versioning scheme
259270-------------------------
260271
@@ -278,10 +289,10 @@ distance and not clean:
278289The next version is calculated by adding ``1 `` to the last numeric component of
279290the tag.
280291
281-
282292For Git projects, the version relies on `git describe <https://git-scm.com/docs/git-describe >`_,
283293so you will see an additional ``g `` prepended to the ``{revision hash} ``.
284294
295+
285296Semantic Versioning (SemVer)
286297~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287298
@@ -306,6 +317,7 @@ Builtin mechanisms for obtaining version numbers
3063173. ``.git_archival.txt `` files (git archives, see subsection below)
3073184. ``PKG-INFO ``
308319
320+
309321Git 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
332347File 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-
457471To use ``setuptools_scm `` in other Python code you can use the ``get_version ``
458472function:
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+
515528Extending setuptools_scm
516529------------------------
517530
518531``setuptools_scm `` ships with a few ``setuptools `` entrypoints based hooks to
519532extend its default capabilities.
520533
534+
521535Adding 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+
542557Version number construction
543558~~~~~~~~~~~~~~~~~~~~~~~~~~~
544559
@@ -594,7 +609,6 @@ is supported.
594609Within that callable, ``setuptools_scm `` is available for import.
595610The 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
641655and/or install the package by using wheels or eggs.
642656
643657
644-
645658Code 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+
654668Security Contact
655669================
656670
0 commit comments