Skip to content

Commit

Permalink
Add version property for backward-compatibility with distutils.version
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Oct 24, 2023
1 parent a4d8b0e commit e335bad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


## Unreleased

- Add `version` property for backward-compatibility with `distutils.version`

## 2023-10-14 v0.1.0
- First release
12 changes: 12 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ def test_version():
< Version("1!1.0b1.dev456")
< Version("1!1.2.rev33+123456")
)


def test_distutils_backward_compatibility():
"""
The `LooseVersion` and `StrictVersion` classes of `distutils.version`
had a `version` property, mirroring the `release` property of
`packaging.version`.
This test verifies it is in place.
"""
version = Version("1.0.dev456")
assert version.version == (1, 0)
7 changes: 7 additions & 0 deletions verlib2/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ def release(self) -> Tuple[int, ...]:
"""
return self._version.release

@property
def version(self) -> Tuple[int, ...]:
"""
Return version tuple for backward-compatibility with `distutils.version`.
"""
return self.release

@property
def pre(self) -> Optional[Tuple[str, int]]:
"""The pre-release segment of the version.
Expand Down

0 comments on commit e335bad

Please sign in to comment.