fix: update macros.py to use setuptools_scm for dynamic versioning#20
Merged
fix: update macros.py to use setuptools_scm for dynamic versioning#20
Conversation
After migrating from bump2version to setuptools_scm, project.version is no longer a static field in pyproject.toml. Use get_version() from setuptools_scm instead, and add it to docs optional dependencies so the CI docs build has access to it.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a broken documentation build by migrating the macros.py version detection from reading a static version field in pyproject.toml to using setuptools_scm.get_version(). This aligns with the project's recent migration from bump2version to setuptools_scm (commit 23f44fd), which changed the version to be dynamically determined from Git tags rather than statically defined.
Changes:
- Updated
macros.pyto callsetuptools_scm.get_version()instead of parsingpyproject.tomlwith tomllib - Added
setuptools_scm>=8.0to thedocsoptional dependencies to ensure it's available during documentation builds
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| macros.py | Replaced tomllib-based version reading with setuptools_scm.get_version() call; simplified _load_version() function to accept root path and delegate to setuptools_scm |
| pyproject.toml | Added setuptools_scm>=8.0 to docs optional dependencies to ensure CI has access to the versioning tool |
Comments suppressed due to low confidence (1)
macros.py:11
- The
get_version()call can raiseLookupErrorwhen the project is not in a Git repository or when Git metadata is unavailable (e.g., in a source tarball). This will cause the documentation build to fail in non-Git environments.
Consider adding error handling with a fallback value, similar to how src/alpha_hwr/__init__.py handles version lookup using importlib.metadata.version() with a try-except block that falls back to "0.0.0+unknown".
def _load_version(root: Path) -> str:
"""Return project version string using setuptools_scm."""
return get_version(root=str(root))
macros.py is a MkDocs plugin file (not library source) and imports setuptools_scm which is not installed in the type-check environment.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After migrating from bump2version to setuptools_scm (commit 23f44fd),
project.versionis no longer a static field inpyproject.toml(it usesdynamic = ["version"]). This broke the Docs CI build with:Fix
macros.pyto callsetuptools_scm.get_version()instead of reading frompyproject.tomlsetuptools_scm>=8.0to thedocsoptional dependencies so the CIpip install .[docs]step includes it