Skip to content

Commit

Permalink
Preserve yaml structure when updating hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed May 10, 2024
1 parent 590f761 commit 8311611
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions catalog_reader/scripts/apps_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import os
import pathlib
import ruamel.yaml
import shutil
import yaml

Expand All @@ -11,6 +12,10 @@
from catalog_reader.names import get_library_path, get_library_hashes_path, get_base_library_dir_name_from_version


YAML = ruamel.yaml.YAML()
YAML.indent(mapping=2, sequence=4, offset=2)


def update_catalog_hashes(catalog_path: str) -> None:
if not os.path.exists(catalog_path):
raise CatalogDoesNotExist(catalog_path)
Expand Down Expand Up @@ -49,7 +54,7 @@ def update_catalog_hashes(catalog_path: str) -> None:
continue

with open(str(app_metadata_file), 'r') as f:
app_config = yaml.safe_load(f.read())
app_config = YAML.load(f)

if (lib_version := app_config.get('lib_version')) and lib_version not in hashes:
print(
Expand All @@ -69,7 +74,7 @@ def update_catalog_hashes(catalog_path: str) -> None:

app_config['lib_version_hash'] = hashes[lib_version]
with open(str(app_metadata_file), 'w') as f:
yaml.safe_dump(app_config, f)
YAML.dump(app_config, f)

print(f'[\033[92mOK\x1B[0m]\tUpdated library hash for {app_dir.name!r} in {train_dir.name}')

Expand Down

0 comments on commit 8311611

Please sign in to comment.