asyncutils.version¶
asyncutils. Inspired by torch.torch_version, but with quite some differences.asyncutils uses a subset of SemVer.Classes¶
str(object='') -> str |
Functions¶
|
Registers normalizers for |
Return the normalizer to be used for the object or type. |
|
|
|
|
Same as |
Registers a custom normalizer for the object or type; returns success, with failure resulting from a normalizer having already been registered. |
|
Unregister the normalizer for the object or type and return it if any. |
Module Contents¶
- class asyncutils.version.VersionDelta[source]¶
Bases:
NamedTupleA named tuple-like class representing the difference between versions.Not actually created bycollections.namedtuple(), but implements its methods.Can be taken by the + or - operators.- __neg__() Self[source]¶
Return the negative of the delta. Additions and subtractions taking the return value correspond to subtractions and additions taking the original delta respectively.
- __replace__(*, major: int = ..., minor: int = ..., patch: int = ...) Self¶
Alias for
_replace().
- __trunc__() int¶
The same as
__floor__().
- class asyncutils.version.VersionInfo[source]¶
Bases:
strstr(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.
Initialize self. See help(type(self)) for accurate signature.
- __add__(n: int, /) Self[source]¶
- __add__(delta: VersionDelta, /) Self
Return this version incremented by
npatches or the deltadelta.
- __format__(format_spec: str, /) str[source]¶
Format specification and corresponding return value: (using version 123.4.0 as example):
x, hex:
'0x7b0400'o, oct:
'0o36602000'b, bin:
'0b11110110000010000000000'd, dec:
'8061952'0, major, maj:
'123'1, minor, min:
'4'2, patch:
'0's, short:
'123.4'l, long:
'asyncutils version 123.4.0'a, ascii:
'{\x04\x00'c, chars:
'{\x04\x00't, tuple:
'(123, 4, 0)'h, hash:
'116380397'n, majmin: ``’123.4’`
- __getitem__(idx: Literal[0, 1, 2], /) int[source]¶
- __getitem__(idx: asyncutils._internal.types.ValidSlice, /) tuple[int, Ellipsis]
Depending on the value of
idx, corresponds to the following properties:Slicing works like the version object is a tuple of these three items, which is also accessible as
parts.
- __hash__() int[source]¶
- A perfect hash function for versions! May produce larger integers than
__int__()in some cases, and may also produce negative integers.Of course, sincehash()returns the output of__hash__()modulo0x1FFFFFFFFFFFFFFF(largest Mersenne prime within 64 bits), thereasonable limit for versions that can be hashed and unhashed losslessly lies aroundVersionInfo(46340, 41707, 2147483645).
- __int__() int[source]¶
Assuming
minorandpatchare less than 256, pack the parts into an integer, which can be larger than 24 bits to fit the major version.OverflowErroris raised if not possible.
- __iter__() collections.abc.Iterator[int][source]¶
- __radd__(n: int, /) Self¶
- __radd__(delta: VersionDelta, /) Self
Return this version incremented by
npatches or the deltadelta.
- __round__(ndigits: int, /) NoReturn[source]¶
- __round__(ndigits: Literal[1, 2, 3] | None = ..., /) Self
Support for rounding.
- __setattr__(name: str, value: object, /) NoReturn[source]¶
Disallow modifying attributes of the object.
- __sub__(n: int, /) Self[source]¶
- __sub__(delta: VersionDelta, /) Self
- __sub__(other: Self, /) VersionDelta
Return this version decremented by
npatches or the deltadelta, or the delta betweenselfandother.
- __trunc__() int¶
The same as
__floor__().
- _replace(major: int = ..., minor: int = ..., patch: int = ...) Self¶
Implemented to satisfy the named tuple interface.
- assert_valid() None[source]¶
Signify an error if the user messed something up in this object, likely intentionally.
- change_sep(sep: str) str[source]¶
This version as a string with the specified separator instead of a dot between parts.
- compatible(other: Self, /, majtol: int | None = ..., mintol: int | None = ...) bool[source]¶
Whether this version is compatible with the other, given the major and minor tolerances.
- classmethod from_rep(rep: str) Self[source]¶
Parse the string representation of a version to get the version back.
- classmethod get_current_version() Self[source]¶
Return the current version number of
asyncutils; equivalent toasyncutils.__version__.
- is_current_version() bool[source]¶
Whether this version is the same as the current version of
asyncutils.
- replace_parts(*, major: int = ..., minor: int = ..., patch: int = ...) Self[source]¶
Another instance of this class with the specified parts.
- shelve(path: asyncutils._internal.types.Openable, /, key: int = ...) None[source]¶
Store this version into the specified
path, non-cryptographically transforming the bytes withkey, which can be any integer.
- to_complex() complex[source]¶
Loses the patch version. Since this class is a
strsubclass, an implementation of__complex__()will not be recognized.
- classmethod unshelve(path: asyncutils._internal.types.Openable, /, key: int = ...) Self[source]¶
Recover a stored version from
path. A wrong key would usually raise an error, and even if it doesn’t, the version would be wrong.
- asyncutils.version.autogenerate_normalizers() bool[source]¶
Registers normalizers for
decimal.Decimalandfractions.Fraction. Return whether both normalizers were successfully registered, including re-registration of the same normalizer.
- asyncutils.version.dispatch_normalizer[T](o: type[T], /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None[source]¶
- asyncutils.version.dispatch_normalizer(o: T, /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None
Return the normalizer to be used for the object or type.
- asyncutils.version.normalize(o: object, /) tuple[int, int, int][source]¶
- Return a
tupleof three integers(major, minor, patch)from the information provided by the object as extracted by registerednormalizers.A normalizer can returnNonefor unnormalizable objects, in which case the comparison operators against instances ofVersionInfowill delegate to that object.If there is fault in the normalizer (it raises an exception or returns a non-iterable), the normalizer is removed and the error propagated.Note
Normalization logic is hardcoded for exact instances of
str,complex,int, andfloat. This takes precedence over any registered normalizers, but those can still be accessed withdispatch_normalizer().Note
For iterables, the default behaviour is to take the first three items and pad zeros behind if necessary.
- asyncutils.version.normalize_allow_unimplemented(o: object, /) tuple[int, int, int] | None[source]¶
Same as
normalize(), but returnsNoneif a normalizer is not found.
- asyncutils.version.register_normalizer[T](o: type[T], f: collections.abc.Callable[[T], collections.abc.Iterable[int]], /) bool[source]¶
- asyncutils.version.register_normalizer(o: T, f: collections.abc.Callable[[T], collections.abc.Iterable[int]], /) bool
Registers a custom normalizer for the object or type; returns success, with failure resulting from a normalizer having already been registered.
- asyncutils.version.unregister_normalizer[T](o: type[T], /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None[source]¶
- asyncutils.version.unregister_normalizer(o: T, /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None
Unregister the normalizer for the object or type and return it if any.