Skip to content

Commit

Permalink
Merge pull request #13 from algoux/py
Browse files Browse the repository at this point in the history
Py
  • Loading branch information
MeiK2333 committed Jul 30, 2024
2 parents 78334a1 + 3e6822d commit 5373e29
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 780 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Cargo.lock
.idea
.vscode
*.exe
.cargo
venv
33 changes: 7 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,11 @@ name = "river"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2.153"
clap = { version = "4.5.1", features = ["derive"] }
clap-verbosity-flag = "2.2.0"
log = "0.4.20"
env_logger = "0.10.2"
tempfile = "3.10.0"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "river"
crate-type = ["cdylib"]

[target.'cfg(windows)'.dependencies.windows]
version = "0.53.0"
features = [
"Win32_Storage",
"Win32_Storage_FileSystem",
"Win32_System_Ioctl",
"Win32_System_IO",
"Win32_Foundation",
"Win32_Security",
"Win32_System_JobObjects",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
"Win32_System_Diagnostics",
"Win32_System_Diagnostics_Debug",
"Win32_System_ProcessStatus",
"Win32_System_WindowsProgramming"
]
[dependencies]
pyo3 = "0.22.0"
libc = "0.2.155"
83 changes: 0 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1 @@
# river

## 用法

```bash
$ river -h
example: `river -vvv -- /usr/bin/echo hello world`

Usage: river.exe [OPTIONS] -- <COMMAND>...

Arguments:
<COMMAND>... Program to run and command line arguments

Options:
-i, --input <INPUT>
Input stream. The default value is STDIN(0)
-o, --output <OUTPUT>
Output stream. The default value is STDOUT(1)
-e, --error <ERROR>
Error stream. The default value is STDERR(2)
-r, --result <RESULT>
Output location of the running result. The default value is STDOUT(1)
-t, --time-limit <TIME_LIMIT>
Time limit, in ms. The default value is unlimited
-c, --cpu-time-limit <CPU_TIME_LIMIT>
CPU Time limit, in ms. The default value is unlimited
-m, --memory-limit <MEMORY_LIMIT>
Memory limit, in kib. The default value is unlimited
-v, --verbose...
Increase logging verbosity
-q, --quiet...
Decrease logging verbosity
-h, --help
Print help
-V, --version
Print version
```

## 结果

结果的格式为 JSON

| 字段 | 含义 |
|-----------------|--------------------|
| `time_used` | 程序运行用时 |
| `cpu_time_used` | 程序运行使用 CPU 时间 |
| `memory_used` | 程序运行使用内存 |
| `exit_code` | 程序退出 code,正常情况下为 0 |
| `status` | 正常情况下为 0 |
| `signal` | 正常情况下为 0 |

## 系统支持

`~` 代表开发中的功能

| 特性 | Linux | Windows | macOS |
|-------------|-------|---------|-------|
| 执行指定命令 | ~ || ~ |
| 流重定向 | ~ || ~ |
| 运行时间统计 | ~ || ~ |
| 运行 CPU 时间统计 | ~ || ~ |
| 运行内存统计 | ~ || ~ |
| 运行时间限制 | ~ || ~ |
| 运行 CPU 时间限制 | ~ | ~ | ~ |
| 运行内存限制 | ~ | ~ | ~ |
| 获取进程退出状态 | ~ | ~ | ~ |
| 切换工作空间 | ~ | ~ | ~ |
| 传递环境变量 | ~ | ~ | ~ |
| 网络限制 | ~ | ~ | ~ |
| 写入文件大小限制 | ~ | ~ | ~ |
| 进程/线程数量限制 | ~ | ~ | ~ |
| 危险系统调用限制 | ~ | ~ | ~ |
| 执行用户权限限制 | ~ | ~ | ~ |
| 平滑退出 | ~ | ~ | ~ |

**注意:** Windows 平台下运行 CPU 时间限制与运行内存限制不能保证精确,请不要以此为基准进行判断。

## 测试

```bash
cargo test -- --test-threads=1
```

测试涉及文件操作,建议顺序执行测试用例(并发限制为 1)
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "river"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
[tool.maturin]
features = ["pyo3/extension-module"]
27 changes: 27 additions & 0 deletions resources/runit.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.text
.globl main
main:
endbr64
pushq %rbp
movq %rsp, %rbp
subq $48, %rsp
movl %edi, -20(%rbp)
movq %rsi, -32(%rbp)
movq %rdx, -40(%rbp)
call fork@PLT
movl %eax, -4(%rbp)
cmpl $0, -4(%rbp)
jne .L2
movq -32(%rbp), %rax
leaq 8(%rax), %rcx
movq -32(%rbp), %rax
addq $8, %rax
movq (%rax), %rax
movq -40(%rbp), %rdx
movq %rcx, %rsi
movq %rax, %rdi
call execve@PLT
.L2:
movl $0, %eax
leave
ret
45 changes: 0 additions & 45 deletions src/error.rs

This file was deleted.

29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use pyo3::prelude::*;

#[pyclass]
struct River {
file: String,
}

#[pymethods]
impl River {
#[new]
fn new(file: String) -> Self {
Self { file }
}

#[getter]
fn val(&self) -> String {
self.file.to_string()
}

fn __str__(&self) -> String {
self.file.to_string()
}
}

#[pymodule]
fn river(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<River>()?;
Ok(())
}
123 changes: 0 additions & 123 deletions src/main.rs

This file was deleted.

Loading

0 comments on commit 5373e29

Please sign in to comment.