Skip to content

Commit

Permalink
Add terminal input and dora echo
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Aug 13, 2024
1 parent aea441b commit 0efd740
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/echo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pt
16 changes: 16 additions & 0 deletions examples/echo/dataflow.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions node-hub/dora-echo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dora echo node

This node will just echo whatever it receives as is.
11 changes: 11 additions & 0 deletions node-hub/dora-echo/dora_echo/__init__.py
Original file line number Diff line number Diff line change
@@ -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."
32 changes: 32 additions & 0 deletions node-hub/dora-echo/dora_echo/main.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions node-hub/dora-echo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tool.poetry]
name = "dora-echo"
version = "0.3.5"
authors = [
"Haixuan Xavier Tao <[email protected]>",
"Enzo Le Van <[email protected]>",
]
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"
5 changes: 2 additions & 3 deletions node-hub/pyarrow-assert/pyarrow_assert/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import argparse
import os
import ast

import numpy as np
import pyarrow as pa

from dora import Node

Expand Down Expand Up @@ -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":
Expand Down
5 changes: 3 additions & 2 deletions node-hub/pyarrow-sender/pyarrow_sender/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import os
import ast

import pyarrow as pa

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions node-hub/terminal-input/README.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 28 additions & 0 deletions node-hub/terminal-input/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tool.poetry]
name = "terminal-input"
version = "0.3.5"
authors = [
"Haixuan Xavier Tao <[email protected]>",
"Enzo Le Van <[email protected]>",
]
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"
11 changes: 11 additions & 0 deletions node-hub/terminal-input/terminal_input/__init__.py
Original file line number Diff line number Diff line change
@@ -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."
74 changes: 74 additions & 0 deletions node-hub/terminal-input/terminal_input/main.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions node-hub/terminal-input/tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_placeholder():
pass

0 comments on commit 0efd740

Please sign in to comment.