Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/setuptools_scm/_integration/dump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@
# file generated by setuptools-scm
# don't change, don't track in version control

__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple", "__commit_id__", "commit_id"]

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple
from typing import Union

VERSION_TUPLE = Tuple[Union[int, str], ...]
COMMIT_ID = Union[str, None]
else:
VERSION_TUPLE = object
COMMIT_ID = object

version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE
commit_id: COMMIT_ID
__commit_id__: COMMIT_ID

__version__ = version = {version!r}
__version_tuple__ = version_tuple = {version_tuple!r}

__commit_id__ = commit_id = {scm_version.node!r}
""",
".txt": "{version}",
}
Expand Down
25 changes: 19 additions & 6 deletions testing/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,30 @@ def read(name: str) -> str:
scm_version = meta("1.0", distance=42, config=c)
dump_version(tmp_path, version, "first.py", scm_version=scm_version)
lines = read("first.py").splitlines()
assert lines[-2:] == [
assert lines[-4:] == [
"__version__ = version = '1.0.dev42'",
"__version_tuple__ = version_tuple = (1, 0, 'dev42')",
"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should get a different test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I added a second test that doesn't use the test template but where the commit id is not None

"__commit_id__ = commit_id = None",
]

version = "1.0.1"
scm_version = meta("1.0.1", node="g4ac9d2c", config=c)
dump_version(tmp_path, version, "second.py", scm_version=scm_version)
lines = read("second.py").splitlines()
assert lines[-4:] == [
"__version__ = version = '1.0.1'",
"__version_tuple__ = version_tuple = (1, 0, 1)",
"",
"__commit_id__ = commit_id = 'g4ac9d2c'",
]

version = "1.0.1+g4ac9d2c"
scm_version = meta("1.0.1", node="g4ac9d2c", config=c)
dump_version(
tmp_path, version, "second.py", scm_version=scm_version, template=template
tmp_path, version, "third.py", scm_version=scm_version, template=template
)
lines = read("second.py").splitlines()
lines = read("third.py").splitlines()
assert "__version__ = version = '1.0.1+g4ac9d2c'" in lines
assert "__version_tuple__ = version_tuple = (1, 0, 1, 'g4ac9d2c')" in lines
assert "__sha__ = 'g4ac9d2c'" in lines
Expand All @@ -204,9 +217,9 @@ def read(name: str) -> str:
"1.2.3", node="gb366d8b", distance=18, node_date=date(2021, 4, 15), config=c
)
dump_version(
tmp_path, version, "third.py", scm_version=scm_version, template=template
tmp_path, version, "fourth.py", scm_version=scm_version, template=template
)
lines = read("third.py").splitlines()
lines = read("fourth.py").splitlines()
assert "__version__ = version = '1.2.3.dev18+gb366d8b.d20210415'" in lines
assert (
"__version_tuple__ = version_tuple = (1, 2, 3, 'dev18', 'gb366d8b.d20210415')"
Expand All @@ -216,7 +229,7 @@ def read(name: str) -> str:

import ast

ast.parse(read("third.py"))
ast.parse(read("fourth.py"))


def test_parse_plain_fails(recwarn: pytest.WarningsRecorder) -> None:
Expand Down
Loading