1
1
setuptools_scm
2
2
==============
3
3
4
- ``setuptools_scm `` extract Python package versions from ``git `` or
4
+ ``setuptools_scm `` extracts Python package versions from ``git `` or
5
5
``hg `` metadata instead of declaring them as the version argument
6
6
or in a SCM managed file.
7
7
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 ``.
11
12
12
- ``setuptools_scm `` support the following scm out of the box:
13
+ ``setuptools_scm `` supports the following scm out of the box:
13
14
14
15
* git
15
16
* mercurial
16
17
17
-
18
-
19
18
.. image :: https://github.com/pypa/setuptools_scm/workflows/python%20tests+artifacts+release/badge.svg
20
19
:target: https://github.com/pypa/setuptools_scm/actions
21
20
@@ -43,7 +42,6 @@ built step by specifying it as one of the build requirements.
43
42
[build-system]
44
43
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
45
44
46
-
47
45
That will be sufficient to require ``setuptools_scm `` for projects
48
46
that support PEP 518 (`pip <https://pypi.org/project/pip >`_ and
49
47
`pep517 <https://pypi.org/project/pep517/ >`_). Many tools,
@@ -52,7 +50,17 @@ continue to rely on ``setup_requires``. For maximum compatibility
52
50
with those uses, consider also including a ``setup_requires `` directive
53
51
(described below in ``setup.py usage `` and ``setup.cfg ``).
54
52
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 ``:
56
64
57
65
.. code :: toml
58
66
@@ -67,10 +75,10 @@ to be supplied to ``get_version()``. For example:
67
75
.. code :: toml
68
76
69
77
# pyproject.toml
70
-
71
78
[tool.setuptools_scm]
72
79
write_to = "pkg/_version.py"
73
80
81
+ Where ``pkg `` is the name of your package.
74
82
75
83
If you need to confirm which version string is being generated
76
84
or debug the configuration, you can install
@@ -152,6 +160,7 @@ as ``setup_requires`` is deprecated in favour of ``pyproject.toml``
152
160
usage in ``setup.cfg `` is considered deprecated,
153
161
please use ``pyproject.toml `` whenever possible.
154
162
163
+
155
164
Programmatic usage
156
165
------------------
157
166
@@ -222,6 +231,7 @@ The underlying reason is, that services like *Read the Docs* sometimes change
222
231
the working directory for good reasons and using the installed metadata
223
232
prevents using needless volatile data there.
224
233
234
+
225
235
Usage from Docker
226
236
-----------------
227
237
@@ -255,6 +265,7 @@ To avoid BuildKit and mounting of the .git folder altogether, one can also pass
255
265
version as a build argument. Note that ``SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME} ``
256
266
is preferred over ``SETUPTOOLS_SCM_PRETEND_VERSION ``.
257
267
268
+
258
269
Default versioning scheme
259
270
-------------------------
260
271
@@ -278,10 +289,10 @@ distance and not clean:
278
289
The next version is calculated by adding ``1 `` to the last numeric component of
279
290
the tag.
280
291
281
-
282
292
For Git projects, the version relies on `git describe <https://git-scm.com/docs/git-describe >`_,
283
293
so you will see an additional ``g `` prepended to the ``{revision hash} ``.
284
294
295
+
285
296
Semantic Versioning (SemVer)
286
297
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287
298
@@ -306,6 +317,7 @@ Builtin mechanisms for obtaining version numbers
306
317
3. ``.git_archival.txt `` files (git archives, see subsection below)
307
318
4. ``PKG-INFO ``
308
319
320
+
309
321
Git archives
310
322
~~~~~~~~~~~~
311
323
@@ -328,6 +340,9 @@ Finally, don't forget to commit those two files::
328
340
329
341
git add .git_archival.txt .gitattributes && git commit
330
342
343
+ Note that if you are creating a ``_version.py `` file, note that it should not
344
+ be kept in version control.
345
+
331
346
332
347
File finders hook makes most of MANIFEST.in unnecessary
333
348
-------------------------------------------------------
@@ -453,7 +468,6 @@ The currently supported configuration keys are:
453
468
that setuptools will still normalize it to create the final distribution,
454
469
so as to stay compliant with the python packaging standards.
455
470
456
-
457
471
To use ``setuptools_scm `` in other Python code you can use the ``get_version ``
458
472
function:
459
473
@@ -479,6 +493,7 @@ Example configuration in ``setup.py`` format:
479
493
}
480
494
)
481
495
496
+
482
497
Environment variables
483
498
---------------------
484
499
@@ -487,15 +502,13 @@ Environment variables
487
502
its used as the primary source for the version number
488
503
in which case it will be a unparsed string
489
504
490
-
491
505
:SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${UPPERCASED_DIST_NAME}:
492
506
when defined and not empty,
493
507
its used as the primary source for the version number
494
508
in which case it will be a unparsed string
495
509
496
510
it takes precedence over ``SETUPTOOLS_SCM_PRETEND_VERSION ``
497
511
498
-
499
512
:SETUPTOOLS_SCM_DEBUG:
500
513
when defined and not empty,
501
514
a lot of debug information will be printed as part of ``setuptools_scm ``
@@ -507,17 +520,18 @@ Environment variables
507
520
derived, otherwise the current time is used
508
521
(https://reproducible-builds.org/docs/source-date-epoch/)
509
522
510
-
511
523
:SETUPTOOLS_SCM_IGNORE_VCS_ROOTS:
512
524
when defined, a ``os.pathsep `` separated list
513
525
of directory names to ignore for root finding
514
526
527
+
515
528
Extending setuptools_scm
516
529
------------------------
517
530
518
531
``setuptools_scm `` ships with a few ``setuptools `` entrypoints based hooks to
519
532
extend its default capabilities.
520
533
534
+
521
535
Adding a new SCM
522
536
~~~~~~~~~~~~~~~~
523
537
@@ -539,6 +553,7 @@ Adding a new SCM
539
553
540
554
Also use then name of your SCM control directory as name of the entrypoint.
541
555
556
+
542
557
Version number construction
543
558
~~~~~~~~~~~~~~~~~~~~~~~~~~~
544
559
@@ -594,7 +609,6 @@ is supported.
594
609
Within that callable, ``setuptools_scm `` is available for import.
595
610
The callable must return the configuration.
596
611
597
-
598
612
.. code :: python
599
613
600
614
# content of setup.py
@@ -641,7 +655,6 @@ its still possible to install a more recent version of setuptools in order to ha
641
655
and/or install the package by using wheels or eggs.
642
656
643
657
644
-
645
658
Code of Conduct
646
659
---------------
647
660
@@ -651,6 +664,7 @@ trackers, chat rooms, and mailing lists is expected to follow the
651
664
652
665
.. _PSF Code of Conduct : https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md
653
666
667
+
654
668
Security Contact
655
669
================
656
670
0 commit comments