Last active
February 28, 2026 05:04
-
-
Save bskinn/e8ecbf886ced696c406018ee53a4a93e to your computer and use it in GitHub Desktop.
Post version bumping setuptools-scm version-scheme callable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import setuptools_scm | |
| from packaging.version import Version | |
| def post_bump_then_dev(version: setuptools_scm.ScmVersion) -> str: | |
| """ | |
| Ahead of tag: | |
| - v0.1 -> 0.1.post1.devN | |
| - v0.1.post1 -> 0.1.post2.devN | |
| Exact tag: | |
| - v0.1.post1 at HEAD -> 0.1.post1 | |
| Local part (+gSHA / timestamp) is handled by local_scheme. | |
| """ | |
| # If exactly on the tag (and clean), keep the tag version verbatim. | |
| if version.distance == 0 and not version.dirty: | |
| return str(version.tag) | |
| tag_v = Version(str(version.tag)) | |
| # Base release like "0.1" or "1.2.3" | |
| base = ".".join(map(str, tag_v.release)) | |
| # Any prerelease | |
| pre = tag_v.pre and "".join(map(str, tag_v.pre)) | |
| # Any epoch | |
| epoch = f"{e}!" if (e := tag_v.epoch) else "" | |
| # Bump post: None->1, N->N+1 | |
| next_post = (tag_v.post or 0) + 1 | |
| # Use the actual commit distance from the tag for devN | |
| return f"{epoch}{base}{pre}.post{next_post}.dev{version.distance}" | |
| if __name__ == "__main__": | |
| print( | |
| setuptools_scm.get_version( | |
| version_scheme=post_bump_then_dev, | |
| local_scheme="node-and-timestamp", | |
| tag_regex=r"^v(?P<version>(\d+!)?\d+\.\d+.*)$", | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment