Trying to get a compliant, typed version parser/comparator
Companion: https://github.com/tmux-python/tmuxp/pull/727
See also:
-
https://github.com/asottile/flake8-typing-imports/blob/923a533/flake8_typing_imports.py#L32-L42
-
https://github.com/pypa/packaging/blob/5984e3b25/packaging/version.py#L444
-
[x] String comparison's against
Version@layday's snippet
-
[ ] LegacyVersion deprecation
In
packaging,LegacyVersion(the supercessor toLooseVersion) will be deprecated, we won't be able to support2.4-openbsd(like what is seen on OpenBSD's tmux versions/home/t/work/python/libtmux/.venv/lib/python3.10/site-packages/packaging/version.py:127: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release warnings.warn( -- Docs: https://docs.pytest.org/en/stable/warnings.html -
[ ] tmux versions
To the above, consider subclassing `Version` for tmux versions to handle git builds, platform builds, etc. then keeping `Version` for supporting pypi releases -
[ ]
VersionAssure thatlibtmux.__version__/tmuxp.__version__supports git refs /localmatch groups
Hi @Tony
So in response to your question in the yt issue, I'm actually not sure my solution version_tuple fits your needs, if you want to support version schemes that used to rely on distutils.LooseVersion, my function may not work.
version_tuple is explicitly aimed only at parsing int tuples, and will truncate any trailing str to support alphas/betas
for instance
>>> version_tuple("2.13-hello")
(2, 13)
is this really what you need ?
@neutrinoceros I saw your follow up here and realize it is explicitly tuple related and I'm dabbling with keeping it as an object: #351. I've underestimated the effort required.
I suppose if it takes no time at all, you could PR the function in src/libtmux/util.py
Seems like you got a better solution from the packaging thread, I won't open a PR after all. Anyway feel free to copy my solution in case you need it still.
Seems like you got a better solution from the packaging thread, I won't open a PR after all. Anyway feel free to copy my solution in case you need it still.
Thank you @neutrinoceros! @layday's mixin for Version seems quite nice and I'm trialing it in another PR here.
In case anyone googles their way here, @layday's snippet:
from functools import total_ordering
from packaging.version import Version
@total_ordering
class _VersionCmpMixin:
def __eq__(self, other: object) -> bool:
if isinstance(other, str):
other = self.__class__(other)
return super().__eq__(other)
def __lt__(self, other: object) -> bool:
if isinstance(other, str):
other = self.__class__(other)
return super().__lt__(other)
class MyVersion(_VersionCmpMixin, Version):
pass
assert MyVersion("3") == "3.0.0"
assert MyVersion("3") != "3.0.1"
Codecov Report
Merging #348 (42bc294) into master (5166809) will decrease coverage by
0.76%. The diff coverage is88.23%.
@@ Coverage Diff @@
## master #348 +/- ##
==========================================
- Coverage 87.82% 87.05% -0.77%
==========================================
Files 15 15
Lines 1511 1530 +19
==========================================
+ Hits 1327 1332 +5
- Misses 184 198 +14
| Impacted Files | Coverage Δ | |
|---|---|---|
| libtmux/common.py | 85.13% <88.23%> (-1.80%) |
:arrow_down: |
| tests/test_common.py | 92.17% <0.00%> (-6.09%) |
:arrow_down: |
| tests/test_server.py | 98.18% <0.00%> (-1.82%) |
:arrow_down: |
| tests/test_window.py | 98.14% <0.00%> (-0.62%) |
:arrow_down: |
| libtmux/session.py | 81.32% <0.00%> (-0.23%) |
:arrow_down: |
| libtmux/window.py | 85.36% <0.00%> (+1.02%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 5166809...42bc294. Read the comment docs.