diff --git a/src/styx/backend/__init__.py b/src/styx/backend/__init__.py index e69de29..cb28796 100644 --- a/src/styx/backend/__init__.py +++ b/src/styx/backend/__init__.py @@ -0,0 +1 @@ +"""Styx Python backend.""" diff --git a/src/styx/backend/python/pycodegen/core.py b/src/styx/backend/python/pycodegen/core.py index 160e434..df67bde 100644 --- a/src/styx/backend/python/pycodegen/core.py +++ b/src/styx/backend/python/pycodegen/core.py @@ -154,7 +154,7 @@ class PyDataClass(PyGen): fields: list[PyArg] = field(default_factory=list) methods: list[PyFunc] = field(default_factory=list) - def generate(self, named_tuple=False) -> LineBuffer: + def generate(self, named_tuple: bool = False) -> LineBuffer: # Sort fields so default arguments come last self.fields.sort(key=lambda a: a.default is not None) @@ -218,9 +218,7 @@ def generate(self) -> LineBuffer: ) return blank_after([ - *( - ['"""', *linebreak_paragraph(self.docstr), '"""'] if self.docstr else [] - ), + *(['"""', *linebreak_paragraph(self.docstr), '"""'] if self.docstr else []), *comment([ "This file was auto generated by Styx.", "Do not edit this file directly.", diff --git a/src/styx/backend/python/utils.py b/src/styx/backend/python/utils.py index c35a261..39771a7 100644 --- a/src/styx/backend/python/utils.py +++ b/src/styx/backend/python/utils.py @@ -62,7 +62,9 @@ def param_py_var_to_str( param: ir.IParam, symbol: str, ) -> tuple[str, bool]: - """Return a Python expression that converts the variable to a string or string array + """Python var to str. + + Return a Python expression that converts the variable to a string or string array and a boolean that indicates if the expression value is an array. """ diff --git a/src/styx/frontend/boutiques/core.py b/src/styx/frontend/boutiques/core.py index 33bc4b3..6596dd5 100644 --- a/src/styx/frontend/boutiques/core.py +++ b/src/styx/frontend/boutiques/core.py @@ -294,7 +294,7 @@ class _NumericConstraints: list_length_max: int | None = None -def _collect_constraints(d, input_type): +def _collect_constraints(d: dict, input_type: InputType) -> _NumericConstraints: ret = _NumericConstraints() value_min_exclusive = False value_max_exclusive = False @@ -385,7 +385,7 @@ def _get_urls(bt: dict) -> list[str]: ) -def _collect_outputs(bt, ir_id_lookup, id_counter: IdCounter): +def _collect_outputs(bt: dict, ir_id_lookup: dict[str, ir.IdType], id_counter: IdCounter) -> list[ir.Output]: outputs: list[ir.Output] = [] for bt_output in bt.get("output-files", []): path_template = bt_output["path-template"] @@ -410,7 +410,7 @@ def _collect_outputs(bt, ir_id_lookup, id_counter: IdCounter): return outputs -def _collect_inputs(bt, id_counter): +def _collect_inputs(bt: dict, id_counter: IdCounter) -> tuple[list[ir.ConditionalGroup], dict[str, ir.IdType]]: inputs_lookup = {i["value-key"]: i for i in bt.get("inputs", [])} # maps boutiques 'value-keys' to expressions ir_id_lookup: dict[str, ir.IdType] = {} @@ -476,25 +476,3 @@ def from_boutiques( struct=dstruct, ), ) - - -if __name__ == "__main__": - # json_path = r"C:\Users\floru\Downloads\bet.json" - json_path = r"C:\Users\floru\Downloads\registration.json" - print(json_path) - with open(json_path, "r", encoding="utf-8") as json_file: - json_data = json.load(json_file) - ir_data = from_boutiques(json_data, package_name="afni", package_docs=ir.Documentation(urls=["Helo hehe"])) - from styx.ir.pretty_print import pretty_print - - pretty_print(ir_data) - from styx.ir.stats import stats - - print(stats(ir_data)) - from styx.backend.python.core import to_python - - for py, module_path in to_python([ir_data]): - print("=" * 80) - print("File: " + ".".join(module_path)) - print("-" * 80) - print(py)