Skip to content

Commit

Permalink
DM-47976: Support conversion field in file template format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoldina committed Dec 6, 2024
1 parent d632886 commit d6a4e7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changes/DM-47976.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support type conversion field in file template format strings.
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/datastore/file_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def format(self, ref: DatasetRef) -> str:
parts = fmt.parse(self.template)
output = ""

for literal, field_name, format_spec, _ in parts:
for literal, field_name, format_spec, conversion in parts:
if field_name and "|" in field_name:
alternates = field_name.split("|")
for alt in alternates:
Expand Down Expand Up @@ -678,6 +678,10 @@ def format(self, ref: DatasetRef) -> str:
if replace_slash:
value = value.replace("/", "_")

# Apply conversion (e.g., integer to string)
if conversion:
value = fmt.convert_field(value, conversion)

Check warning on line 683 in python/lsst/daf/butler/datastore/file_templates.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/datastore/file_templates.py#L683

Added line #L683 was not covered by tests

# Now use standard formatting
output = output + literal + format(value, format_spec)

Expand Down

0 comments on commit d6a4e7c

Please sign in to comment.