Skip to content

Commit d3d155a

Browse files
author
torri
committed
refining of outputs
1 parent 2e27904 commit d3d155a

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

.github/workflows/check_licenses.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
echo "modules_results.json file exists, trying to fetch the license..."
132132
ml Python-bundle-PyPI/2023.06-GCCcore-12.3.0 BeautifulSoup/4.12.2-GCCcore-12.3.0 PyYAML/6.0-GCCcore-12.3.0
133133
python licenses/parse_licenses.py modules_results.json licenses/licenses.yml
134-
cat licenses_aux.yaml
134+
cat temporal_print.yaml
135135
else
136136
echo "modules_results.json file does not exist, skipping license fetch."
137137
fi

licenses/licenses_transformer.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
import yaml
4+
from collections import defaultdict
5+
6+
infile = "licenses.yaml"
7+
outfile = "licenses.yml"
8+
9+
with open(infile, "r") as f:
10+
data = yaml.safe_load(f)
11+
12+
# Nested dict: {software: {version: info}}
13+
result = {}
14+
15+
for full_key, info in data.items():
16+
# Example full_key: "ALL/0.9.2-foss-2023a"
17+
try:
18+
software, rest = full_key.split("/", 1)
19+
except ValueError:
20+
# If no '/', skip or handle differently
21+
# For now just continue
22+
print(f"Skipping key without '/': {full_key}")
23+
continue
24+
25+
# Split the version from the toolchain suffix
26+
# "0.9.2-foss-2023a" -> version="0.9.2"
27+
version = rest.split("-", 1)[0]
28+
29+
# Ensure nested structure exists
30+
if software not in result:
31+
result[software] = {}
32+
if version in result[software]:
33+
# Optional: warn if we’re overwriting same software/version
34+
print(f"Warning: duplicate entry for {software} {version}, overwriting.")
35+
36+
result[software][version] = info
37+
38+
with open(outfile, "w") as f:
39+
yaml.safe_dump(result, f, sort_keys=True)

licenses/parse_licenses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ def process_modules_for_licenses(modules_file):
241241

242242
def save_license_results(results, output_file="licenses_aux.yaml",licenses_original = os.sys.argv[2]):
243243
"""Saves license information to a JSON file."""
244+
with open("temporal_print.yaml", "w") as f:
245+
yaml.dump(results, f, default_flow_style=False, sort_keys=True) #Fast dump of what we have to print in the workflow
246+
244247
full_data = {}
245248
with open(licenses_original, 'r') as f:
246249
full_data = yaml.safe_load(f)
@@ -250,7 +253,8 @@ def save_license_results(results, output_file="licenses_aux.yaml",licenses_origi
250253
full_data[software_name] = {}
251254

252255
for version, details in versions_data.items():
253-
full_data[software_name][version] = details #Add/replace the details of modules found in the new licenses data dictionary
256+
if version not in full_data[software_name]:
257+
full_data[software_name][version] = details #Add/replace the details of modules found in the new licenses data dictionary
254258

255259
with open(output_file, "w") as f:
256260
yaml.dump(full_data, f, default_flow_style=False, sort_keys=True) #Export data dictionary as licenses_aux.yaml file

0 commit comments

Comments
 (0)