Skip to content

Commit dc15d3e

Browse files
author
Jon
committed
Thanks ruff
1 parent 0a998b5 commit dc15d3e

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

codegen/lco/generator.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,47 @@
1212

1313

1414
def get_extra_params_fields(extra_params_validation_schema: dict) -> dict:
15-
""" Loops over the "extra_params" section of a validation_schema dict and creates a dictionary of
16-
field to aeonlib field_class to place into the template
15+
"""Loops over the "extra_params" section of a validation_schema dict and creates a dictionary of
16+
field to aeonlib field_class to place into the template
1717
"""
1818
fields = {}
1919
for field, properties in extra_params_validation_schema.items():
20-
field_class = ''
20+
field_class = ""
2121
# If a set of allowed values is present, use that to make a Literal unless this is a boolean variable
22-
if 'allowed' in properties and properties.get('type') != 'boolean':
23-
allowed_values = [f'"{val}"' if properties['type'] == 'string' else val for val in properties['allowed']]
22+
if "allowed" in properties and properties.get("type") != "boolean":
23+
allowed_values = [
24+
f'"{val}"' if properties["type"] == "string" else val
25+
for val in properties["allowed"]
26+
]
2427
field_class += f"Literal[{', '.join(allowed_values)}]"
2528
else:
2629
# Otherwise form an Annotated field based on its datatype, with min/max validation if present
2730
field_class += "Annotated["
28-
match properties['type']:
29-
case 'string':
31+
match properties["type"]:
32+
case "string":
3033
field_class += "str"
31-
case 'integer':
34+
case "integer":
3235
field_class += "int"
33-
case 'float':
36+
case "float":
3437
field_class += "float"
35-
case 'boolean':
38+
case "boolean":
3639
field_class += "bool"
37-
if 'min' in properties:
40+
if "min" in properties:
3841
field_class += f", Ge({properties['min']})"
39-
if 'max' in properties:
42+
if "max" in properties:
4043
field_class += f", Le({properties['max']})"
4144
# Add description to Annotated field. Annotated fields must have at least 2 properties.
42-
field_class += f', "{properties.get('description', "")}"]'
43-
if not properties.get('required', False) and 'default' not in properties:
45+
field_class += f', "{properties.get("description", "")}"]'
46+
if not properties.get("required", False) and "default" not in properties:
4447
# The field is considered optional if it doesn't have a default or required is set to True
4548
field_class += " | None = None"
46-
elif 'default' in properties:
49+
elif "default" in properties:
4750
# If a default value is present, provide it
48-
default = f'"{properties['default']}"' if properties['type'] == 'string' else properties['default']
51+
default = (
52+
f'"{properties["default"]}"'
53+
if properties["type"] == "string"
54+
else properties["default"]
55+
)
4956
field_class += f" = {default}"
5057
fields[field] = field_class
5158
return fields
@@ -124,8 +131,17 @@ def generate_instrument_configs(ins_s: str, facility: str) -> str:
124131
k.rstrip("s"): v
125132
for k, v in ins["optical_elements"].items()
126133
},
127-
"configuration_extra_params": get_extra_params_fields(ins['validation_schema'].get('extra_params', {}).get('schema', {})),
128-
"instrument_config_extra_params": get_extra_params_fields(ins['validation_schema'].get('instrument_configs', {}).get('schema', {}).get('schema', {}).get('extra_params', {}).get('schema', {}))
134+
"configuration_extra_params": get_extra_params_fields(
135+
ins["validation_schema"].get("extra_params", {}).get("schema", {})
136+
),
137+
"instrument_config_extra_params": get_extra_params_fields(
138+
ins["validation_schema"]
139+
.get("instrument_configs", {})
140+
.get("schema", {})
141+
.get("schema", {})
142+
.get("extra_params", {})
143+
.get("schema", {})
144+
),
129145
}
130146
)
131147

0 commit comments

Comments
 (0)