Skip to content

Commit

Permalink
Merge pull request #147 from seqeralabs/dev
Browse files Browse the repository at this point in the history
Release v0.4.8
  • Loading branch information
ejseqera authored May 2, 2024
2 parents 520a3f5 + 72a8d71 commit 60efe63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions seqerakit/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import yaml
from seqerakit import utils
import sys
import json


def parse_yaml_block(yaml_data, block_name):
Expand Down Expand Up @@ -79,24 +80,28 @@ def parse_all_yaml(file_paths, destroy=False):
f" The file '{file_path}' is empty or "
"does not contain valid data."
)

# Process each key-value pair in YAML data
for key, new_value in data.items():
if key in merged_data:
if isinstance(new_value, list) and all(
isinstance(i, dict) for i in new_value
):
# Handle list of dictionaries & merge without duplication
existing_items = {
tuple(sorted(d.items())) for d in merged_data[key]
}
for item in new_value:
if tuple(sorted(item.items())) not in existing_items:
merged_data[key].append(item)
else:
# override if not list of dictionaries
merged_data[key] = new_value
# Check if key exist in merged_data and
# new value is a list of dictionaries
if (
key in merged_data
and isinstance(new_value, list)
and all(isinstance(i, dict) for i in new_value)
):
# Serialize dictionaries to JSON strings for comparison
existing_items = {
json.dumps(d, sort_keys=True) for d in merged_data[key]
}
for item in new_value:
# Check if item is not already present in merged data
item_json = json.dumps(item, sort_keys=True)
if item_json not in existing_items:
# Append item to merged data
merged_data[key].append(item)
else:
merged_data[key] = new_value

except FileNotFoundError:
print(f"Error: The file '{file_path}' was not found.")
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import find_packages, setup

VERSION = "0.4.7"
VERSION = "0.4.8"

with open("README.md") as f:
readme = f.read()
Expand Down

0 comments on commit 60efe63

Please sign in to comment.