|
| 1 | +# setuptools_scm |
| 2 | +[](https://github.com/pypa/setuptools_scm/actions) |
| 3 | +[ ](https://tidelift.com/subscription/pkg/pypi-setuptools-scm?utm_source=pypi-setuptools-scm&utm_medium=readme) |
| 4 | + |
| 5 | +## about |
| 6 | + |
| 7 | +[setuptools-scm] extracts Python package versions from `git` or |
| 8 | +`hg` metadata instead of declaring them as the version argument |
| 9 | +or in an SCM managed file. |
| 10 | + |
| 11 | +Additionally, [setuptools-scm] provides setuptools |
| 12 | +with a list of files that are managed by the SCM <br/> |
| 13 | +(i.e. it automatically adds **all of** the SCM-managed files to the sdist).<br/> |
| 14 | +Unwanted files must be excluded via `MANIFEST.in`. |
| 15 | + |
| 16 | + |
| 17 | +## `pyproject.toml` usage |
| 18 | + |
| 19 | +The preferred way to configure [setuptools-scm] is to author |
| 20 | +settings in a `tool.setuptools_scm` section of `pyproject.toml`. |
| 21 | + |
| 22 | +This feature requires setuptools 60 or later. |
| 23 | +First, ensure that [setuptools-scm] is present during the project's |
| 24 | +build step by specifying it as one of the build requirements. |
| 25 | + |
| 26 | +```toml |
| 27 | +[build-system] |
| 28 | +requires = [ |
| 29 | + "setuptools>=60", |
| 30 | + "setuptools-scm>=8.0"] |
| 31 | +``` |
| 32 | + |
| 33 | +That will be sufficient to require [setuptools-scm] for projects |
| 34 | +that support [PEP 518] like [pip] and [build]. |
| 35 | + |
| 36 | +[pip]: https://pypi.org/project/pip |
| 37 | +[build]: https://pypi.org/project/build |
| 38 | +[PEP 518]: https://peps.python.org/pep-0518/ |
| 39 | + |
| 40 | + |
| 41 | +To enable version inference, you need to set the version |
| 42 | +dynamically in the `project` section of `pyproject.toml`: |
| 43 | + |
| 44 | +```toml title="pyproject.toml" |
| 45 | +[project] |
| 46 | +# version = "0.0.1" # Remove any existing version parameter. |
| 47 | +dynamic = ["version"] |
| 48 | +[tool.setuptools_scm] |
| 49 | +``` |
| 50 | + |
| 51 | +Additionally, a version file can be written by specifying: |
| 52 | + |
| 53 | +```toml title="pyproject.toml" |
| 54 | +[tool.setuptools_scm] |
| 55 | +version_file = "pkg/_version.py" |
| 56 | +``` |
| 57 | + |
| 58 | +Where `pkg` is the name of your package. |
| 59 | + |
| 60 | +If you need to confirm which version string is being generated or debug the configuration, |
| 61 | +you can install [setuptools-scm] directly in your working environment and run: |
| 62 | + |
| 63 | +[setuptools-scm]: https://github.com/pypa/setuptools_scm |
| 64 | + |
| 65 | +```console |
| 66 | +$ python -m setuptools_scm |
| 67 | +# To explore other options, try: |
| 68 | +$ python -m setuptools_scm --help |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +## Interaction with Enterprise Distributions |
| 74 | + |
| 75 | +Some enterprise distributions like RHEL7 |
| 76 | +ship rather old setuptools versions. |
| 77 | + |
| 78 | +In those cases its typically possible to build by using an sdist against `setuptools_scm<2.0`. |
| 79 | +As those old setuptools versions lack sensible types for versions, |
| 80 | +modern [setuptools-scm] is unable to support them sensibly. |
| 81 | + |
| 82 | +It's strongly recommended to build a wheel artifact using modern Python and setuptools, |
| 83 | +then installing the artifact instead of trying to run against old setuptools versions. |
| 84 | + |
| 85 | + |
| 86 | +## Code of Conduct |
| 87 | + |
| 88 | + |
| 89 | +Everyone interacting in the [setuptools-scm] project's codebases, issue |
| 90 | +trackers, chat rooms, and mailing lists is expected to follow the |
| 91 | +[PSF Code of Conduct]. |
| 92 | + |
| 93 | +[PSF Code of Conduct]: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md |
| 94 | + |
| 95 | + |
| 96 | +## Security Contact |
| 97 | + |
| 98 | +To report a security vulnerability, please use the |
| 99 | +[Tidelift security contact](https://tidelift.com/security). |
| 100 | +Tidelift will coordinate the fix and disclosure. |
0 commit comments