Browse Source

Minor template fix

tags/v0.3.9-rc1
haixuantao 1 year ago
parent
commit
52d883e6b5
8 changed files with 66 additions and 42 deletions
  1. +37
    -0
      binaries/cli/src/template/python/__node-name__/README.md
  2. +0
    -0
      binaries/cli/src/template/python/__node-name__/__node_name__/__init__.py
  3. +0
    -0
      binaries/cli/src/template/python/__node-name__/__node_name__/__main__.py
  4. +3
    -3
      binaries/cli/src/template/python/__node-name__/__node_name__/main.py
  5. +4
    -4
      binaries/cli/src/template/python/__node-name__/pyproject.toml
  6. +1
    -1
      binaries/cli/src/template/python/__node-name__/tests/test___node_name__.py
  7. +21
    -25
      binaries/cli/src/template/python/mod.rs
  8. +0
    -9
      binaries/cli/src/template/python/node-name/README.md

+ 37
- 0
binaries/cli/src/template/python/__node-name__/README.md View File

@@ -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

binaries/cli/src/template/python/node-name/node_name/__init__.py → binaries/cli/src/template/python/__node-name__/__node_name__/__init__.py View File


binaries/cli/src/template/python/node-name/node_name/__main__.py → binaries/cli/src/template/python/__node-name__/__node_name__/__main__.py View File


binaries/cli/src/template/python/node-name/node_name/main.py → binaries/cli/src/template/python/__node-name__/__node_name__/main.py View File

@@ -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={}
)



binaries/cli/src/template/python/node-name/pyproject.toml → binaries/cli/src/template/python/__node-name__/pyproject.toml View File

@@ -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"]

binaries/cli/src/template/python/node-name/tests/test_node_name.py → binaries/cli/src/template/python/__node-name__/tests/test___node_name__.py View File

@@ -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):

+ 21
- 25
binaries/cli/src/template/python/mod.rs View File

@@ -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<PathBuf>) -> 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");


+ 0
- 9
binaries/cli/src/template/python/node-name/README.md View File

@@ -1,9 +0,0 @@
# name

## YAML Specification

## Examples

## License

name's code are released under the MIT License

Loading…
Cancel
Save