Skip to content

Commit c592377

Browse files
committed
Try to collect configurations from the script which makes them
1 parent ef9f4a9 commit c592377

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

.github/workflows/linux-eic-shell.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ jobs:
3333
- uses: actions/checkout@v4
3434
- id: list-detector-configs
3535
run: |
36-
CONFIGS_CSV=$(
37-
ls -1 configurations | sed 's/^/epic_/g' | xargs | sed 's/\.yml//g;s/ /,/g'
38-
)
39-
CONFIGS_JSON=$((
40-
echo '['
41-
ls -1 configurations | sed 's/^/epic_/g' | xargs | sed 's/\.yml//g;s/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
42-
echo ']'
43-
) | jq -c .)
36+
# Collect all config names from all YAMLs, one per line
37+
CONFIGS="$(
38+
for config in configurations/*.yml; do
39+
./bin/make_detector_configuration -d templates -t epic.xml.jinja2 -c "$config" -o "epic_$(basename "$config" .yml).xml" -p
40+
done | sort -u
41+
)"
42+
43+
# CSV
44+
CONFIGS_CSV="$(echo "$CONFIGS" | paste -sd, -)"
45+
# JSON
46+
CONFIGS_JSON="$(echo "$CONFIGS" | jq -R -s -c 'split("\n")[:-1]')"
47+
4448
echo "configs_csv=${CONFIGS_CSV}" | tee -a $GITHUB_OUTPUT
4549
echo "configs_json=${CONFIGS_JSON}" | tee -a $GITHUB_OUTPUT
4650

bin/make_detector_configuration

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ parser.add_argument('-d', '--dir', type=str, default='templates', help='Template
1212
parser.add_argument('-t', '--template', type=str, help='Template to render.')
1313
parser.add_argument('-o', '--output', type=str, help='Output file to write.')
1414
parser.add_argument('-c', '--config', type=str, help='Config file to load.')
15+
parser.add_argument('-p', '--print', action='store_true', help='Print the list of configurations to be created without creating them.')
1516
args = parser.parse_args()
1617

18+
outputs = [args.output]
19+
1720
# template
1821
env = jinja2.Environment(
1922
loader = jinja2.FileSystemLoader(args.dir),
@@ -27,8 +30,9 @@ if args.config is not None:
2730
config = yaml.safe_load(f)
2831

2932
# render the template
30-
with open(args.output, 'w') as output:
31-
output.write(template.render(**config))
33+
if not args.print:
34+
with open(args.output, 'w') as output:
35+
output.write(template.render(**config))
3236

3337
# If the config contains far_forward or far_backward create new xml files with ebeam and pbeam set
3438
if 'features' in config and ('far_forward' in config['features'] or 'far_backward' in config['features']):
@@ -52,11 +56,19 @@ if 'features' in config and ('far_forward' in config['features'] or 'far_backwar
5256
]
5357

5458
for values in ebeam_pbeam_values:
59+
# Create a new output filename based on the ebeam and pbeam values
60+
new_output = args.output.replace('.xml', f"_{values['ebeam']}x{values['pbeam']}.xml")
61+
outputs.append(new_output)
62+
5563
# Create a new config dictionary with the current ebeam and pbeam values
5664
new_config = config.copy()
5765
new_config.update(values)
66+
67+
if not args.print:
68+
with open(new_output, 'w') as output:
69+
output.write(template.render(**new_config))
5870

59-
# Render the template with the new config
60-
new_output = args.output.replace('.xml', f"_{values['ebeam']}x{values['pbeam']}.xml")
61-
with open(new_output, 'w') as output:
62-
output.write(template.render(**new_config))
71+
if args.print:
72+
for output in outputs:
73+
# Print the output configuration name without the xml extension
74+
print(os.path.basename(output).replace('.xml', ''))

0 commit comments

Comments
 (0)