Skip to content

Commit environment

commit_environment

Invocation-local transport for a declared commit dependency environment.

commit_environment(environment)

Bind an immutable snapshot for this invocation and always restore it.

Source code in packages/axm-git/src/axm_git/core/commit_environment.py
Python
@contextmanager
def commit_environment(environment: Mapping[str, str] | None) -> Iterator[None]:
    """Bind an immutable snapshot for this invocation and always restore it."""
    snapshot = None if environment is None else MappingProxyType(dict(environment))
    token = _ENVIRONMENT.set(snapshot)
    try:
        yield
    finally:
        _ENVIRONMENT.reset(token)

dependency_environment(candidate, declared)

Validate the explicit read runtime before staging, without preparing it.

Source code in packages/axm-git/src/axm_git/core/commit_environment.py
Python
def dependency_environment(
    candidate: Path,
    declared: Mapping[str, object] | DependencyEnvironment | None,
) -> Mapping[str, str] | None:
    """Validate the explicit read runtime before staging, without preparing it."""
    if declared is None:
        return None
    if isinstance(declared, DependencyEnvironment):
        declared = declared.to_mapping()
    if not isinstance(declared, Mapping):
        raise ValueError("dependency_environment must be a mapping")
    environment = DependencyEnvironment.from_mapping(declared)
    _check_locations(candidate, environment)
    result = dict(os.environ)
    result["PATH"] = (
        str(Path(environment.interpreter).parent) + os.pathsep + result.get("PATH", "")
    )
    result["PYTHONPATH"] = os.pathsep.join(_candidate_sources(candidate, environment))
    result["PYTHONDONTWRITEBYTECODE"] = "1"
    result["AXM_DEPENDENCY_INTERPRETER"] = environment.interpreter
    result["AXM_DEPENDENCY_PACKAGE_ROOT"] = environment.package_root
    return MappingProxyType(result)

environment_options(explicit=None)

Snapshot scoped runtime plus local Git options for one subprocess.

Without a scope, an explicit mapping is a complete subprocess environment. Within a scope, explicit options overlay it while declared Python runtime keys remain authoritative. No mapping supplied by a caller is mutated.

Source code in packages/axm-git/src/axm_git/core/commit_environment.py
Python
def environment_options(
    explicit: Mapping[str, str] | None = None,
) -> _EnvironmentOptions:
    """Snapshot scoped runtime plus local Git options for one subprocess.

    Without a scope, an explicit mapping is a complete subprocess environment.
    Within a scope, explicit options overlay it while declared Python runtime
    keys remain authoritative. No mapping supplied by a caller is mutated.
    """
    scoped = _ENVIRONMENT.get()
    if scoped is None:
        return {} if explicit is None else {"env": dict(explicit)}
    merged = dict(scoped)
    if explicit is not None:
        merged.update(explicit)
        merged.update({key: scoped[key] for key in _RUNTIME_KEYS if key in scoped})
    return {"env": merged}