Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,38 @@ on:
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [
{ target: "x86_64-unknown-linux-musl", image_tag: "x86_64-musl" },
# { target: "aarch64-unknown-linux-musl", image_tag: "aarch64-musl" },
]
container:
image: docker://messense/rust-musl-cross:${{ matrix.platform.image_tag }}
env:
CFLAGS_armv7_unknown_linux_musleabihf: '-mfpu=vfpv3-d16'
steps:
- uses: actions/checkout@v3
- uses: messense/maturin-action@v1
with:
manylinux: auto
command: build
args: --release --sdist -o dist --find-interpreter
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
- uses: actions/checkout@v2
# - name: Build Wheels - manylinux
# uses: messense/maturin-action@main
# with:
# target: ${{ matrix.platform.target }}
# manylinux: auto
# container: off
# args: --release -o dist
- name: Build Wheels - musllinux
uses: messense/maturin-action@main
with:
target: ${{ matrix.platform.target }}
manylinux: musllinux_1_2
container: off

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: messense/maturin-action@v1
with:
command: build
args: --release -o dist --find-interpreter
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
args: --release -o dist
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist

macos:
runs-on: macos-latest
Expand All @@ -55,7 +61,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
# if: "startsWith(github.ref, 'refs/tags/')"
needs: [ macos, windows, linux ]
needs: [ macos, linux ]
steps:
- uses: actions/download-artifact@v2
with:
Expand Down
20 changes: 9 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evalrspy"
version = "0.1.0"
version = "0.1.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -14,4 +14,7 @@ serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
anyhow = "1.0.65"
thiserror = "1.0.37"
js-sandbox = "0.2.0-rc.0"
js-sandbox = "0.2.0-rc.0"

[patch.crates-io]
deno_core = { git = "https://github.com/fevral13/deno.git", branch = "patched" }
16 changes: 8 additions & 8 deletions src/evaluator/evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use js_sandbox::{AnyError, Script};
use pyo3::prelude::*;
use serde::{self, Deserialize};
use serde;
use serde_json::{self, Value};
use std::time::Duration;
use thiserror;

use super::constants::{DEFAULT_TIMEOUT, JS_PRELUDE};

#[derive(Debug, Deserialize)]
#[derive(Debug, serde::Deserialize)]
pub struct Request {
pub script: String,
pub variables: Value,
Expand All @@ -24,16 +24,16 @@ impl Request {
#[derive(thiserror::Error, Debug)]
enum EvalrsError {
#[error("Wrong argument structure")]
WrongArguments,
WrongArguments(#[source] serde_json::Error),

#[error("Variables must be a dict")]
WrongVariablesType,

#[error("Script is not a valid JS code")]
WrongScriptCode { source: AnyError },
WrongScriptCode(#[source] AnyError),

#[error("Script evaluation error")]
ScriptEvaluationError { source: AnyError },
ScriptEvaluationError(#[source] AnyError),
}

#[pyfunction]
Expand Down Expand Up @@ -67,7 +67,7 @@ fn parse_request(request_string: &str) -> Result<Request, EvalrsError> {

match parse_result {
Ok(request) => Ok(request),
Err(_) => Err(EvalrsError::WrongArguments),
Err(error) => Err(EvalrsError::WrongArguments(error)),
}
}

Expand All @@ -93,7 +93,7 @@ fn get_script_evaluator(script_code: &str, timeout: u64) -> Result<Script, Evalr

match Script::from_string(script_code) {
Ok(evaluator) => Ok(evaluator.with_timeout(duration)),
Err(error) => Err(EvalrsError::WrongScriptCode { source: error }),
Err(error) => Err(EvalrsError::WrongScriptCode(error)),
}
}

Expand All @@ -107,7 +107,7 @@ fn evaluate_script(
(Value::String(script.clone()), variables.clone()),
) {
Ok(result) => Ok(result),
Err(error) => Err(EvalrsError::ScriptEvaluationError { source: error }),
Err(error) => Err(EvalrsError::ScriptEvaluationError(error)),
}
}

Expand Down