diff --git a/CHANGELOG.md b/CHANGELOG.md index ce25d3f1..72e655de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - migrate git describe command to new scm config - add support for failing on missing submodules - fix #279: expand errors when scm can be found upwards and relative_to wasnt used +- fix #577: introduce explicit scmversion node and short node ## v8.3.1 diff --git a/src/setuptools_scm/_integration/dump_version.py b/src/setuptools_scm/_integration/dump_version.py index 6918bd19..62827a1b 100644 --- a/src/setuptools_scm/_integration/dump_version.py +++ b/src/setuptools_scm/_integration/dump_version.py @@ -6,29 +6,12 @@ from .. import _types as _t from .._log import log as parent_log -from .._node_utils import _format_node_for_output from .._version_cls import _version_as_tuple from ..version import ScmVersion log = parent_log.getChild("dump_version") -class _TemplateScmVersion: - """Wrapper for ScmVersion that formats node for template output.""" - - def __init__(self, scm_version: ScmVersion) -> None: - self._scm_version = scm_version - - def __getattr__(self, name: str) -> object: - # Delegate all attribute access to the wrapped ScmVersion - return getattr(self._scm_version, name) - - @property - def node(self) -> str | None: - """Return the node formatted for output.""" - return _format_node_for_output(self._scm_version.node) - - TEMPLATES = { ".py": """\ # file generated by setuptools-scm @@ -64,7 +47,7 @@ def node(self) -> str | None: __version__ = version = {version!r} __version_tuple__ = version_tuple = {version_tuple!r} -__commit_id__ = commit_id = {scm_version.node!r} +__commit_id__ = commit_id = {scm_version.short_node!r} """, ".txt": "{version}", } @@ -119,12 +102,10 @@ def write_version_to_path( log.debug("dump %s into %s", version, target) version_tuple = _version_as_tuple(version) if scm_version is not None: - # Wrap ScmVersion to provide formatted node for templates - template_scm_version = _TemplateScmVersion(scm_version) content = final_template.format( version=version, version_tuple=version_tuple, - scm_version=template_scm_version, + scm_version=scm_version, ) else: content = final_template.format(version=version, version_tuple=version_tuple) diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index c3bc1148..69b184eb 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -159,6 +159,11 @@ def exact(self) -> bool: """returns true checked out exactly on a tag and no local changes apply""" return self.distance == 0 and not self.dirty + @property + def short_node(self) -> str | None: + """Return the node formatted for output.""" + return _format_node_for_output(self.node) + def __repr__(self) -> str: return ( f"