Coverage for lintro / enums / install_context.py: 100%
31 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Installation context and CI system enums for lintro.
3Identifies how lintro itself was installed and which CI environment
4it is running in.
5"""
7from __future__ import annotations
9import os
10from enum import StrEnum, auto
13class InstallContext(StrEnum):
14 """How lintro itself was installed."""
16 HOMEBREW_FULL = auto()
17 HOMEBREW_BIN = auto()
18 PIP = auto()
19 DOCKER = auto()
20 DEVELOPMENT = auto()
23class PackageManager(StrEnum):
24 """Known package managers that can install lintro's external tools."""
26 BREW = auto()
27 BUN = auto()
28 CARGO = auto()
29 NPM = auto()
30 PIP = auto()
31 RUSTUP = auto()
32 UV = auto()
35class CISystem(StrEnum):
36 """Known CI/CD systems detected via environment variables."""
38 GITHUB_ACTIONS = "GitHub Actions"
39 GITLAB_CI = "GitLab CI"
40 CIRCLECI = "CircleCI"
41 JENKINS = "Jenkins"
42 BUILDKITE = "Buildkite"
43 AZURE_PIPELINES = "Azure Pipelines"
45 @classmethod
46 def detect(cls) -> CISystem | None:
47 """Detect the current CI system from environment variables.
49 Returns:
50 The matching CISystem member, or None if not in CI.
51 """
52 for env_var, system in _CI_ENV_MAP.items():
53 if os.environ.get(env_var):
54 return system
55 return None
58# Mapping from env var to CISystem — kept outside the class to avoid
59# StrEnum treating it as a member.
60_CI_ENV_MAP: dict[str, CISystem] = {
61 "GITHUB_ACTIONS": CISystem.GITHUB_ACTIONS,
62 "GITLAB_CI": CISystem.GITLAB_CI,
63 "CIRCLECI": CISystem.CIRCLECI,
64 "JENKINS_URL": CISystem.JENKINS,
65 "BUILDKITE": CISystem.BUILDKITE,
66 "TF_BUILD": CISystem.AZURE_PIPELINES,
67}