Skip to content

Commit d837167

Browse files
Merge pull request #1154 from JulianFP/git_hash
Add commit_id to dump_file template
2 parents 5f517fa + 9217df2 commit d837167

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/setuptools_scm/_integration/dump_version.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,30 @@
1616
# file generated by setuptools-scm
1717
# don't change, don't track in version control
1818
19-
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
19+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple", "__commit_id__", "commit_id"]
2020
2121
TYPE_CHECKING = False
2222
if TYPE_CHECKING:
2323
from typing import Tuple
2424
from typing import Union
2525
2626
VERSION_TUPLE = Tuple[Union[int, str], ...]
27+
COMMIT_ID = Union[str, None]
2728
else:
2829
VERSION_TUPLE = object
30+
COMMIT_ID = object
2931
3032
version: str
3133
__version__: str
3234
__version_tuple__: VERSION_TUPLE
3335
version_tuple: VERSION_TUPLE
36+
commit_id: COMMIT_ID
37+
__commit_id__: COMMIT_ID
3438
3539
__version__ = version = {version!r}
3640
__version_tuple__ = version_tuple = {version_tuple!r}
41+
42+
__commit_id__ = commit_id = {scm_version.node!r}
3743
""",
3844
".txt": "{version}",
3945
}

testing/test_basic_api.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,30 @@ def read(name: str) -> str:
184184
scm_version = meta("1.0", distance=42, config=c)
185185
dump_version(tmp_path, version, "first.py", scm_version=scm_version)
186186
lines = read("first.py").splitlines()
187-
assert lines[-2:] == [
187+
assert lines[-4:] == [
188188
"__version__ = version = '1.0.dev42'",
189189
"__version_tuple__ = version_tuple = (1, 0, 'dev42')",
190+
"",
191+
"__commit_id__ = commit_id = None",
192+
]
193+
194+
version = "1.0.1"
195+
scm_version = meta("1.0.1", node="g4ac9d2c", config=c)
196+
dump_version(tmp_path, version, "second.py", scm_version=scm_version)
197+
lines = read("second.py").splitlines()
198+
assert lines[-4:] == [
199+
"__version__ = version = '1.0.1'",
200+
"__version_tuple__ = version_tuple = (1, 0, 1)",
201+
"",
202+
"__commit_id__ = commit_id = 'g4ac9d2c'",
190203
]
191204

192205
version = "1.0.1+g4ac9d2c"
193206
scm_version = meta("1.0.1", node="g4ac9d2c", config=c)
194207
dump_version(
195-
tmp_path, version, "second.py", scm_version=scm_version, template=template
208+
tmp_path, version, "third.py", scm_version=scm_version, template=template
196209
)
197-
lines = read("second.py").splitlines()
210+
lines = read("third.py").splitlines()
198211
assert "__version__ = version = '1.0.1+g4ac9d2c'" in lines
199212
assert "__version_tuple__ = version_tuple = (1, 0, 1, 'g4ac9d2c')" in lines
200213
assert "__sha__ = 'g4ac9d2c'" in lines
@@ -204,9 +217,9 @@ def read(name: str) -> str:
204217
"1.2.3", node="gb366d8b", distance=18, node_date=date(2021, 4, 15), config=c
205218
)
206219
dump_version(
207-
tmp_path, version, "third.py", scm_version=scm_version, template=template
220+
tmp_path, version, "fourth.py", scm_version=scm_version, template=template
208221
)
209-
lines = read("third.py").splitlines()
222+
lines = read("fourth.py").splitlines()
210223
assert "__version__ = version = '1.2.3.dev18+gb366d8b.d20210415'" in lines
211224
assert (
212225
"__version_tuple__ = version_tuple = (1, 2, 3, 'dev18', 'gb366d8b.d20210415')"
@@ -216,7 +229,7 @@ def read(name: str) -> str:
216229

217230
import ast
218231

219-
ast.parse(read("third.py"))
232+
ast.parse(read("fourth.py"))
220233

221234

222235
def test_parse_plain_fails(recwarn: pytest.WarningsRecorder) -> None:

0 commit comments

Comments
 (0)