Skip to content

Commit

Permalink
add override handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 26, 2023
1 parent d0f4b12 commit 46580d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion builder2ibek.README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ARGUMENT_NO:VALUE pairs. For example this is the command that works with a
recent version of the pmac module:

```bash
./builder2ibek.support.py /dls_sw/prod/R3.14.12.7/support/pmac/2-5-23beta1/ -o '245:A+B 407:1 410:1'
./builder2ibek.support.py /dls_sw/prod/R3.14.12.7/support/pmac/2-5-23beta1/ -o '14:A+B 474:A+B 801:1 805:1.0 804:1.0'
```

Without the 3 overrides the tools will fail as builder.py tries to convert
Expand Down
36 changes: 22 additions & 14 deletions builder2ibek.support.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
- by editing .vscode/launch.json
"""

# if arg_name == "CS":
# typ = "int"

import argparse
import inspect
import re
Expand Down Expand Up @@ -65,14 +62,15 @@ class ArgInfo:
name_re = re.compile(r"iocbuilder\.modules\.(.*)")
arg_num = 1

def __init__(self, name, unique_name, description):
def __init__(self, name, unique_name, description, overrides):
"""
Unique name is the argument that uniquely identifies
"""
# The arginfo we will consume when calling add_arg_info
self.arginfo = None
# unique name for the builder class
self.unique_name = unique_name
# value overrides for arguments
self.overrides = overrides

# list of ordereddict args to be used in the YAML
self.yaml_args = []
# the root of the definition in yaml that holds above yaml_args
Expand All @@ -83,6 +81,9 @@ def __init__(self, name, unique_name, description):
# list of all the arg names only (across multiple add_arg_info)
self.all_args = []

# The arginfo we will consume when calling add_arg_info
self.arginfo = None

self.yaml_defs["name"] = self.name_re.findall(name)[0]

if description:
Expand Down Expand Up @@ -150,11 +151,12 @@ def make_arg(self, name, details, default=None):
Create a builder object arg entry with best guess for a value.
Support overriding of the guessed values from the command line.
"""

if name == self.unique_name:
typ = "id"
if default == "":
default = None
value = default or "ID_" + str(self.arg_num)
value = default or "ID_" + str(ArgInfo.arg_num)
elif details.typ == str:
typ = "str"
if default == "":
Expand All @@ -181,20 +183,25 @@ def make_arg(self, name, details, default=None):
value = default or details.labels[0]
typ = "enum"

if self.arg_num in Builder2Support.arg_value_overrides:
pass
# special case because CS in pmac comes in as even though it is an int
# TODO needs more investigation
if name == "CS":
typ = "int"
value = MagicMock()

if name not in self.builder_args:
if ArgInfo.arg_num in self.overrides:
value = self.overrides[ArgInfo.arg_num]

self.builder_args[name] = value

# TODO OVERRIDES
if isinstance(value, MagicMock):
value = "Object" + str(self.arg_num)
print(" ARG {:3} {:20} {:<20} {}".format(self.arg_num, name, value, typ))
value = "Object" + str(ArgInfo.arg_num)
print(" ARG {:3} {:20} {:<20} {}".format(ArgInfo.arg_num, name, value, typ))

self.arg_num += 1
ArgInfo.arg_num += 1

return typ, default
return typ, default


class Builder2Support:
Expand Down Expand Up @@ -263,6 +270,7 @@ def _make_builder_object(self, name, builder_class):
name,
getattr(builder_class, "UniqueName", "name"),
getattr(builder_class, "__doc__"),
self.arg_value_overrides
)
arg_info.add_arg_info(builder_class.ArgInfo)

Expand Down

0 comments on commit 46580d1

Please sign in to comment.