jw-pkg/src/python/jw/pkg/lib/version/base.py
Jan Lindemann 01a0c40647
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 2m22s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 2m16s
CI / Packaging test (pull_request) Failing after 0s
lib.version: Add API docstrings
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>
2026-09-09 15:22:19 +02:00

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