Skip to content

Commit

Permalink
Handle nonzero version epoch in StandardScheme (fix #1032) (#1036)
Browse files Browse the repository at this point in the history
* Handle nonzero version epoch in StandardScheme (fix #1032)

* Fix wrong name type in pytest.mark.parametrize

* add release note

---------

Co-authored-by: Ofek Lev <[email protected]>
  • Loading branch information
object-Object and ofek authored Nov 26, 2023
1 parent 86393f9 commit 63d676b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/src/hatchling/version/scheme/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def update(
def reset_version_parts(version: Version, **kwargs: Any) -> None:
# https://github.com/pypa/packaging/blob/20.9/packaging/version.py#L301-L310
internal_version = version._version # noqa: SLF001
parts: dict[str, Any] = {'epoch': 0}
ordered_part_names = ('release', 'pre', 'post', 'dev', 'local')
parts: dict[str, Any] = {}
ordered_part_names = ('epoch', 'release', 'pre', 'post', 'dev', 'local')

reset = False
for part_name in ordered_part_names:
Expand Down
1 change: 1 addition & 0 deletions docs/history/hatchling.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
***Fixed:***

- Fix parsing dependencies for environments when warnings are emitted
- Properly handle non-zero version epoch for the `standard` version scheme

## [1.18.0](https://github.com/pypa/hatch/releases/tag/hatchling-v1.18.0) - 2023-06-12 ## {: #hatchling-v1.18.0 }

Expand Down
18 changes: 18 additions & 0 deletions tests/backend/version/scheme/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,21 @@ def test_correct(self, isolation, operations, expected):
scheme = StandardScheme(str(isolation), {})

assert scheme.update(operations, '0.0.1', {}) == expected


class TestWithEpoch:
@pytest.mark.parametrize(
('operations', 'expected'),
[
('patch,dev,release', '1!0.0.2'),
('fix,rc', '1!0.0.2rc0'),
('minor,dev', '1!0.1.0.dev0'),
('minor,preview', '1!0.1.0rc0'),
('major,beta', '1!1.0.0b0'),
('major,major,major', '1!3.0.0'),
],
)
def test_correct(self, isolation, operations, expected):
scheme = StandardScheme(str(isolation), {})

assert scheme.update(operations, '1!0.0.1', {}) == expected

0 comments on commit 63d676b

Please sign in to comment.