From f30e225a7dfa50e5c9097547386aa0700cf4832e Mon Sep 17 00:00:00 2001 From: Florian Rupprecht Date: Thu, 5 Sep 2024 14:32:18 -0400 Subject: [PATCH] IR progress --- src/styx/backend/python/__init__.py | 2 +- src/styx/backend/python/constraints.py | 2 +- src/styx/backend/python/lookup.py | 2 +- src/styx/frontend/boutiques/__init__.py | 4 ++-- src/styx/frontend/boutiques/core.py | 5 +---- src/styx/ir/core.py | 10 +++++----- src/styx/ir/dyn.py | 3 +-- 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/styx/backend/python/__init__.py b/src/styx/backend/python/__init__.py index 146306d..2cec5fb 100644 --- a/src/styx/backend/python/__init__.py +++ b/src/styx/backend/python/__init__.py @@ -1,3 +1,3 @@ """Python wrapper backend.""" -from .core import to_python +from .core import to_python as to_python diff --git a/src/styx/backend/python/constraints.py b/src/styx/backend/python/constraints.py index 85e71ce..5ad9a71 100644 --- a/src/styx/backend/python/constraints.py +++ b/src/styx/backend/python/constraints.py @@ -1,6 +1,6 @@ +import styx.ir.core as ir from styx.backend.python.lookup import LookupParam from styx.backend.python.pycodegen.core import LineBuffer, PyFunc, indent -import styx.ir.core as ir def _generate_raise_value_err(obj: str, expectation: str, reality: str | None = None) -> LineBuffer: diff --git a/src/styx/backend/python/lookup.py b/src/styx/backend/python/lookup.py index 266644c..0598309 100644 --- a/src/styx/backend/python/lookup.py +++ b/src/styx/backend/python/lookup.py @@ -1,6 +1,6 @@ import styx.ir.core as ir from styx.backend.python.pycodegen.scope import Scope -from styx.backend.python.pycodegen.utils import python_snakify, python_pascalize +from styx.backend.python.pycodegen.utils import python_pascalize, python_snakify from styx.backend.python.utils import iter_params_recursively, param_py_type diff --git a/src/styx/frontend/boutiques/__init__.py b/src/styx/frontend/boutiques/__init__.py index 426278a..f1522bd 100644 --- a/src/styx/frontend/boutiques/__init__.py +++ b/src/styx/frontend/boutiques/__init__.py @@ -1,3 +1,3 @@ -"""Boutiques frontend""" +"""Boutiques frontend.""" -from .core import from_boutiques +from .core import from_boutiques as from_boutiques diff --git a/src/styx/frontend/boutiques/core.py b/src/styx/frontend/boutiques/core.py index 4ec01aa..f38239d 100644 --- a/src/styx/frontend/boutiques/core.py +++ b/src/styx/frontend/boutiques/core.py @@ -446,9 +446,6 @@ def _collect_inputs(bt, id_counter): def from_boutiques(tool: dict, package_name: str) -> ir.Interface: """Convert a Boutiques tool to a Styx descriptor.""" - if not (tool_name := tool.get("name")): - raise ValueError(f"name is missing for tool '{tool}'") - hash_ = _hash_from_boutiques(tool) docker: str | None = None @@ -463,7 +460,7 @@ def from_boutiques(tool: dict, package_name: str) -> ir.Interface: uid=f"{hash_}.boutiques", package=ir.Package( name=package_name, - version="1.0", + version=tool.get("tool-version"), docker=docker, ), command=ir.PStruct( diff --git a/src/styx/ir/core.py b/src/styx/ir/core.py index 38b9eec..9524313 100644 --- a/src/styx/ir/core.py +++ b/src/styx/ir/core.py @@ -1,7 +1,7 @@ import dataclasses -import typing from abc import ABC from dataclasses import dataclass +from typing import Any, Generator @dataclass @@ -58,7 +58,7 @@ class IParam(ABC): class IOptional(ABC): - class SetToNoneAble: + class SetToNoneAble: # noqa pass SetToNone = SetToNoneAble() @@ -210,7 +210,7 @@ class PBoolListOpt(IBool, IList, IParam, IOptional): class Carg: tokens: list[IParam | str] = dataclasses.field(default_factory=list) - def iter_params(self): + def iter_params(self) -> Generator[IParam, Any, None]: for token in self.tokens: if isinstance(token, IParam): yield token @@ -220,7 +220,7 @@ def iter_params(self): class ConditionalGroup: cargs: list[Carg] = dataclasses.field(default_factory=list) - def iter_params(self): + def iter_params(self) -> Generator[IParam, Any, None]: for carg in self.cargs: yield from carg.iter_params() @@ -232,7 +232,7 @@ class DStruct: """(group (cargs (join str+params))) """ docs: Documentation | None = None - def iter_params(self): + def iter_params(self) -> Generator[IParam, Any, None]: for group in self.groups: yield from group.iter_params() diff --git a/src/styx/ir/dyn.py b/src/styx/ir/dyn.py index c6f5b7a..eeedbe6 100644 --- a/src/styx/ir/dyn.py +++ b/src/styx/ir/dyn.py @@ -10,10 +10,9 @@ def dyn_param( dyn_type: typing.Literal["int", "float", "str", "file", "bool", "struct", "struct_union"], dyn_list: bool, dyn_optional: bool, - **kwargs, + **kwargs, # noqa ) -> ir.IParam: """Convenience function that allows dynamic param class creation.""" - cls = { ("int", True, True): ir.PIntListOpt, ("int", True, False): ir.PIntList,