Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fre/yamltools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def clean_yaml(yml_dict):
if kc in yml_dict.keys():
del yml_dict[kc]

# Clean up any fre_properties in the platforms
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dropping a test like this into test_helpers.py might help out the code coverage report:

def test_yaml_clean():
    input_yaml = {
                  "name": "test"
                  "platform": "ptest"
                  "target": "ttest"
                  "fre_properties": ["some", "list"]
                  "build": {"compile": "yaml1", "platform": "yaml2"}
                  "experiments": ["some", "list"]
                  "compile": {"info": "info1"}
                  "platforms": [{"name": "plat1"},
                                {"name": "plat2", "fre_properties": ["another", "list"]}]
                 }

    # After cleaning - yaml should look like this
    expected_yaml = {
                     "name": "test"
                     "platform": "ptest"
                     "target": "ttest"
                     "compile": {"info": "info1"}
                     "platforms": [{"name": "plat1"},
                                   {"name": "plat2"}]
                    }

    # Clean yaml
    output_yaml = clean_yaml(input_yaml)

    assert output_yaml == expected_yaml

platforms = yml_dict.get('platforms', [])
if platforms:
for platform in platforms:
if "fre_properties" in platform:
del platform['fre_properties']

# Dump cleaned dictionary back into combined yaml file
#cleaned_yaml = yaml.safe_dump(yml_dict,default_flow_style=False,sort_keys=False)
return yml_dict
Expand Down
24 changes: 12 additions & 12 deletions fre/yamltools/info_parsers/compile_info_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def combine_platforms(self, yaml_content):
:param yaml_content: string of yaml information including name, platform,
target, model, and compile yaml content
:type yaml_content: str
:return: dictionary of yaml information including name, platform,
target, model, compile, and platform yaml content
:rtype: dict
:return: string of yaml information including name, platform,
target, model, and compile yaml content
:rtype: str
"""
self.mainyaml_dir = os.path.dirname(self.yml)

Expand All @@ -139,12 +139,9 @@ def combine_platforms(self, yaml_content):
# Combine information as strings
yaml_content += platform_content

# Load string as yaml
yml = yaml.load(yaml_content, Loader = yaml.Loader)

# Return the combined string and loaded yaml
fre_logger.info(f" platforms yaml: {py_path}")
return yml
return yaml_content

def combine(self):
"""
Expand All @@ -168,19 +165,22 @@ def combine(self):

# Merge compile into combined file to create updated yaml_content/yaml
try:
yaml_content = self.combine_compile(yaml_content)
yaml_content = self.combine_platforms(yaml_content)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Though not necessary, it might be nice to have the functions in the class above follow how the yamls are combined here, which means 2 changes:

  1. Just switching the order of the functions around in InitCompileYaml in this file
  2. Switching around the order that class follows in abstract_classes.py

except Exception as exc:
raise ValueError("ERR: Could not merge compile yaml config with model config.") from exc
raise ValueError("ERR: Could not merge platform yaml config with model config.") from exc

# Merge platforms.yaml into combined file
try:
full_combined = self.combine_platforms(yaml_content)
full_combined = self.combine_compile(yaml_content)
except Exception as exc:
raise ValueError("ERR: Could not merge platform yaml config with model and compile configs.") from exc
raise ValueError("ERR: Could not merge compile yaml config with model and platform configs.") from exc

# Load string as yaml
yml = yaml.load(full_combined, Loader = yaml.Loader)

# Clean the yaml
try:
cleaned_yaml = clean_yaml(full_combined)
cleaned_yaml = clean_yaml(yml)
except Exception as exc:
raise ValueError("The final YAML could not cleaned.") from exc

Expand Down
Loading