Skip to content

Commit

Permalink
IR progress
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Sep 6, 2024
1 parent 6daecb8 commit 0318a6f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/styx/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Styx Python backend."""
6 changes: 2 additions & 4 deletions src/styx/backend/python/pycodegen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.",
Expand Down
4 changes: 3 additions & 1 deletion src/styx/backend/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down
28 changes: 3 additions & 25 deletions src/styx/frontend/boutiques/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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] = {}
Expand Down Expand Up @@ -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)

0 comments on commit 0318a6f

Please sign in to comment.