Skip to content

just_dna_format.identity

just_dna_format.identity

Identity and versioning (SPEC §6).

Identity is namespace/name. name keeps the DSL rule ^[a-z][a-z0-9_]*$; namespace is an owned account/org slug (lowercase alphanumeric with hyphens, e.g. just-dna-seq). Versions are SemVer MAJOR.MINOR.PATCH for public ordering; the legacy vN directory convention maps v1 -> 1.0.0, v2 -> 2.0.0.

Version dataclass

Version(major: int, minor: int, patch: int)

A parsed SemVer MAJOR.MINOR.PATCH, comparable and stringifiable.

is_valid_name

is_valid_name(name: str) -> bool

Whether name matches the module name rule ^[a-z][a-z0-9_]*$.

Source code in schema/src/just_dna_format/identity.py
def is_valid_name(name: str) -> bool:
    """Whether `name` matches the module name rule `^[a-z][a-z0-9_]*$`."""
    return bool(NAME_PATTERN.match(name))

validate_name

validate_name(name: str) -> str

Return name if valid, else raise ValueError.

Source code in schema/src/just_dna_format/identity.py
def validate_name(name: str) -> str:
    """Return `name` if valid, else raise `ValueError`."""
    if not is_valid_name(name):
        raise ValueError(f"module name must be lowercase alphanumeric with underscores, got: {name!r}")
    return name

is_valid_namespace

is_valid_namespace(namespace: str) -> bool

Whether namespace is a valid account/org slug (lowercase alnum + hyphens).

Source code in schema/src/just_dna_format/identity.py
def is_valid_namespace(namespace: str) -> bool:
    """Whether `namespace` is a valid account/org slug (lowercase alnum + hyphens)."""
    return bool(NAMESPACE_PATTERN.match(namespace))

validate_namespace

validate_namespace(namespace: str) -> str

Return namespace if valid, else raise ValueError.

Source code in schema/src/just_dna_format/identity.py
def validate_namespace(namespace: str) -> str:
    """Return `namespace` if valid, else raise `ValueError`."""
    if not is_valid_namespace(namespace):
        raise ValueError(f"namespace must be lowercase alphanumeric with hyphens, got: {namespace!r}")
    return namespace

canonical_id

canonical_id(
    namespace: str, name: str, version: str
) -> str

Build the canonical id namespace/name@version.

Source code in schema/src/just_dna_format/identity.py
def canonical_id(namespace: str, name: str, version: str) -> str:
    """Build the canonical id `namespace/name@version`."""
    return f"{namespace}/{name}@{version}"

parse_version

parse_version(version: str) -> Version

Parse a strict MAJOR.MINOR.PATCH string into a Version, else raise ValueError.

Source code in schema/src/just_dna_format/identity.py
def parse_version(version: str) -> Version:
    """Parse a strict `MAJOR.MINOR.PATCH` string into a `Version`, else raise `ValueError`."""
    match = _VERSION_PATTERN.match(version)
    if match is None:
        raise ValueError(f"version must be MAJOR.MINOR.PATCH, got: {version!r}")
    return Version(int(match.group(1)), int(match.group(2)), int(match.group(3)))

is_valid_version

is_valid_version(version: str) -> bool

Whether version is a strict MAJOR.MINOR.PATCH string.

Source code in schema/src/just_dna_format/identity.py
def is_valid_version(version: str) -> bool:
    """Whether `version` is a strict `MAJOR.MINOR.PATCH` string."""
    return bool(_VERSION_PATTERN.match(version))

version_from_legacy

version_from_legacy(legacy: str) -> str

Map a legacy integer or vN directory name to SemVer (v1/1 -> 1.0.0).

Source code in schema/src/just_dna_format/identity.py
def version_from_legacy(legacy: str) -> str:
    """Map a legacy integer or `vN` directory name to SemVer (`v1`/`1` -> `1.0.0`)."""
    match = _LEGACY_PATTERN.match(legacy)
    if match is None:
        raise ValueError(f"legacy version must be an integer or vN, got: {legacy!r}")
    return f"{int(match.group(1))}.0.0"

latest

latest(versions: list[str]) -> str

Return the highest SemVer string from a non-empty list.

Source code in schema/src/just_dna_format/identity.py
def latest(versions: list[str]) -> str:
    """Return the highest SemVer string from a non-empty list."""
    if not versions:
        raise ValueError("cannot pick latest from an empty version list")
    return str(max(parse_version(v) for v in versions))