Spaces:
Sleeping
Sleeping
Download server/config.py from brianbellx/codehygiene: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/brianbellx/codehygiene/resolve/main/server/config.py
- Command line
-
hf download hf://spaces/brianbellx/codehygiene/server/config.py
-
curl -L -o config.py https://huggingface.co/spaces/brianbellx/codehygiene/resolve/main/server/config.py
2.57 kB
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| import os | |
| from pathlib import Path | |
| SPACE_DIR = Path(__file__).resolve().parents[1] | |
| REPO_ROOT = next( | |
| (p for p in SPACE_DIR.parents if (p / "compile.py").is_file()), | |
| SPACE_DIR.parent, | |
| ) | |
| def _env_float(env: dict[str, str], name: str, default: float) -> float: | |
| raw = env.get(name, "").strip() | |
| return float(raw) if raw else default | |
| def _env_flag(env: dict[str, str], name: str, default: bool) -> bool: | |
| raw = env.get(name, "").strip().lower() | |
| if not raw: | |
| return default | |
| return raw in ("1", "true", "yes", "on") | |
| def _env_text(env: dict[str, str], name: str) -> str: | |
| return env.get(name, "").strip() | |
| def _first_existing(*candidates: Path) -> Path | None: | |
| return next((path for path in candidates if path.is_file()), None) | |
| class Settings: | |
| presets_path: Path | None = None | |
| web_dist: Path = SPACE_DIR / "web" / "dist" | |
| stats_path: Path = Path("/tmp/codehygiene_stats.json") | |
| stats_dataset_repo: str = "" | |
| hf_token: str = field(default="", repr=False) | |
| stats_sync_seconds: float = 300.0 | |
| github_token: str = field(default="", repr=False) | |
| leaderboard_path: Path = Path("/tmp/codehygiene_leaderboard.json") | |
| leaderboard_seed: bool = True | |
| leaderboard_seed_pause: float = 20.0 | |
| def load_settings(env: dict[str, str] | None = None) -> Settings: | |
| env = dict(os.environ if env is None else env) | |
| presets_env = _env_text(env, "PRESETS_PATH") | |
| presets_path = _first_existing( | |
| *([Path(presets_env)] if presets_env else []), | |
| SPACE_DIR / "web" / "vendor" / "presets.json", | |
| SPACE_DIR / "presets.json", | |
| REPO_ROOT / "docs" / "presets.json", | |
| ) | |
| defaults = Settings() | |
| return Settings( | |
| presets_path=presets_path, | |
| web_dist=Path(_env_text(env, "WEB_DIST") or defaults.web_dist), | |
| stats_path=Path(_env_text(env, "STATS_PATH") or defaults.stats_path), | |
| stats_dataset_repo=_env_text(env, "HF_STATS_DATASET_REPO"), | |
| hf_token=_env_text(env, "HF_TOKEN"), | |
| stats_sync_seconds=_env_float(env, "STATS_SYNC_SECONDS", defaults.stats_sync_seconds), | |
| github_token=_env_text(env, "GITHUB_TOKEN"), | |
| leaderboard_path=Path(_env_text(env, "LEADERBOARD_PATH") or defaults.leaderboard_path), | |
| leaderboard_seed=_env_flag(env, "LEADERBOARD_SEED", defaults.leaderboard_seed), | |
| leaderboard_seed_pause=_env_float( | |
| env, "LEADERBOARD_SEED_PAUSE", defaults.leaderboard_seed_pause | |
| ), | |
| ) | |