Repository navigation
Expand file tree
/
Copy pathconstants.py
More file actions
164 lines (127 loc) · 5.92 KB
/
Copy pathconstants.py
File metadata and controls
164 lines (127 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"""
constants.py - Project-wide constants for FLocKit (FLock.io).
Defines constants used across the FLocKit project, including the canonical
brand identity (product name, vendor, tagline, homepage) and the list of
supported template names. Template registration and discovery is handled by
``templates/__init__.py``; this module simply re-exports the template names
so that entry-point code (``main.py``, ``bootstrap.py``) can validate user
input without importing the full template machinery.
Sections:
Path constants - Repository / output path roots.
Brand constants - Single source of truth for product / vendor strings
consumed by CLI ``--version``, log banners, OCI
labels, and the FlockSDK health endpoint.
Template names - Canonical template identifiers and tuple.
SDK constants - Defaults for the FLock SDK server.
Helper functions - Lightweight validators and formatters.
Usage:
from constants import AVAILABLE_TEMPLATES, is_valid_template
from constants import REPO_ROOT, DEFAULT_OUTPUT_ROOT
from constants import PRODUCT_NAME, VENDOR, get_product_version
"""
from __future__ import annotations
import os
# -----------------------------------------------------------------------------
# Path constants
# -----------------------------------------------------------------------------
# Project root directory (parent of this file).
REPO_ROOT: str = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
# Default root directory for all outputs (checkpoints, logs, cache, inference).
# Overridable via tracking_args.output_root in YAML.
DEFAULT_OUTPUT_ROOT: str = "output"
# -----------------------------------------------------------------------------
# Brand constants
# -----------------------------------------------------------------------------
# Single source of truth for the FLocKit product identity. Any surface that
# shows the brand (CLI ``--version``, argparse epilog, log banners, Docker
# OCI labels, FlockSDK ``/`` health endpoint, persisted artifact metadata)
# must read from these constants so the wording stays consistent.
# Human-readable product name.
PRODUCT_NAME: str = "FLocKit"
# Distribution / installable package name (matches ``pyproject.toml``
# ``[project].name`` and ``importlib.metadata`` lookups).
PRODUCT_DIST_NAME: str = "flockit"
# Short tagline reused as a one-line subtitle / byline beneath the
# product name. Carries the parent brand (FLock.io) so operators see
# product + vendor together at every entry point.
PRODUCT_TAGLINE: str = "FLocKit · FLock.io"
# Parent brand / vendor (used in Docker OCI labels, CLI epilog, etc.).
VENDOR: str = "FLock.io"
# Project homepage; surfaced in --version, OCI labels, and CLI epilog.
HOMEPAGE: str = "https://flock.io"
def get_product_version() -> str:
"""
Resolve the installed FLocKit version.
Tries the installed-package metadata first (``importlib.metadata``) so
`pip install flockit` users get the exact wheel version. Falls back to
the version declared in ``pyproject.toml`` so source-only checkouts
(developer machines, ``uv run`` from a clone) still report a real
version instead of "unknown".
Returns:
Semver string (e.g. ``"1.0.0"``) or ``"unknown"`` if neither lookup
succeeds. Never raises — callers can safely embed the result in a
log line or HTTP response.
"""
try:
from importlib.metadata import version as _pkg_version
return _pkg_version(PRODUCT_DIST_NAME)
except Exception:
pass
try:
try:
import tomllib # 3.11+
except ImportError: # pragma: no cover - 3.10 fallback
import tomli as tomllib # type: ignore[no-redef]
pyproject = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"pyproject.toml",
)
if os.path.exists(pyproject):
with open(pyproject, "rb") as fh:
data = tomllib.load(fh)
return str(data.get("project", {}).get("version", "unknown"))
except Exception:
pass
return "unknown"
# -----------------------------------------------------------------------------
# Template name constants
# -----------------------------------------------------------------------------
# These MUST stay in sync with the TEMPLATE_REGISTRY in templates/__init__.py.
# If you add a new template, add its name here AND register it in the registry.
LLM_FINETUNING: str = "llm_finetuning"
AUTOMATIC_SPEECH_RECOGNITION: str = "automatic_speech_recognition"
TIME_SERIES_PREDICTION: str = "time_series_prediction"
GRAPH_NODE_CLASSIFICATION: str = "graph_node_classification"
AVAILABLE_TEMPLATES: tuple[str, ...] = (
LLM_FINETUNING,
AUTOMATIC_SPEECH_RECOGNITION,
TIME_SERIES_PREDICTION,
GRAPH_NODE_CLASSIFICATION,
)
# -----------------------------------------------------------------------------
# SDK constants
# -----------------------------------------------------------------------------
# Default port for the FLock SDK Flask server.
DEFAULT_SDK_PORT: int = 5000
# Fallback loss value used when evaluation returns non-finite results.
FALLBACK_LOSS_VALUE: float = 999.0
# -----------------------------------------------------------------------------
# Helper functions
# -----------------------------------------------------------------------------
def is_valid_template(template_name: str) -> bool:
"""
Check whether *template_name* is a recognised FLocKit template.
Args:
template_name: The template identifier to validate.
Returns:
True if the name is in the list of available templates.
"""
return template_name in AVAILABLE_TEMPLATES
def get_template_choices() -> str:
"""
Return a comma-separated string of available template names.
Useful for CLI help text and error messages.
Returns:
Formatted string listing all template names.
"""
return ", ".join(AVAILABLE_TEMPLATES)