diff --git a/binaries/cli/src/template/python/__node-name__/README.md b/binaries/cli/src/template/python/__node-name__/README.md new file mode 100644 index 00000000..81b12cc0 --- /dev/null +++ b/binaries/cli/src/template/python/__node-name__/README.md @@ -0,0 +1,37 @@ +# Node Name + +## Getting started + +- Install it with pip: + +```bash +pip install -e . +``` + +## Contribution Guide + +- Format with [black](https://github.com/psf/black): + +```bash +black . # Format +``` + +- Lint with [pylint](https://github.com/pylint-dev/pylint): + +```bash +pylint --disable=C,R --ignored-modules=cv2 . # Lint +``` + +- Test with [pytest](https://github.com/pytest-dev/pytest) + +```bash +pytest . # Test +``` + +## YAML Specification + +## Examples + +## License + +Node Name's code are released under the MIT License diff --git a/binaries/cli/src/template/python/node-name/node_name/__init__.py b/binaries/cli/src/template/python/__node-name__/__node_name__/__init__.py similarity index 100% rename from binaries/cli/src/template/python/node-name/node_name/__init__.py rename to binaries/cli/src/template/python/__node-name__/__node_name__/__init__.py diff --git a/binaries/cli/src/template/python/node-name/node_name/__main__.py b/binaries/cli/src/template/python/__node-name__/__node_name__/__main__.py similarity index 100% rename from binaries/cli/src/template/python/node-name/node_name/__main__.py rename to binaries/cli/src/template/python/__node-name__/__node_name__/__main__.py diff --git a/binaries/cli/src/template/python/node-name/node_name/main.py b/binaries/cli/src/template/python/__node-name__/__node_name__/main.py similarity index 67% rename from binaries/cli/src/template/python/node-name/node_name/main.py rename to binaries/cli/src/template/python/__node-name__/__node_name__/main.py index ae95012c..823e2e09 100644 --- a/binaries/cli/src/template/python/node-name/node_name/main.py +++ b/binaries/cli/src/template/python/__node-name__/__node_name__/main.py @@ -15,10 +15,10 @@ def main(): metadata: {event["metadata"]}""" ) - else: - # Warning: Make sure to add the output event_id within the dataflow. + elif event["id"] == "my_input_id": + # Warning: Make sure to add my_output_id and my_input_id within the dataflow. node.send_output( - output_id="event_id", data=pa.array([1, 2, 3]), metadata={} + output_id="my_output_id", data=pa.array([1, 2, 3]), metadata={} ) diff --git a/binaries/cli/src/template/python/node-name/pyproject.toml b/binaries/cli/src/template/python/__node-name__/pyproject.toml similarity index 79% rename from binaries/cli/src/template/python/node-name/pyproject.toml rename to binaries/cli/src/template/python/__node-name__/pyproject.toml index cb94c6fd..a54fb19e 100644 --- a/binaries/cli/src/template/python/node-name/pyproject.toml +++ b/binaries/cli/src/template/python/__node-name__/pyproject.toml @@ -1,13 +1,13 @@ [tool.poetry] -name = "node-name" +name = "__node-name__" version = "0.0.0" authors = ["author"] description = "Node Name" license = "MIT License" homepage = "https://github.com/dora-rs/dora.git" -documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/node-name/README.md" +documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/__node-name__/README.md" readme = "README.md" -packages = [{ include = "node_name" }] +packages = [{ include = "__node_name__" }] [tool.poetry.dependencies] dora-rs = "^0.3.6" @@ -21,7 +21,7 @@ pylint = ">= 3.3.2" black = ">= 24.10" [tool.poetry.scripts] -node-name = "node_name.main:main" +__node-name__ = "__node_name__.main:main" [build-system] requires = ["poetry-core>=1.8.0"] diff --git a/binaries/cli/src/template/python/node-name/tests/test_node_name.py b/binaries/cli/src/template/python/__node-name__/tests/test___node_name__.py similarity index 83% rename from binaries/cli/src/template/python/node-name/tests/test_node_name.py rename to binaries/cli/src/template/python/__node-name__/tests/test___node_name__.py index 1ed74b07..7fefda95 100644 --- a/binaries/cli/src/template/python/node-name/tests/test_node_name.py +++ b/binaries/cli/src/template/python/__node-name__/tests/test___node_name__.py @@ -2,7 +2,7 @@ import pytest def test_import_main(): - from node_name.main import main + from __node_name__.main import main # Check that everything is working, and catch dora Runtime Exception as we're not running in a dora dataflow. with pytest.raises(RuntimeError): diff --git a/binaries/cli/src/template/python/mod.rs b/binaries/cli/src/template/python/mod.rs index 778d15c4..911141eb 100644 --- a/binaries/cli/src/template/python/mod.rs +++ b/binaries/cli/src/template/python/mod.rs @@ -4,12 +4,12 @@ use std::{ path::{Path, PathBuf}, }; -const MAIN_PY: &str = include_str!("node-name/node_name/main.py"); -const _MAIN_PY: &str = include_str!("node-name/node_name/__main__.py"); -const _INIT_PY: &str = include_str!("node-name/node_name/__init__.py"); -const _TEST_PY: &str = include_str!("node-name/tests/test_node_name.py"); -const PYPROJECT_TOML: &str = include_str!("node-name/pyproject.toml"); -const README_MD: &str = include_str!("node-name/README.md"); +const MAIN_PY: &str = include_str!("__node-name__/__node_name__/main.py"); +const _MAIN_PY: &str = include_str!("__node-name__/__node_name__/__main__.py"); +const _INIT_PY: &str = include_str!("__node-name__/__node_name__/__init__.py"); +const _TEST_PY: &str = include_str!("__node-name__/tests/test___node_name__.py"); +const PYPROJECT_TOML: &str = include_str!("__node-name__/pyproject.toml"); +const README_MD: &str = include_str!("__node-name__/README.md"); const TALKER_PY: &str = include_str!("talker/talker-template.py"); const LISTENER_PY: &str = include_str!("listener/listener-template.py"); @@ -29,8 +29,9 @@ pub fn create(args: crate::CommandNew) -> eyre::Result<()> { } fn replace_space(file: &str, name: &str) -> String { - let file = file.replace("node-name", &name.replace(" ", "-")); - file.replace("node_name", &name.replace(" ", "_")) + let mut file = file.replace("__node-name__", &name.replace(" ", "-")); + file = file.replace("__node_name__", &name.replace("-", "_").replace(" ", "_")); + file.replace("Node Name", &name) } fn create_custom_node( name: String, @@ -39,15 +40,15 @@ fn create_custom_node( ) -> Result<(), eyre::ErrReport> { // create directories let root = path.unwrap_or_else(|| PathBuf::from(name.replace(" ", "-"))); - let module_path = root.join(name.replace(" ", "_")); + let module_path = root.join(name.replace(" ", "_").replace("-", "_")); fs::create_dir(&root) - .with_context(|| format!("failed to create directory `{}`", &root.display()))?; + .with_context(|| format!("failed to create root directory `{}`", &root.display()))?; fs::create_dir(&module_path) - .with_context(|| format!("failed to create directory `{}`", &root.display()))?; + .with_context(|| format!("failed to create module directory `{}`", &root.display()))?; fs::create_dir(&root.join("tests")) - .with_context(|| format!("failed to create directory `{}`", &root.display()))?; + .with_context(|| format!("failed to create tests directory `{}`", &root.display()))?; // PYPROJECT.toml let node_path = root.join("pyproject.toml"); @@ -57,7 +58,7 @@ fn create_custom_node( // README.md let node_path = root.join("README.md"); - fs::write(&node_path, README_MD.replace("name", &name)) + fs::write(&node_path, README_MD.replace("Node Name", &name)) .with_context(|| format!("failed to write `{}`", node_path.display()))?; // main.py @@ -75,7 +76,7 @@ fn create_custom_node( fs::write(&node_path, _INIT_PY) .with_context(|| format!("failed to write `{}`", node_path.display()))?; - // tests/tests_node_name.py + // tests/tests___node_name__.py let node_path = root .join("tests") .join(format!("test_{}.py", name.replace(" ", "_"))); @@ -87,16 +88,11 @@ fn create_custom_node( "Created new Python node `{name}` at {}", Path::new(".").join(&root).display() ); - println!( - " pip install -e {} # Install", - Path::new(".").join(&root).display() - ); - println!(" black {} # Format", Path::new(".").join(&root).display()); - println!( - " pylint --disable=C,R {} # Lint", - Path::new(".").join(&root).display() - ); - println!(" pytest {} # Test", Path::new(".").join(&root).display()); + println!(" cd {}", Path::new(".").join(&root).display()); + println!(" pip install -e . # Install",); + println!(" black . # Format"); + println!(" pylint --disable=C,R . # Lint",); + println!(" pytest . # Test"); Ok(()) } @@ -114,7 +110,7 @@ fn create_dataflow(name: String, path: Option) -> Result<(), eyre::ErrR // create directories let root = path.as_deref().unwrap_or_else(|| Path::new(&name)); fs::create_dir(root) - .with_context(|| format!("failed to create directory `{}`", root.display()))?; + .with_context(|| format!("failed to create module directory `{}`", root.display()))?; let dataflow_yml = DATAFLOW_YML.replace("___name___", &name); let dataflow_yml_path = root.join("dataflow.yml"); diff --git a/binaries/cli/src/template/python/node-name/README.md b/binaries/cli/src/template/python/node-name/README.md deleted file mode 100644 index 18a052cc..00000000 --- a/binaries/cli/src/template/python/node-name/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# name - -## YAML Specification - -## Examples - -## License - -name's code are released under the MIT License