Skip to content

Commit 0e287a8

Browse files
committed
Use base-output-filename for example transform outputs
1 parent 68167ba commit 0e287a8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ogc/bblocks/transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ogc.bblocks import mimetypes
1111
from ogc.bblocks.models import BuildingBlock, TransformMetadata, BuildingBlockError
1212
from ogc.bblocks.transformers import transformers
13+
from ogc.bblocks.util import sanitize_filename
1314

1415

1516
def apply_transforms(bblock: BuildingBlock,
@@ -78,8 +79,12 @@ def apply_transforms(bblock: BuildingBlock,
7879
if snippet_mime_type not in supported_input_media_types:
7980
continue
8081

81-
output_fn = output_dir / (f"example_{example_id + 1}_{snippet_id + 1}"
82-
f".{transform['id']}{default_suffix}")
82+
if base_output_filename := example.get('base-output-filename'):
83+
output_fn = output_dir / sanitize_filename(base_output_filename)
84+
output_fn = output_fn.with_name(f"{output_fn.stem}.{transform['id']}{default_suffix}")
85+
else:
86+
output_fn = output_dir / (f"example_{example_id + 1}_{snippet_id + 1}"
87+
f".{transform['id']}{default_suffix}")
8388

8489
metadata = transform.get('metadata', {})
8590
metadata['_prefixes'] = example_prefixes

ogc/bblocks/validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ def validate_test_resources(bblock: BuildingBlock,
316316
add_snippets_formats = []
317317

318318
extension = FORMAT_ALIASES.get(snippet['language'], snippet['language']).replace('/', '.')
319-
fn = bblock.files_path / (f"example_{example_id + 1}_{snippet_id + 1}"
320-
f".{extension}")
319+
fn = bblock.files_path / f"example_{example_id + 1}_{snippet_id + 1}"
321320

322-
output_fn = output_dir / sanitize_filename(example.get('base-output-filename', fn.name))
321+
output_fn = (output_dir.joinpath(sanitize_filename(example.get('base-output-filename', fn.name)))
322+
.with_suffix(f'.{extension}'))
323323
i = 0
324324
while output_fn.stem in output_base_filenames:
325325
i += 1

0 commit comments

Comments
 (0)