Skip to content

Commit

Permalink
feat(rust): wrap_pyfunction "process_rule_pack" in libcore module
Browse files Browse the repository at this point in the history
  • Loading branch information
HsiangNianian committed Jun 4, 2024
1 parent 28a7b2e commit 09413f0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 37 deletions.
70 changes: 47 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,55 @@ HydroRoll-Core <=> 水系核心 |Structure|
- 📚 *PDF* 生成,结合自定义 *PDF* 模板,能够生成符合需求的 *PDF* 书籍。
- 🌏 离线文档与在线协作站点,使用 *Sphinx* 框架与 *Vue* 技术栈生成本地文档与在线站点。

架构设计
--------

核心模块 ``corelib``

包含 *CLI* 界面,用于单独使用。
包含 *REST API* 和 *WebSocket* 通信模块,以便其他语言能够接入和与之交互。
集成请求处理模块,确保能够处理大量请求。

规则包加载模块 ``Rule Pack Loading Module``

负责读取约定式的规则包。
利用并行处理技术,可通过Rust实现以提高性能。

PDF生成模块 ``PDF Generation Module``

将规则包作为输入,结合高度自定义的PDF模板,生成符合要求的PDF书籍。

文档站点生成模块 ``Documentation Site Generation Module``

使用Sphinx框架生成本地在线文档站点。

其他功能模块 ``Other Feature Modules``
架构设计
-------

.. code-block:: mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
具象化模型
----------

.. code-block:: stl
solid cube_corner
facet normal 0.0 -1.0 0.0
outer loop
vertex 0.0 0.0 0.0
vertex 1.0 0.0 0.0
vertex 0.0 0.0 1.0
endloop
endfacet
facet normal 0.0 0.0 -1.0
outer loop
vertex 0.0 0.0 0.0
vertex 0.0 1.0 0.0
vertex 1.0 0.0 0.0
endloop
endfacet
facet normal -1.0 0.0 0.0
outer loop
vertex 0.0 0.0 0.0
vertex 0.0 0.0 1.0
vertex 0.0 1.0 0.0
endloop
endfacet
facet normal 0.577 0.577 0.577
outer loop
vertex 1.0 0.0 0.0
vertex 0.0 1.0 0.0
vertex 0.0 0.0 1.0
endloop
endfacet
endsolid
包括尚未确定的其他功能,如文档生成、数据分析等。
----

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
extlinks = {
"issue": ("https://github.com/HydroRoll-Team/HydroRollCore/%s", "issue %s"),
"doc": ("https://core.hydroroll.team/en/latest/%s", "pages/%s"),
"doc": ("https://core.hydroroll.team/zh-cn/latest/%s", "pages/%s"),
}
source_suffix = {
".rst": "restructuredtext",
Expand Down
3 changes: 1 addition & 2 deletions examples/BRP/src/character.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import inspect
from hydro_roll_core.development import Character
from typing import Literal, List, Tuple, Union, Dict, Generic, Optional

from typing import Literal, List, Tuple, Union, Dict, Generic, Optional, TYPE_CHECKING

class Identity:
"""
Expand Down
5 changes: 3 additions & 2 deletions hydro_roll_core/libcore.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class libcore:
"""Core library for hydro roll"""

def __init__(self): ...
def sum_as_string(self, a: int, b: int) -> str:
"""sum two numbers and return the result as a string"""

def process_rule_pack(rule_pack: str) -> str:
...
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["maturin>=1.4,<2.0"]
build-backend = "maturin"

[project]
name = "hydro_roll_core"
name = "hydro-roll-core"
dynamic = ["version"]
description = "Core of HydroRoll SDK."
authors = [{ name = "简律纯", email = "[email protected]" }]
Expand All @@ -12,7 +12,7 @@ dependencies = [
]
requires-python = ">=3.9"
readme = "README.rst"
license = { text = "MIT" }
license = { text = " AGPL-3.0" }

[project.urls]
homepage = "https://core.hydroroll.team/"
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
fn process_rule_pack(rule_pack: &str) -> PyResult<String> {
// 处理规则包的逻辑
Ok(format!("Processed rule pack: {}", rule_pack))
}

/// A Python module implemented in Rust.
#[pymodule]
#[pyo3(name = "libcore")]
fn corelib(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
fn libcore(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(process_rule_pack, m)?)?;
Ok(())
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use lib::process_rule_pack;

fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <rule_pack>", args[0]);
std::process::exit(1);
}
match process_rule_pack(&args[1]) {
Ok(result) => println!("Result: {}", result),
Err(e) => eprintln!("Error: {}", e),
}
}
11 changes: 9 additions & 2 deletions tests/test_corelib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from hydro_roll_core import libcore

cb = libcore()
cb.sum_as_string(1, 2)
cb = libcore

def main():
rule_pack = "example_rule_pack"
result = cb.process_rule_pack(rule_pack)
print(result)

if __name__ == "__main__":
main()

0 comments on commit 09413f0

Please sign in to comment.