Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1119: consider all version parts for version tuple #1120

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

## v8.2.1

### Fixed

- fix #1119: also include pre/post release details in version_tuple


## v8.2.0

### Added
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ force-single-line = true
from-first = false
lines-between-types = 1
order-by-type = true

[tool.repo-review]
ignore = ["PP305", "GH103", "GH212", "MY100", "PC111", "PC160", "PC170", "PC180", "PC901"]

Expand Down
9 changes: 9 additions & 0 deletions src/setuptools_scm/_version_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ def _version_as_tuple(version_str: str) -> tuple[int | str, ...]:
return (version_str,)
else:
version_fields: tuple[int | str, ...] = parsed_version.release
if parsed_version.epoch:
version_fields = (f"{parsed_version.epoch}!", *version_fields)
if parsed_version.pre is not None:
version_fields += (f"{parsed_version.pre[0]}{parsed_version.pre[1]}",)

if parsed_version.post is not None:
version_fields += (f"post{parsed_version.post}",)

if parsed_version.dev is not None:
version_fields += (f"dev{parsed_version.dev}",)

if parsed_version.local is not None:
version_fields += (parsed_version.local,)
return version_fields
Expand Down
16 changes: 16 additions & 0 deletions testing/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from importlib.metadata import EntryPoint
from importlib.metadata import distribution
from pathlib import Path
from typing import Sequence

import pytest

Expand Down Expand Up @@ -130,3 +131,18 @@ def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> No
match=r".*VERSION.py' .* .*subdir.*",
):
write_version_files(replace(c, root=subdir), "1.0", v)


@pytest.mark.parametrize(
("input", "expected"),
[
("1.0", (1, 0)),
("1.0a2", (1, 0, "a2")),
("1.0.b2dev1", (1, 0, "b2", "dev1")),
("1.0.dev1", (1, 0, "dev1")),
],
)
def test_version_as_tuple(input: str, expected: Sequence[int | str]) -> None:
from setuptools_scm._version_cls import _version_as_tuple

assert _version_as_tuple(input) == expected
Loading