You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.4 kB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Dora Node Hub
  2. This hub contains useful pre-built nodes for Dora.
  3. # Python
  4. ## Add a new python node
  5. - To work on a new node, start by:
  6. ```bash
  7. cd node-hub
  8. dora new your-node-name --lang python --kind node
  9. cd ./your-node-name
  10. uv venv --seed -p 3.11
  11. uv pip install -e . # Install
  12. uv run ruff check . --fix # Format
  13. uv run ruff check . # Lint
  14. uv run pytest . # Test
  15. ```
  16. - To add a python dependency just do:
  17. ```bash
  18. uv add numpy # for example
  19. ```
  20. > The package is then added to your `pyproject.toml`
  21. - Modify the code within `main.py` in your liking.
  22. - Create a PR and let the CI/CD run test on it 🙋
  23. ## Structure
  24. The structure of the node hub is as follows (please use the same structure if you need to add a new node):
  25. ```
  26. node-hub/
  27. └── your-node/
  28. ├── README.md
  29. ├── your-node
  30. │ ├── __init__.py
  31. │ ├── __main__.py
  32. │ └── main.py
  33. ├── pyproject.toml
  34. └── tests
  35. └── test_<your-node>.py
  36. ```
  37. The idea is to make a `pyproject.toml` file that will install the required dependencies for the node **and** attach main
  38. function of the node inside a callable script in your environment.
  39. To do so, you will need to add a `main` function inside the `main.py` file.
  40. ```python
  41. def main():
  42. pass
  43. ```
  44. And then you will need to adapt the following `pyproject.toml` file:
  45. ```toml
  46. [project]
  47. name = "[name of the node e.g. video-encoder, with '-' to replace spaces]"
  48. version = "0.1"
  49. authors = [{ name = "[Pseudo/Name]", email = "[email]" }]
  50. description = "Dora Node for []"
  51. readme = "README.md"
  52. license = { text = "MIT" }
  53. dependencies = [
  54. "dora-rs >= 0.3.8",
  55. ]
  56. [project.scripts]
  57. [name of the node with '-' to replace spaces] = "[name of the node with '_' to replace spaces].main:main"
  58. [tool.ruff.lint]
  59. extend-select = [
  60. "D", # pydocstyle
  61. "UP", # Ruff's UP rule
  62. "PERF", # Ruff's PERF rule
  63. "RET", # Ruff's RET rule
  64. "RSE", # Ruff's RSE rule
  65. "NPY", # Ruff's NPY rule
  66. "N", # Ruff's N rule
  67. "I", # Ruff's I rule
  68. ]
  69. ```
  70. Finally, the README.md file should explicit all inputs/outputs of the node and how to configure it in the YAML file.
  71. ## Example
  72. ```toml
  73. [project]
  74. name = "opencv-plot"
  75. version = "0.1"
  76. authors = [
  77. "Haixuan Xavier Tao <tao.xavier@outlook.com>",
  78. "Enzo Le Van <dev@enzo-le-van.fr>"
  79. ]
  80. description = "Dora Node for plotting data with OpenCV"
  81. readme = "README.md"
  82. license = { text = "MIT" }
  83. requires-python = ">=3.7"
  84. dependencies = [
  85. "dora-rs >= 0.3.8",
  86. ]
  87. [dependency-groups]
  88. dev = ["pytest >=8.1.1", "ruff >=0.9.1"]
  89. [project.scripts]
  90. opencv-plot = "opencv_plot.main:main"
  91. [tool.ruff.lint]
  92. extend-select = [
  93. "D", # pydocstyle
  94. "UP", # Ruff's UP rule
  95. "PERF", # Ruff's PERF rule
  96. "RET", # Ruff's RET rule
  97. "RSE", # Ruff's RSE rule
  98. "NPY", # Ruff's NPY rule
  99. "N", # Ruff's N rule
  100. "I", # Ruff's I rule
  101. ]
  102. ```
  103. ## Adding git dependency
  104. - If a git repository is added as submodule. Proper path should be added in `pyproject.toml` inorder to make sure that linting and testing are exempted for that dependency.
  105. - A very good example of how this can be done is as follows
  106. Correct approach:
  107. ```toml
  108. [tool.ruff]
  109. exclude = ["dora_magma/Magma"]
  110. [tool.black]
  111. extend.exclude = "dora_magma/Magma"
  112. ```
  113. Incorrect Approach:
  114. ```toml
  115. [tool.ruff]
  116. exclude = ["dora-magma/dora_magma/Magma"]
  117. [tool.black]
  118. extend.exclude = "dora_magma/Magma"
  119. ```
  120. ##### Note:
  121. - `dora-magma` is root folder of the node.
  122. # Rust
  123. ## Add a new rust node
  124. ```bash
  125. cd node-hub
  126. dora new your-node-name --lang rust --kind node
  127. cd ./your-node-name
  128. ```
  129. ## Steps Before Building
  130. - Before building the node, make sure to add your node to the workspace members list in the root `Cargo.toml` file:
  131. ```
  132. [workspace]
  133. members = [
  134. ...
  135. "node-hub/your-node-name"
  136. ]
  137. ```
  138. - Also change the `Cargo.toml` file in your node to use the workspace version of dora-node-api:
  139. ```
  140. [dependencies]
  141. dora-node-api = { workspace = true }
  142. ```
  143. ## Structure
  144. The structure of the node hub for Rust is as follows (please use the same structure if you need to add a new node):
  145. ```
  146. node-hub/
  147. └── your-node/
  148. ├── Cargo.toml
  149. ├── README.md
  150. └── src/
  151. └── main.rs
  152. ```
  153. The README.md file should explicit all inputs/outputs of the node and how to configure it in the YAML file.
  154. ## License
  155. This project is licensed under Apache-2.0. Check out [NOTICE.md](../NOTICE.md) for more information.