-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0947e5
commit 36c01c1
Showing
4 changed files
with
106 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
import navi | ||
|
||
from .group import NestedIdGroup | ||
from .input import BaseInput | ||
from .output import BaseOutput | ||
from .types import FeatureId, InputId, NodeKind, OutputId, RunFn | ||
|
||
|
||
class IteratorInputInfo: | ||
def __init__( | ||
self, | ||
inputs: int | InputId | list[int] | list[InputId] | list[int | InputId], | ||
length_type: navi.ExpressionJson = "uint", | ||
) -> None: | ||
self.inputs: list[InputId] = ( | ||
[InputId(x) for x in inputs] | ||
if isinstance(inputs, list) | ||
else [InputId(inputs)] | ||
) | ||
self.length_type: navi.ExpressionJson = length_type | ||
|
||
def to_dict(self): | ||
return { | ||
"inputs": self.inputs, | ||
"lengthType": self.length_type, | ||
} | ||
|
||
|
||
class IteratorOutputInfo: | ||
def __init__( | ||
self, | ||
outputs: int | OutputId | list[int] | list[OutputId] | list[int | OutputId], | ||
length_type: navi.ExpressionJson = "uint", | ||
) -> None: | ||
self.outputs: list[OutputId] = ( | ||
[OutputId(x) for x in outputs] | ||
if isinstance(outputs, list) | ||
else [OutputId(outputs)] | ||
) | ||
self.length_type: navi.ExpressionJson = length_type | ||
|
||
def to_dict(self): | ||
return { | ||
"outputs": self.outputs, | ||
"lengthType": self.length_type, | ||
} | ||
|
||
|
||
@dataclass(frozen=True) | ||
class NodeData: | ||
schema_id: str | ||
description: str | ||
see_also: list[str] | ||
name: str | ||
icon: str | ||
kind: NodeKind | ||
|
||
inputs: list[BaseInput] | ||
outputs: list[BaseOutput] | ||
group_layout: list[InputId | NestedIdGroup] | ||
|
||
iterator_inputs: list[IteratorInputInfo] | ||
iterator_outputs: list[IteratorOutputInfo] | ||
|
||
side_effects: bool | ||
deprecated: bool | ||
node_context: bool | ||
features: list[FeatureId] | ||
|
||
run: RunFn | ||
|
||
@property | ||
def single_iterator_input(self) -> IteratorInputInfo: | ||
assert len(self.iterator_inputs) == 1 | ||
return self.iterator_inputs[0] | ||
|
||
@property | ||
def single_iterator_output(self) -> IteratorOutputInfo: | ||
assert len(self.iterator_outputs) == 1 | ||
return self.iterator_outputs[0] |