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: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog


## v9.0.1

### Fixed

- fix #1180: ensure version dumping works when no scm_version is given (problems in downstreams)


## v9.0.0

### Breaking
Expand Down
31 changes: 23 additions & 8 deletions src/setuptools_scm/_integration/dump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,34 @@ def _validate_template(target: Path, template: str | None) -> str:
return template


class DummyScmVersion:
@property
def short_node(self) -> str | None:
return None


def write_version_to_path(
target: Path, template: str | None, version: str, scm_version: ScmVersion | None
target: Path,
template: str | None,
version: str,
scm_version: ScmVersion | None = None,
) -> None:
final_template = _validate_template(target, template)
log.debug("dump %s into %s", version, target)
version_tuple = _version_as_tuple(version)
if scm_version is not None:
content = final_template.format(
version=version,
version_tuple=version_tuple,
scm_version=scm_version,
if scm_version is None:
warnings.warn(
"write_version_to_path called without scm_version parameter. "
"This will be required in a future version. "
"Pass scm_version=None explicitly to suppress this warning.",
DeprecationWarning,
stacklevel=2,
)
else:
content = final_template.format(version=version, version_tuple=version_tuple)

content = final_template.format(
version=version,
version_tuple=version_tuple,
scm_version=scm_version or DummyScmVersion(),
)

target.write_text(content, encoding="utf-8")
58 changes: 58 additions & 0 deletions testing/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,61 @@ def test_has_command_logs_stderr(caplog: pytest.LogCaptureFixture) -> None:
def test_tag_to_version(tag: str, expected_version: str) -> None:
version = str(tag_to_version(tag, c))
assert version == expected_version


def test_write_version_to_path_deprecation_warning_none(tmp_path: Path) -> None:
"""Test that write_version_to_path warns when scm_version=None is passed."""
from setuptools_scm._integration.dump_version import write_version_to_path

target_file = tmp_path / "version.py"

# This should raise a deprecation warning when scm_version=None is explicitly passed
with pytest.warns(
DeprecationWarning, match="write_version_to_path called without scm_version"
):
write_version_to_path(
target=target_file,
template=None, # Use default template
version="1.2.3",
scm_version=None, # Explicitly passing None should warn
)

# Verify the file was created and contains the expected content
assert target_file.exists()
content = target_file.read_text(encoding="utf-8")

# Check that the version is correctly formatted
assert "__version__ = version = '1.2.3'" in content
assert "__version_tuple__ = version_tuple = (1, 2, 3)" in content

# Check that commit_id is set to None when scm_version is None
assert "__commit_id__ = commit_id = None" in content


def test_write_version_to_path_deprecation_warning_missing(tmp_path: Path) -> None:
"""Test that write_version_to_path warns when scm_version parameter is not provided."""
from setuptools_scm._integration.dump_version import write_version_to_path

target_file = tmp_path / "version.py"

# This should raise a deprecation warning when scm_version is not provided
with pytest.warns(
DeprecationWarning, match="write_version_to_path called without scm_version"
):
write_version_to_path(
target=target_file,
template=None, # Use default template
version="1.2.3",
# scm_version not provided - should warn
)

# Verify the file was created and contains the expected content
assert target_file.exists()
content = target_file.read_text(encoding="utf-8")

# Check that the version is correctly formatted
assert "__version__ = version = '1.2.3'" in content
assert "__version_tuple__ = version_tuple = (1, 2, 3)" in content

# Check that commit_id is set to None when scm_version is None
assert "__commit_id__ = commit_id = None" in content
Loading