Skip to content

feat: expose effective_root paths in SQL runtime templates#65

Merged
Gabrymi93 merged 3 commits intomainfrom
feat/sql-template-root-paths
Mar 22, 2026
Merged

feat: expose effective_root paths in SQL runtime templates#65
Gabrymi93 merged 3 commits intomainfrom
feat/sql-template-root-paths

Conversation

@matteocavo
Copy link
Copy Markdown
Contributor

Supports dataciviclab/dataset-incubator#69

Cosa cambia

toolkit/core/template.py

  • aggiunge build_runtime_template_ctx(...)
  • espone in modo additive-only i placeholder runtime root, root_posix, base_dir, base_dir_posix
  • mantiene invariati i placeholder esistenti {year} e {dataset}

toolkit/clean/run.py e toolkit/mart/run.py

  • usano il nuovo contesto runtime quando rendono il SQL
  • i query file possono quindi leggere artifact sotto l'effective_root reale senza dipendere dal current working directory

toolkit/cli/sql_dry_run.py

  • usa lo stesso contesto del runtime reale, cosi' il dry-run valida anche SQL che usano {root_posix}

Test

  • aggiunge un test dry-run per SQL MART con {root_posix}
  • aggiunge un test runtime per run_mart(...) con {root_posix}
  • lascia verdi anche i test esistenti sul path contract CLI

Perché

Nel follow-up dataset-incubator#69 il candidate ispra-ru-costi-kg aveva bisogno di leggere parquet MART gia' prodotti sotto l'effective_root del dataset.

Senza un placeholder runtime per il root, l'unica opzione era hardcodare out/data/... nei SQL, con due effetti indesiderati:

  • dipendenza dal current working directory
  • scarsa riproducibilita' su ambienti o layout con root diverso

Questo hook resta minimale e backward-compatible, ma sblocca un contratto molto piu' robusto per SQL compose/cross che leggono artifact gia' materializzati.

Verifica

  • ruff check toolkit/core/template.py toolkit/clean/run.py toolkit/mart/run.py toolkit/cli/sql_dry_run.py tests/test_run_dry_run.py tests/test_artifacts_policy.py
  • pytest tests/test_run_dry_run.py -q -k root_posix
  • pytest tests/test_artifacts_policy.py -q -k root_posix
  • pytest tests/test_cli_path_contract.py tests/test_run_dry_run.py -q

@matteocavo matteocavo added the enhancement New feature or request label Mar 22, 2026
@matteocavo
Copy link
Copy Markdown
Contributor Author

@Gabrymi93 pronta per review. Fix additive-only: esposto nel template runtime, backward-compatible con tutti i dataset.yml esistenti. Collega dataset-incubator#69.

Copy link
Copy Markdown
Member

@Gabrymi93 Gabrymi93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfetto!

@Gabrymi93 Gabrymi93 merged commit 74bec49 into main Mar 22, 2026
5 checks passed
@Gabrymi93 Gabrymi93 deleted the feat/sql-template-root-paths branch March 22, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants