metrics_constants.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. """Metric constants for the Web backend - derived from the single source
  2. of truth in the platform core (src/afmcore/metrics.py).
  3. THIS FILE MUST NOT define its own metric lists. All definitions, aliases,
  4. labels, directions and required-metric rules live in src/afmcore/metrics.py.
  5. If you add a metric, edit src/afmcore/metrics.py only.
  6. Deployment note: when the Web backend is packaged without the repository
  7. tree, make src/afmcore importable (e.g. pip install -e ., or copy
  8. src/afmcore into the backend as a package) so this module keeps resolving.
  9. """
  10. import os
  11. import sys
  12. # Make the repository src/ importable when running from a checkout.
  13. _BACKEND_APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. # web/backend/app/metrics_constants.py -> <repo>/src
  15. _SRC_DIR = os.path.normpath(os.path.join(_BACKEND_APP_DIR, "..", "..", "src"))
  16. if _SRC_DIR not in sys.path and os.path.isdir(_SRC_DIR):
  17. sys.path.insert(0, _SRC_DIR)
  18. from afmcore.metrics import ( # noqa: E402
  19. METRIC_KEYS,
  20. METRIC_LABELS,
  21. METRIC_UNITS,
  22. METRIC_DIRECTIONS,
  23. REQUIRED_METRICS,
  24. )