Skip to content

Commit

Permalink
Merge pull request #131 from epics-containers/dev
Browse files Browse the repository at this point in the history
fix pre-commit. Update builder2ibeksupport.py convertor
  • Loading branch information
gilesknap authored Nov 8, 2023
2 parents b21cfa9 + ab560a6 commit 25a1693
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-yaml
Expand Down
35 changes: 27 additions & 8 deletions builder2ibek.support.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,25 @@ def _interpret(self):
new_yaml_arg["type"] = typ
new_yaml_arg["name"] = arg_name
new_yaml_arg["description"] = PreservedScalarString(description_str)
if default:
if default is not None:
new_yaml_arg["default"] = default
if typ == "enum":
new_yaml_arg["values"] = {
str(label): None for label in details.labels
}
# coerce type of args that have default strings which are ints or reals
if typ == "str" and default:
try:
i = int(default)
new_yaml_arg["default"] = i
new_yaml_arg["type"] = "int"
except ValueError:
try:
f = float(default)
new_yaml_arg["default"] = f
new_yaml_arg["type"] = "float"
except ValueError:
pass

self.yaml_args.append(new_yaml_arg)
self.all_args.append(arg_name)
Expand Down Expand Up @@ -198,6 +211,7 @@ def make_arg(self, name, details, default=None):
if name not in self.builder_args:
if ArgInfo.arg_num in self.overrides:
value = self.overrides[ArgInfo.arg_num]
typ = type(value).__name__

self.builder_args[name] = value

Expand Down Expand Up @@ -367,6 +381,8 @@ def _make_init_script(self, builder_object, func_name, script, arginfo, when=Non
missing = set(command_args) - set(arginfo.all_args)
comment = MISSING + ", ".join(missing) if missing else None

# remove spurious \n from the script text (not newlines)
script_text = script_text.replace(r"\n", "")
script_item.insert(3, "value", script_text, comment=comment)

script.append(script_item)
Expand Down Expand Up @@ -424,16 +440,17 @@ def write_yaml_tree(self, filename):
def tidy_up(yaml):
# add blank lines between major fields
for field in [
"- name:",
" databases:",
" pre_init:",
" post_init:",
" - name:",
" databases:",
" pre_init:",
" post_init:",
"module",
"defs",
" - type:",
" - type:",
" - file:",
" - value:",
]:
yaml = re.sub(r"(\n%s)" % field, "\n\\g<1>", yaml)

return yaml

yaml = YAML()
Expand All @@ -443,11 +460,13 @@ def tidy_up(yaml):
# add support yaml schema
self.yaml_tree.yaml_add_eol_comment(
"yaml-language-server: $schema=https://github.com/epics-"
"containers/ibek/releases/download/1.2.0/ibek.support.schema.json"
"containers/ibek/releases/download/1.2.0/ibek.support.schema.json",
column=0,
)

print("\nWriting YAML output to %s ..." % filename)
with open(filename, "wb") as f:
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.dump(self.yaml_tree, f, transform=tidy_up)


Expand Down

0 comments on commit 25a1693

Please sign in to comment.