Skip to content

Commit

Permalink
rename version to version_str in dump_version
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed May 25, 2023
1 parent ebbc395 commit 2fa9977
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
".py": """\
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = {version!r}
__version__ = version = {version_str!r}
__version_tuple__ = version_tuple = {version_tuple!r}
""",
".txt": "{version}",
Expand All @@ -43,27 +43,31 @@

def dump_version(
root: _t.PathT,
version: str,
version_str: str,
write_to: _t.PathT,
template: str | None = None,
) -> None:
assert isinstance(version, str)
assert isinstance(version_str, str)
target = os.path.normpath(os.path.join(root, write_to))
ext = os.path.splitext(target)[1]
template = template or TEMPLATES.get(ext)
from ._log import log

log.debug("dump %s into %s", version, write_to)
log.debug("dump %s into %s", version_str, write_to)
if template is None:
raise ValueError(
"bad file format: '{}' (of {}) \nonly *.txt and *.py are supported".format(
os.path.splitext(target)[1], target
)
)
version_tuple = _version_as_tuple(version)
version_tuple = _version_as_tuple(version_str)

with open(target, "w") as fp:
fp.write(template.format(version=version, version_tuple=version_tuple))
fp.write(template.format(
version=version_str, # for backward compatibility with previous versions
version_str=version_str,
version_tuple=version_tuple
))


def _do_parse(config: Configuration) -> _t.SCMVERSION | None:
Expand Down Expand Up @@ -155,20 +159,20 @@ def _get_version(config: Configuration) -> str | None:
parsed_version = _do_parse(config)
if parsed_version is None:
return None
version_string = _format_version(
version_str = _format_version(
parsed_version,
version_scheme=config.version_scheme,
local_scheme=config.local_scheme,
)
if config.write_to is not None:
dump_version(
root=config.root,
version=version_string,
version_str=version_str,
write_to=config.write_to,
template=config.write_to_template,
)

return version_string
return version_str


# Public API
Expand Down

0 comments on commit 2fa9977

Please sign in to comment.