Compare commits

..

4 Commits

Author SHA1 Message Date
d246913b4c
加个函数 2024-02-25 16:04:59 +08:00
aa641b4b82
更新上传文件名以匹配特定格式 2024-02-25 12:46:49 +08:00
e14ffbddb4
更改目录结构 2024-02-25 12:37:38 +08:00
1b5c33c1d5
add builds workflow 2024-02-25 12:29:45 +08:00
6 changed files with 2217 additions and 4 deletions

43
.github/workflows/builds.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: build and test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: 获取版本号
id: get_version
uses: sravinet/toml-select@v1.0.1
with:
file: ./ica-rs/Cargo.toml
field: "package.version"
- name: Setup Python
uses: actions/setup-python@v5.0.0
with:
# Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset.
python-version: 3.8
- name: Run tests
run: cargo test --verbose
- name: Build
run: cargo build --release
- name: 上传
uses: actions/upload-artifact@v2
with:
name: ica-rs-b${{ github.run_number }}-${{ steps.get_version.outputs.value }}-py38-win-x64
path: ./target/release/ica-rs.exe

5
.gitignore vendored
View File

@ -6,3 +6,8 @@ config.toml
*.pyc
*__pycache__/
# Added by cargo
/target

2146
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[workspace]
members = [
"ica-rs"
]
resolver = "2"
[patch.crates-io]
rust_socketio = { git = "https://github.com/shenjackyuanjie/rust-socketio.git", branch = "mult_payload" }
# pyo3 = { git = "https://github.com/PyO3/pyo3.git", branch = "main" }

View File

@ -25,7 +25,3 @@ pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"]
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["time"] }
[patch.crates-io]
rust_socketio = { git = "https://github.com/shenjackyuanjie/rust-socketio.git", branch = "mult_payload" }
# pyo3 = { git = "https://github.com/PyO3/pyo3.git", branch = "main" }

View File

@ -141,6 +141,20 @@ pub fn get_change_time(path: &PathBuf) -> Option<SystemTime> {
path.metadata().ok()?.modified().ok()
}
pub fn py_module_from_code(content: &str, path: &str) -> PyResult<Py<PyAny>> {
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
let module: PyResult<Py<PyAny>> = PyModule::from_code(
py,
&content,
&path,
&path,
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
)
.map(|module| module.into());
module
})
}
/// 传入文件路径
/// 返回 hash 和 文件内容
pub fn load_py_file(path: &PathBuf) -> std::io::Result<(Option<SystemTime>, String)> {