diff --git a/examples/echo/.gitignore b/examples/echo/.gitignore new file mode 100644 index 00000000..eede66d8 --- /dev/null +++ b/examples/echo/.gitignore @@ -0,0 +1 @@ +*.pt \ No newline at end of file diff --git a/examples/echo/dataflow.yml b/examples/echo/dataflow.yml new file mode 100644 index 00000000..20adefcb --- /dev/null +++ b/examples/echo/dataflow.yml @@ -0,0 +1,16 @@ +nodes: + - id: terminal-input + build: pip install -e ../../node-hub/terminal-input + path: dynamic + outputs: + - data + inputs: + echo: dora-echo/echo + + - id: dora-echo + build: pip install -e ../../node-hub/dora-echo + path: dora-echo + inputs: + input: terminal-input/data + outputs: + - echo diff --git a/node-hub/dora-echo/README.md b/node-hub/dora-echo/README.md new file mode 100644 index 00000000..feeef1f8 --- /dev/null +++ b/node-hub/dora-echo/README.md @@ -0,0 +1,3 @@ +# Dora echo node + +This node will just echo whatever it receives as is. diff --git a/node-hub/dora-echo/dora_echo/__init__.py b/node-hub/dora-echo/dora_echo/__init__.py new file mode 100644 index 00000000..ac3cbef9 --- /dev/null +++ b/node-hub/dora-echo/dora_echo/__init__.py @@ -0,0 +1,11 @@ +import os + +# Define the path to the README file relative to the package directory +readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md") + +# Read the content of the README file +try: + with open(readme_path, "r", encoding="utf-8") as f: + __doc__ = f.read() +except FileNotFoundError: + __doc__ = "README file not found." diff --git a/node-hub/dora-echo/dora_echo/main.py b/node-hub/dora-echo/dora_echo/main.py new file mode 100644 index 00000000..b01eb688 --- /dev/null +++ b/node-hub/dora-echo/dora_echo/main.py @@ -0,0 +1,32 @@ +import argparse +import os +from dora import Node + +RUNNER_CI = True if os.getenv("CI") == "true" else False + + +def main(): + + # Handle dynamic nodes, ask for the name of the node in the dataflow, and the same values as the ENV variables. + parser = argparse.ArgumentParser(description="Simple arrow sender") + + parser.add_argument( + "--name", + type=str, + required=False, + help="The name of the node in the dataflow.", + default="echo", + ) + args = parser.parse_args() + + node = Node( + args.name + ) # provide the name to connect to the dataflow if dynamic node + + for event in node: + if event["type"] == "INPUT": + node.send_output("echo", event["value"]) + + +if __name__ == "__main__": + main() diff --git a/node-hub/dora-echo/pyproject.toml b/node-hub/dora-echo/pyproject.toml new file mode 100644 index 00000000..f9d054c4 --- /dev/null +++ b/node-hub/dora-echo/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "dora-echo" +version = "0.3.5" +authors = [ + "Haixuan Xavier Tao ", + "Enzo Le Van ", +] +description = "Dora echo" +license = "MIT License" +homepage = "https://github.com/dora-rs/dora.git" +documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/dora-echo/README.md" +readme = "README.md" +packages = [{ include = "dora_echo" }] + +[tool.poetry.dependencies] +dora-rs = "0.3.5" +numpy = "< 2.0.0" +pyarrow = ">= 5.0.0" + +[tool.poetry.scripts] +dora-echo = "dora_echo.main:main" + +[build-system] +requires = ["poetry-core>=1.8.0"] +build-backend = "poetry.core.masonry.api" + +[project] +readme = "README.md" diff --git a/node-hub/pyarrow-assert/pyarrow_assert/main.py b/node-hub/pyarrow-assert/pyarrow_assert/main.py index 289086df..d2529da9 100644 --- a/node-hub/pyarrow-assert/pyarrow_assert/main.py +++ b/node-hub/pyarrow-assert/pyarrow_assert/main.py @@ -1,8 +1,7 @@ import argparse import os +import ast -import numpy as np -import pyarrow as pa from dora import Node @@ -37,7 +36,7 @@ def main(): args.name ) # provide the name to connect to the dataflow if dynamic node - assert_data = eval(data) + assert_data = ast.literal_eval(data) for event in node: if event["type"] == "INPUT": diff --git a/node-hub/pyarrow-sender/pyarrow_sender/main.py b/node-hub/pyarrow-sender/pyarrow_sender/main.py index 379621b8..66065ad0 100644 --- a/node-hub/pyarrow-sender/pyarrow_sender/main.py +++ b/node-hub/pyarrow-sender/pyarrow_sender/main.py @@ -1,5 +1,6 @@ import argparse import os +import ast import pyarrow as pa @@ -41,7 +42,7 @@ def main(): data = input( "Provide the data you want to send: ", ) - data = eval(data) + data = ast.literal_eval(data) if isinstance(data, list): data = pa.array(data) # initialize pyarrow array elif isinstance(data, str): @@ -54,7 +55,7 @@ def main(): data = pa.array(data) # initialize pyarrow array node.send_output("data", data) else: - data = eval(data) + data = ast.literal_eval(data) if isinstance(data, list): data = pa.array(data) # initialize pyarrow array elif isinstance(data, str): diff --git a/node-hub/terminal-input/README.md b/node-hub/terminal-input/README.md new file mode 100644 index 00000000..3c88037e --- /dev/null +++ b/node-hub/terminal-input/README.md @@ -0,0 +1,3 @@ +# Dora Node for sending terminal input data. + +This node send the data that is given to him within a terminal window. diff --git a/node-hub/terminal-input/pyproject.toml b/node-hub/terminal-input/pyproject.toml new file mode 100644 index 00000000..6e35bc38 --- /dev/null +++ b/node-hub/terminal-input/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "terminal-input" +version = "0.3.5" +authors = [ + "Haixuan Xavier Tao ", + "Enzo Le Van ", +] +description = "Dora terminal input" +license = "MIT License" +homepage = "https://github.com/dora-rs/dora.git" +documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/terminal-input/README.md" +readme = "README.md" +packages = [{ include = "terminal_input" }] + +[tool.poetry.dependencies] +dora-rs = "0.3.5" +numpy = "< 2.0.0" +pyarrow = ">= 5.0.0" + +[tool.poetry.scripts] +terminal-input = "terminal_input.main:main" + +[build-system] +requires = ["poetry-core>=1.8.0"] +build-backend = "poetry.core.masonry.api" + +[project] +readme = "README.md" diff --git a/node-hub/terminal-input/terminal_input/__init__.py b/node-hub/terminal-input/terminal_input/__init__.py new file mode 100644 index 00000000..ac3cbef9 --- /dev/null +++ b/node-hub/terminal-input/terminal_input/__init__.py @@ -0,0 +1,11 @@ +import os + +# Define the path to the README file relative to the package directory +readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md") + +# Read the content of the README file +try: + with open(readme_path, "r", encoding="utf-8") as f: + __doc__ = f.read() +except FileNotFoundError: + __doc__ = "README file not found." diff --git a/node-hub/terminal-input/terminal_input/main.py b/node-hub/terminal-input/terminal_input/main.py new file mode 100644 index 00000000..4b03c135 --- /dev/null +++ b/node-hub/terminal-input/terminal_input/main.py @@ -0,0 +1,74 @@ +import argparse +import os +import ast + +import pyarrow as pa + +from dora import Node + +RUNNER_CI = True if os.getenv("CI") == "true" else False + + +def main(): + + # Handle dynamic nodes, ask for the name of the node in the dataflow, and the same values as the ENV variables. + parser = argparse.ArgumentParser(description="Simple arrow sender") + + parser.add_argument( + "--name", + type=str, + required=False, + help="The name of the node in the dataflow.", + default="terminal-input", + ) + parser.add_argument( + "--data", + type=str, + required=False, + help="Arrow Data as string.", + default=None, + ) + + args = parser.parse_args() + + data = os.getenv("DATA", args.data) + + node = Node( + args.name + ) # provide the name to connect to the dataflow if dynamic node + + if data is None and os.getenv("DORA_NODE_CONFIG") is None: + while True: + data = input( + "Provide the data you want to send: ", + ) + data = ast.literal_eval(data) + if isinstance(data, list): + data = pa.array(data) # initialize pyarrow array + elif isinstance(data, str): + data = pa.array([data]) + elif isinstance(data, int): + data = pa.array([data]) + elif isinstance(data, float): + data = pa.array([data]) + elif isinstance(data, dict): + data = pa.array([data]) + else: + data = pa.array(data) # initialize pyarrow array + node.send_output("data", data) + event = node.next(timeout=0.2) + if event is not None: + print(f"Received: {event['value'].to_pylist()}") + else: + data = ast.literal_eval(data) + if isinstance(data, list): + data = pa.array(data) # initialize pyarrow array + elif isinstance(data, str): + data = pa.array([data]) + else: + data = pa.array(data) # initialize pyarrow array + node.send_output("data", data) + + +if __name__ == "__main__": + main() diff --git a/node-hub/terminal-input/tests/test.py b/node-hub/terminal-input/tests/test.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/node-hub/terminal-input/tests/test.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass