RRC / scripts /upload_report_artifacts.py
pablogrois's picture
Deploy MVP: API JSON + SPA + bundle/cache de artifacts CORE
e58615a
Raw
History Blame Contribute Delete
2.35 kB
"""Sube a Azure (report_artifacts root) los artifacts que necesitan los
reportes reales: parquets + bundles GNN. Reusa el patrón de
scripts/upload_preprocessed_labeled.py.
Uso:
python scripts/upload_report_artifacts.py \
--source /Users/pagrois/Racing/data [--overwrite]
"""
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from azure.identity import ClientSecretCredential, DefaultAzureCredential
from azure.storage.filedatalake import DataLakeServiceClient
from racing_reports.config import DEFAULT_SETTINGS
from racing_reports.vendor_env import ARTIFACT_RELATIVE_PATHS
def _credential():
import os
t, c, s = (
os.getenv("AZURE_TENANT_ID"),
os.getenv("AZURE_CLIENT_ID"),
os.getenv("AZURE_CLIENT_SECRET"),
)
if t and c and s:
return ClientSecretCredential(tenant_id=t, client_id=c, client_secret=s)
return DefaultAzureCredential()
def main() -> None:
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
log = logging.getLogger(__name__)
parser = argparse.ArgumentParser(description="Sube artifacts de reportes a Azure.")
parser.add_argument("--source", required=True, help="Carpeta local con los artifacts.")
parser.add_argument("--overwrite", action="store_true")
args = parser.parse_args()
source = Path(args.source)
settings = DEFAULT_SETTINGS
service = DataLakeServiceClient(
account_url=settings.account_url, credential=_credential()
)
fs = service.get_file_system_client(settings.azure_filesystem)
root = settings.azure_report_artifacts_root
for rel in ARTIFACT_RELATIVE_PATHS:
local = source / rel
if not local.exists():
log.warning("No existe (se saltea): %s", local)
continue
remote = f"{root}/{rel}".replace("//", "/")
fc = fs.get_file_client(remote)
if fc.exists() and not args.overwrite:
log.info("Ya existe (usar --overwrite): %s", remote)
continue
log.info("Subiendo %s -> %s", local, remote)
with local.open("rb") as f:
fc.upload_data(f, overwrite=True)
log.info("Listo.")
if __name__ == "__main__":
main()