Skip to content

env

env

Environment variables — one idiom, with backward compatibility.

The project was renamed OpenJarvis → Diapason, so the variables become DIAPASON_*. Renaming them outright would break every existing setup SILENTLY: a shell profile, a CI job or a systemd unit exporting OPENJARVIS_HOME would simply stop being read, with no error — the worst possible failure mode for a configuration contract.

So each variable is read through :func:get, which tries, in order:

  1. DIAPASON_<NAME> — the new name, always wins;
  2. the legacy name(s) — OPENJARVIS_<NAME> and/or JARVIS_<NAME>.

A legacy hit is logged once at DEBUG with the new name to migrate to, so the old spelling keeps working while telling you it is old.

Functions:

get

get(
    name: str, default: Optional[str] = None
) -> Optional[str]

Return DIAPASON_<name>, falling back to the legacy spellings.

name is the bare suffix: get("HOME") reads DIAPASON_HOME, then OPENJARVIS_HOME, then JARVIS_HOME.

Source code in src/diapason/core/env.py
def get(name: str, default: Optional[str] = None) -> Optional[str]:
    """Return ``DIAPASON_<name>``, falling back to the legacy spellings.

    ``name`` is the bare suffix: ``get("HOME")`` reads ``DIAPASON_HOME``, then
    ``OPENJARVIS_HOME``, then ``JARVIS_HOME``.
    """
    new = f"DIAPASON_{name}"
    value = os.environ.get(new)
    if value is not None:
        return value

    for legacy in _legacy_names(name):
        value = os.environ.get(legacy)
        if value is not None:
            if legacy not in _warned:
                _warned.add(legacy)
                logger.debug(
                    "%s is the old name for %s; it still works, but prefer %s",
                    legacy,
                    new,
                    new,
                )
            return value
    return default

is_set

is_set(name: str) -> bool

True when the variable is set under any accepted spelling.

Source code in src/diapason/core/env.py
def is_set(name: str) -> bool:
    """True when the variable is set under any accepted spelling."""
    return get(name) is not None

names

names(name: str) -> tuple[str, ...]

Every spelling read for name, new first — handy for diagnostics.

Source code in src/diapason/core/env.py
def names(name: str) -> tuple[str, ...]:
    """Every spelling read for ``name``, new first — handy for diagnostics."""
    return (f"DIAPASON_{name}", *_legacy_names(name))