Skip to content

Commit

Permalink
switch from yaml to toml
Browse files Browse the repository at this point in the history
  • Loading branch information
damonbayer committed Dec 17, 2024
1 parent 3e4ef32 commit a31a7e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pipelines/forecast_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import os
import shutil
import subprocess
import tomllib
import tomli_w

Check warning on line 7 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L6-L7

Added lines #L6 - L7 were not covered by tests
from datetime import datetime, timedelta
from pathlib import Path

import numpyro
import polars as pl
import yaml
from prep_data import process_and_save_state
from pygit2 import Repository
from save_eval_data import save_eval_data
Expand All @@ -20,11 +21,11 @@


def record_git_info(model_run_dir: Path):
metadata_file = Path(model_run_dir, "metadata.yaml")
metadata_file = Path(model_run_dir, "metadata.toml")

Check warning on line 24 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L24

Added line #L24 was not covered by tests

if metadata_file.exists():
with open(metadata_file, "r") as file:
metadata = yaml.safe_load(file)
with open(metadata_file, "rb") as file:
metadata = tomllib.load(file)

Check warning on line 28 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L26-L28

Added lines #L26 - L28 were not covered by tests
else:
metadata = {}

Check warning on line 30 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L30

Added line #L30 was not covered by tests

Expand All @@ -43,17 +44,18 @@ def record_git_info(model_run_dir: Path):

metadata.update(new_metadata)

Check warning on line 45 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L45

Added line #L45 was not covered by tests

with open(metadata_file, "w") as file:
yaml.dump(metadata, file)
metadata_file.parent.mkdir(parents=True, exist_ok=True)
with open(metadata_file, "wb") as file:
tomli_w.dump(metadata, file)

Check warning on line 49 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L47-L49

Added lines #L47 - L49 were not covered by tests


def copy_and_record_priors(priors_path: Path, model_run_dir: Path):
metadata_file = Path(model_run_dir, "metadata.yaml")
metadata_file = Path(model_run_dir, "metadata.toml")
shutil.copyfile(priors_path, Path(model_run_dir, "priors.py"))

Check warning on line 54 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L52-L54

Added lines #L52 - L54 were not covered by tests

if metadata_file.exists():
with open(metadata_file, "r") as file:
metadata = yaml.safe_load(file)
with open(metadata_file, "rb") as file:
metadata = tomllib.load(file)

Check warning on line 58 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L56-L58

Added lines #L56 - L58 were not covered by tests
else:
metadata = {}

Check warning on line 60 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L60

Added line #L60 was not covered by tests

Expand All @@ -63,8 +65,8 @@ def copy_and_record_priors(priors_path: Path, model_run_dir: Path):

metadata.update(new_metadata)

Check warning on line 66 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L66

Added line #L66 was not covered by tests

with open(metadata_file, "w") as file:
yaml.dump(metadata, file)
with open(metadata_file, "wb") as file:
tomli_w.dump(metadata, file)

Check warning on line 69 in pipelines/forecast_state.py

View check run for this annotation

Codecov / codecov/patch

pipelines/forecast_state.py#L68-L69

Added lines #L68 - L69 were not covered by tests


def generate_epiweekly(model_run_dir: Path) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pyarrow = "^18.0.0"
pygit2 = "^1.16.0"
azuretools = {git = "https://github.com/cdcgov/cfa-azuretools"}
forecasttools = {git = "https://github.com/CDCgov/forecasttools-py"}
tomli-w = "^1.1.0"

[tool.poetry.group.test]
optional = true
Expand Down

0 comments on commit a31a7e0

Please sign in to comment.