Skip to content

Commit

Permalink
Replac pyyaml with ruamel.yaml for more flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
riprasad committed Jan 5, 2025
1 parent cdf7be4 commit 4b212be
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = "pypi"

[packages]
requests = "~=2.32.3"
pyyaml = "~=6.0.2"
gitpython = "~=3.1.44"
"ruamel.yaml" = "~=0.18.9"

[dev-packages]

Expand Down
122 changes: 61 additions & 61 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/gam_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
import json
import os
import yaml
import ruamel.yaml
from hydra_adapter import HydraAdapter
import util

Expand All @@ -20,7 +20,7 @@ def __init__(self, business_component: str, execution_id: str, gam_run_url: str)
self.hydra_payload = self.generate_hydra_payload()

def read_gam_config(self):
return yaml.load(open(GAM_CONFIG), Loader=yaml.SafeLoader)
return ruamel.yaml.YAML(typ='safe').load(open(GAM_CONFIG))

def read_component_config(self):
try:
Expand All @@ -38,23 +38,25 @@ def generate_execution_metadata(self):
execution_metadata_template = {
'config': self.component_config,
'metadata': {
'execution_id': self.execution_id,
'path': metadata_path,
'git': None,
'nvr': None,
'execution_id': self.execution_id,
'path': metadata_path,
'gam_run_url': self.gam_run_url,
'auto_merge_url': None,
'test_run_url': None,
'test_result': None,
'auto_merge_url': None,
'status': None
}
}
# Populate Execution Metadata Template
execution_metadata = util.populate_execution_metadata(execution_metadata_template, self.component_config)

# Save the updated metadata to the file
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
with open(METADATA, 'w') as metadata:
metadata.write(yaml.dump(execution_metadata))
yaml.dump(execution_metadata, metadata)

return execution_metadata

Expand Down
4 changes: 2 additions & 2 deletions src/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
import git
import json
import yaml
import ruamel.yaml
import tempfile

def populate_execution_metadata(execution_metadata, component_config):
Expand All @@ -17,7 +17,7 @@ def populate_execution_metadata(execution_metadata, component_config):

# Load the necessary files from the cloned repo
cvp = json.load(open(temp_dir + '/build/latest/cvp.json'))
upstream_sources = yaml.safe_load(open(temp_dir + '/build/latest/upstream_sources.yml', 'r'))
upstream_sources = ruamel.yaml.YAML(typ='safe').load(open(temp_dir + '/build/latest/upstream_sources.yml', 'r'))

# Update the metadata with the NVR from the CVP file
execution_metadata['metadata']['nvr'] = cvp['artifact']['nvr']
Expand Down

0 comments on commit 4b212be

Please sign in to comment.