Skip to content

Commit e804af2

Browse files
fix #577: intoduce explicit short node
1 parent 69fb3a5 commit e804af2

File tree

5 files changed

+11
-24
lines changed

5 files changed

+11
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- migrate git describe command to new scm config
3333
- add support for failing on missing submodules
3434
- fix #279: expand errors when scm can be found upwards and relative_to wasnt used
35+
- fix #577: introduce explicit scmversion node and short node
3536

3637
## v8.3.1
3738

src/setuptools_scm/_integration/dump_version.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@
66

77
from .. import _types as _t
88
from .._log import log as parent_log
9-
from .._node_utils import _format_node_for_output
109
from .._version_cls import _version_as_tuple
1110
from ..version import ScmVersion
1211

1312
log = parent_log.getChild("dump_version")
1413

1514

16-
class _TemplateScmVersion:
17-
"""Wrapper for ScmVersion that formats node for template output."""
18-
19-
def __init__(self, scm_version: ScmVersion) -> None:
20-
self._scm_version = scm_version
21-
22-
def __getattr__(self, name: str) -> object:
23-
# Delegate all attribute access to the wrapped ScmVersion
24-
return getattr(self._scm_version, name)
25-
26-
@property
27-
def node(self) -> str | None:
28-
"""Return the node formatted for output."""
29-
return _format_node_for_output(self._scm_version.node)
30-
31-
3215
TEMPLATES = {
3316
".py": """\
3417
# file generated by setuptools-scm
@@ -64,7 +47,7 @@ def node(self) -> str | None:
6447
__version__ = version = {version!r}
6548
__version_tuple__ = version_tuple = {version_tuple!r}
6649
67-
__commit_id__ = commit_id = {scm_version.node!r}
50+
__commit_id__ = commit_id = {scm_version.short_node!r}
6851
""",
6952
".txt": "{version}",
7053
}
@@ -119,12 +102,10 @@ def write_version_to_path(
119102
log.debug("dump %s into %s", version, target)
120103
version_tuple = _version_as_tuple(version)
121104
if scm_version is not None:
122-
# Wrap ScmVersion to provide formatted node for templates
123-
template_scm_version = _TemplateScmVersion(scm_version)
124105
content = final_template.format(
125106
version=version,
126107
version_tuple=version_tuple,
127-
scm_version=template_scm_version,
108+
scm_version=scm_version,
128109
)
129110
else:
130111
content = final_template.format(version=version, version_tuple=version_tuple)

src/setuptools_scm/version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def exact(self) -> bool:
159159
"""returns true checked out exactly on a tag and no local changes apply"""
160160
return self.distance == 0 and not self.dirty
161161

162+
@property
163+
def short_node(self) -> str | None:
164+
"""Return the node formatted for output."""
165+
return _format_node_for_output(self.node)
166+
162167
def __repr__(self) -> str:
163168
return (
164169
f"<ScmVersion {self.tag} dist={self.distance} "

testing/test_basic_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
template = """\
2424
__version__ = version = {version!r}
2525
__version_tuple__ = version_tuple = {version_tuple!r}
26-
__sha__ = {scm_version.node!r}
26+
__sha__ = {scm_version.short_node!r}
2727
"""
2828

2929

testing/test_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_pretend_metadata_with_version(
216216
major = {version_tuple[0]}
217217
minor = {version_tuple[1]}
218218
patch = {version_tuple[2]}
219-
commit_hash = '{scm_version.node}'
219+
commit_hash = '{scm_version.short_node}'
220220
num_commit = {scm_version.distance}
221221
""" # noqa: RUF027
222222
# Use write_to with template to create version file
@@ -294,7 +294,7 @@ def test_pretend_metadata_with_scm_version(
294294
# This is a template string, not an f-string - used by setuptools-scm templating
295295
version_file_content = """
296296
version = '{version}'
297-
commit_hash = '{scm_version.node}'
297+
commit_hash = '{scm_version.short_node}'
298298
num_commit = {scm_version.distance}
299299
""" # noqa: RUF027
300300
version = wd.get_version(

0 commit comments

Comments
 (0)