-
Notifications
You must be signed in to change notification settings - Fork 110
Trying to get a compliant, typed version parser/comparator #348
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
Conversation
Hi @tony
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. |
Thank you @neutrinoceros! @layday's mixin for 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" |
ec9aed4
to
42bc294
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
bb68b70
to
d6ab13b
Compare
Companion: tmux-python/tmuxp#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
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 versionstmux versions
Version
Assure thatlibtmux.__version__
/tmuxp.__version__
supports git refs /local
match groups