Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MeiK2333 committed Aug 22, 2024
1 parent 17b6875 commit 1aad279
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 100 deletions.
95 changes: 1 addition & 94 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,8 @@ jobs:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -54,95 +46,10 @@ jobs:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, musllinux, windows, macos]
needs: [linux]
steps:
- name: GH Release
uses: softprops/[email protected]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# river

```shell
pip install maturin
maturin develop
python tests/test.py
```
78 changes: 73 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,90 @@ use pyo3::prelude::*;
#[pyclass]
struct River {
file: String,
args: Vec<String>,
time_limit: Option<i64>,
memory_limit: Option<i64>,
in_fd: Option<i64>,
out_fd: Option<i64>,
err_fd: Option<i64>,
}

#[pymethods]
impl River {
#[new]
fn new(file: String) -> Self {
Self { file }
fn new(cmd: &str) -> Self {
let commands: Vec<&str> = cmd.split_whitespace().collect();
Self {
file: commands[0].to_string(),
args: commands[1..].iter().map(|f| f.to_string()).collect(),
time_limit: None,
memory_limit: None,
in_fd: None,
out_fd: None,
err_fd: None,
}
}

#[setter]
fn set_time_limit(&mut self, time_limit: i64) {
self.time_limit = Some(time_limit)
}
#[getter]
fn get_time_limit(&self) -> Option<i64> {
self.time_limit
}

#[setter]
fn set_memory_limit(&mut self, memory_limit: i64) {
self.memory_limit = Some(memory_limit)
}
#[getter]
fn get_memory_limit(&self) -> Option<i64> {
self.memory_limit
}

#[setter]
fn set_in_fd(&mut self, fd: i64) {
self.in_fd = Some(fd)
}
#[getter]
fn val(&self) -> String {
self.file.to_string()
fn get_in_fd(&self) -> Option<i64> {
self.in_fd
}

#[setter]
fn set_out_fd(&mut self, fd: i64) {
self.out_fd = Some(fd)
}
#[getter]
fn get_out_fd(&self) -> Option<i64> {
self.out_fd
}

#[setter]
fn set_err_fd(&mut self, fd: i64) {
self.err_fd = Some(fd)
}
#[getter]
fn get_err_fd(&self) -> Option<i64> {
self.err_fd
}

fn __str__(&self) -> String {
self.file.to_string()
let mut resp = String::from("command: ");
resp.push_str(&self.file);
if self.args.len() > 0 {
resp.push_str(" ");
resp.push_str(&self.args.join(" "));
}
if let Some(t) = self.time_limit {
resp.push_str(format!("\ntime limit: {}", t).as_str());
}
if let Some(t) = self.memory_limit {
resp.push_str(format!("\nmemory limit: {}", t).as_str());
}

resp
}
}

Expand Down
7 changes: 6 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from river import River
import os

def main():
r = River("echo")
r = River("echo Hello World!")
r.time_limit = 1000
r.memory_limit = 65535
r.out_fd = 1
r.err_fd = 2
print(r)

main()

0 comments on commit 1aad279

Please sign in to comment.