You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This configuration uses the `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}` environment variable to override the `scm.git.pre_parse` setting specifically for your project when building on ReadTheDocs, forcing setuptools-scm to fail with a clear error if the repository is shallow.
50
+
This configuration uses the `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}` environment variable to override the `scm.git.pre_parse` setting specifically for your project when building on ReadTheDocs, forcing setuptools-scm to fail with a clear error if the repository is shallow.
51
+
52
+
## CI/CD and Package Publishing
53
+
54
+
### Publishing to PyPI from CI/CD
55
+
56
+
When publishing packages to PyPI or test-PyPI from CI/CD pipelines, you often need to remove local version components that are not allowed on public package indexes according to [PEP 440](https://peps.python.org/pep-0440/#local-version-identifiers).
57
+
58
+
setuptools-scm provides the `no-local-version` local scheme and environment variable overrides to handle this scenario cleanly.
59
+
60
+
#### The Problem
61
+
62
+
By default, setuptools-scm generates version numbers like:
63
+
- `1.2.3.dev4+g1a2b3c4d5`(development version with git hash)
64
+
- `1.2.3+dirty`(dirty working directory)
65
+
66
+
These local version components (`+g1a2b3c4d5`, `+dirty`) prevent uploading to PyPI.
67
+
68
+
#### The Solution
69
+
70
+
Use the `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}` environment variable to override the `local_scheme` to `no-local-version` when building for upload to PyPI.
71
+
72
+
### GitHub Actions Example
73
+
74
+
Here's a complete GitHub Actions workflow that:
75
+
- Runs tests on all branches
76
+
- Uploads development versions to test-PyPI from feature branches
77
+
- Uploads development versions to PyPI from the main branch (with no-local-version)
78
+
- Uploads tagged releases to PyPI (using exact tag versions)
**Fetch depth**: Always use `fetch-depth: 0` in GitHub Actions to ensure setuptools-scm has access to the full git history for proper version calculation.
0 commit comments