The lib.version module carries no documentation: the Syntax, Component and Boundary types, the Version and Dependency classes and their public methods are bare, and the compatibility tiers the next_* stepping methods implement are not documented anywhere. Add docstrings: a line each for the base.py types, the compatibility tier table in the Version class, and a short description for every public method, with the three next_* methods citing the tier each one steps to. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from enum import Enum, Flag, auto
|
|
from typing import TYPE_CHECKING, NamedTuple, TypeAlias
|
|
|
|
if TYPE_CHECKING:
|
|
from .Version import Version
|
|
|
|
class Syntax(Enum): # export
|
|
"""Syntaxes for rendered version constraints"""
|
|
|
|
DEBIAN = auto()
|
|
SEM_VER = auto()
|
|
NAMES_ONLY = auto()
|
|
|
|
class Component(Flag): # export
|
|
"""Version components that parts_str() can extract"""
|
|
|
|
ID = auto()
|
|
MAJOR = auto()
|
|
MINOR = auto()
|
|
MICRO = auto()
|
|
REVISION = auto()
|
|
CORE = MAJOR | MINOR | MICRO
|
|
|
|
class Boundary(NamedTuple): # export
|
|
"""A comparison operator and the Version it bounds"""
|
|
|
|
op: str
|
|
version: Version
|
|
|
|
"""Syntax-aware formatted version comparion operator"""
|
|
def format_op(self, syntax: Syntax) -> str:
|
|
if syntax is Syntax.DEBIAN:
|
|
match self.op:
|
|
case '<':
|
|
return '<<'
|
|
case '>':
|
|
return '>>'
|
|
case _:
|
|
return self.op
|
|
return self.op
|
|
|
|
Lookup: TypeAlias = Callable[[str], str] # export
|