From 1aad279e6e7115655d565a6b44064e97ff4c175e Mon Sep 17 00:00:00 2001 From: MeiK Date: Thu, 22 Aug 2024 20:42:44 +0800 Subject: [PATCH] update --- .github/workflows/CI.yml | 95 +--------------------------------------- README.md | 6 +++ src/lib.rs | 78 ++++++++++++++++++++++++++++++--- tests/test.py | 7 ++- 4 files changed, 86 insertions(+), 100 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d275bde..7b9ffc2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 @@ -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/action-gh-release@v2.0.8 diff --git a/README.md b/README.md index 170def1..6ac0f41 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ # river + +```shell +pip install maturin +maturin develop +python tests/test.py +``` \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d1042b4..1ecb4c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,22 +3,90 @@ use pyo3::prelude::*; #[pyclass] struct River { file: String, + args: Vec, + time_limit: Option, + memory_limit: Option, + in_fd: Option, + out_fd: Option, + err_fd: Option, } #[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 { + 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 { + 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 { + self.in_fd + } + + #[setter] + fn set_out_fd(&mut self, fd: i64) { + self.out_fd = Some(fd) + } + #[getter] + fn get_out_fd(&self) -> Option { + self.out_fd + } + + #[setter] + fn set_err_fd(&mut self, fd: i64) { + self.err_fd = Some(fd) + } + #[getter] + fn get_err_fd(&self) -> Option { + 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 } } diff --git a/tests/test.py b/tests/test.py index d1f1cf2..d470050 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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()