bundlewrap/libs/version.py
CroneKorkN 730625e36c
libs/hooks/bin: add one-line module docstrings and # purpose: headers
every libs/*.py and hooks/*.py now starts with a one-line module
docstring; every bin/* script starts with a `# purpose:` header.
discovery-by-`ls`-and-read instead of by index.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 15:36:19 +02:00

30 lines
838 B
Python

"""version: comparable Version class for dotted-int version strings."""
from functools import total_ordering
@total_ordering
class Version():
def __init__(self, string):
self._tuple = self.tupelize(string)
def __lt__(self, other):
return self._tuple < self.tupelize(other)
def __eq__(self, other):
return self._tuple == self.tupelize(other)
def __repr__(self):
return f'{type(self).__name__}({repr(self._tuple)})'
def __str__(self):
return '.'.join(str(i) for i in self._tuple)
@staticmethod
def tupelize(version):
if isinstance(version, (int, float, str, Version)):
return tuple(int(i) for i in str(version).split('.'))
elif type(version) == tuple:
return version
else:
raise TypeError(type(version))