Skip to content

Commit

Permalink
feat: Parse numerical strings in yaml files as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdcordeiro committed May 24, 2024
1 parent 6625b16 commit f7bc87f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/docs/generate_oci_doc_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ def read_documentation_yaml(doc_file: str) -> Dict:
logging.info("Opening file %s", doc_file)
with open(doc_file, "r", encoding="UTF-8") as file:
try:
base_doc_data = DocSchema(**yaml.safe_load(file) or {}).dict(
exclude_none=True
)
base_doc_data = DocSchema(
**yaml.load(file, Loader=yaml.BaseLoader) or {}
).dict(exclude_none=True)
except (yaml.YAMLError, pydantic.ValidationError) as exc:
msg = f"Error loading the {doc_file} file"
raise Exception(msg) from exc
Expand Down
2 changes: 1 addition & 1 deletion src/image/merge_release_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def backfill_higher_risks(channels: dict) -> None:

print(f"Getting existing image trigger from {args.image_trigger}")
with open(args.image_trigger, encoding="UTF-8") as trigger:
image_trigger = yaml.safe_load(trigger)
image_trigger = yaml.load(trigger, Loader=yaml.BaseLoader)

_ = ImageSchema(**image_trigger)

Expand Down
2 changes: 1 addition & 1 deletion src/image/prepare_single_image_build_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def validate_image_trigger(data: dict) -> None:

print(f"Generating build matrix for {image_trigger_file}")
with open(image_trigger_file, encoding="UTF-8") as bf:
image_trigger = yaml.safe_load(bf)
image_trigger = yaml.load(bf, Loader=yaml.BaseLoader)
try:
validate_image_trigger(image_trigger)
except pydantic.error_wrappers.ValidationError as err:
Expand Down
2 changes: 1 addition & 1 deletion src/image/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

print(f"Parsing image trigger {args.image_trigger}")
with open(args.image_trigger, encoding="UTF-8") as trigger:
image_trigger = ImageSchema(**yaml.safe_load(trigger))
image_trigger = ImageSchema(**yaml.load(trigger, Loader=yaml.BaseLoader))

tag_mapping_from_trigger = {}
for track, risks in image_trigger.release.items():
Expand Down
3 changes: 2 additions & 1 deletion src/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docker
pydantic==1.9.0
pydantic==1.9.0
requests==2.31
5 changes: 3 additions & 2 deletions src/uploads/infer_image_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import yaml


logging.basicConfig()


Expand All @@ -31,7 +32,7 @@ def get_release_from_codename(codename: str) -> str:
with open(
f"{args.recipe_dirname.rstrip('/')}/rockcraft.yaml", encoding="UTF-8"
) as rockcraft_file:
rockcraft_yaml = yaml.safe_load(rockcraft_file)
rockcraft_yaml = yaml.load(rockcraft_file, Loader=yaml.BaseLoader)

rock_base = (
rockcraft_yaml["base"]
Expand All @@ -43,7 +44,7 @@ def get_release_from_codename(codename: str) -> str:
base_release = float(rock_base.replace(":", "@").split("@")[-1])
except ValueError:
logging.warning(
f"Could not infer rock's base release from {rock_base}. Trying with codename."
f"Could not infer ROCK's base release from {rock_base}. Trying with codename."
)
base_release = float(
get_release_from_codename(rock_base.replace(":", "@").split("@")[-1])
Expand Down

0 comments on commit f7bc87f

Please sign in to comment.