Skip to content

Commit

Permalink
Update build CI (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays authored Feb 25, 2024
1 parent dbdd508 commit adbb265
Show file tree
Hide file tree
Showing 11 changed files with 440 additions and 312 deletions.
394 changes: 299 additions & 95 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "piston_rspy"
description = "Python bindings for piston_rs."
version = "0.3.2"
version = "0.4.2"
edition = "2021"
authors = ["Jonxslays"]
readme = "README.md"
Expand All @@ -17,7 +17,7 @@ name = "piston_rspy"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.15", features = ["extension-module"] }
pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] }
pyo3 = { version = "0.18.3", features = ["extension-module"] }
pyo3-asyncio = { version = "0.18", features = ["tokio-runtime"] }
tokio = { version = "1" }
piston_rs = "0.4.3"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ a Rust library designed for the same purpose.

## Getting started

piston_rspy officially supports Python versions 3.7, 3.8, 3.9, 3.10, and 3.11.
piston_rspy officially supports Python versions 3.8, 3.9, 3.10, 3.11, and 3.12.

For an in depth look at the API, check out the [documentation](https://jonxslays.github.io/piston_rspy/piston_rspy/)!

Expand All @@ -29,6 +29,7 @@ pip install piston_rspy
### Usage

Fetching the available runtimes from Piston.

```py
import asyncio

Expand All @@ -49,6 +50,7 @@ if __name__ == "__main__":
---

Executing python code via Piston.

```py
import asyncio

Expand Down Expand Up @@ -86,6 +88,7 @@ if __name__ == "__main__":

The builder flow that is used in `piston_rs` is available in
`piston_rspy` as well.

```py
import asyncio

Expand Down
1 change: 1 addition & 0 deletions piston_rspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
__pdoc__: dict[str, bool] = {}
__pdoc__["piston_rspy.piston_rspy"] = False


from .piston_rspy import *
65 changes: 38 additions & 27 deletions piston_rspy/piston_rspy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ from __future__ import annotations
import typing as t
from dataclasses import dataclass, field

__all__: list[str] = [
__all__ = (
"Runtime",
"File",
"ExecResult",
"ExecResponse",
"Executor",
"Client",
]
)

@dataclass(frozen=True)
class Runtime:
Expand All @@ -35,7 +35,7 @@ class Runtime:

language: str
version: str
aliases: list[str]
aliases: t.List[str]
def copy(self) -> Runtime:
"""Copies the runtime, leaving the existing one unchanged.
Expand Down Expand Up @@ -72,6 +72,7 @@ class File:
`File`: The new file.
"""
...

def set_content(self, content: str) -> File:
"""Sets the content of the file.
Expand All @@ -83,6 +84,7 @@ class File:
`File`: The file, for chained method calls.
"""
...

def load_content_from(self, path: str) -> File:
"""Sets the content of the file to the contents of an existing
file on disk.
Expand All @@ -95,6 +97,7 @@ class File:
`File`: The file, for chained method calls.
"""
...

def set_name(self, name: str) -> File:
"""Sets the name of the file.
Expand All @@ -106,6 +109,7 @@ class File:
`File`: The file, for chained method calls.
"""
...

def set_encoding(self, encoding: str) -> File:
"""Sets the encoding of the file.
Expand All @@ -117,6 +121,7 @@ class File:
`File`: The file, for chained method calls.
"""
...

def copy(self) -> File:
"""Copies the file, leaving the existing one unchanged.
Expand Down Expand Up @@ -153,15 +158,16 @@ class ExecResult:
stdout: str
stderr: str
output: str
code: int | None
signal: str | None
code: t.Optional[int]
signal: t.Optional[str]
def is_ok(self) -> bool:
"""Whether or not the execution was ok.
Returns:
`bool`: `True` if the execution returned a zero exit code.
"""
...

def is_err(self) -> bool:
"""Whether or not the execution produced errors.
Expand Down Expand Up @@ -200,7 +206,7 @@ class ExecResponse:
language: str
version: str
run: ExecResult
compile: ExecResult | None
compile: t.Optional[ExecResult]
status: int
def is_ok(self) -> bool:
"""Whether or not the request to Piston succeeded.
Expand All @@ -209,6 +215,7 @@ class ExecResponse:
`bool`: `True` if a 200 status code was received.
"""
...

def is_err(self) -> bool:
"""Whether or not the request to Piston failed.
Expand Down Expand Up @@ -252,9 +259,9 @@ class Executor:

language: str = ""
version: str = "*"
files: list[File] = field(default_factory=list)
files: t.List[File] = field(default_factory=list)
stdin: str = ""
args: list[str] = field(default_factory=list)
args: t.List[str] = field(default_factory=list)
compile_timeout: int = 10000
run_timeout: int = 3000
compile_memory_limit: int = -1
Expand All @@ -266,13 +273,15 @@ class Executor:
`Executor`: A copy of the executor.
"""
...

def reset(self) -> None:
"""Resets the executor back to a `new` state, ready to be
configured again and sent to Piston after metadata is added.
- This method mutates the executor in place.
"""
...

def set_language(self, language: str) -> Executor:
"""Sets the language to use for execution.
Expand All @@ -284,6 +293,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def set_version(self, version: str) -> Executor:
"""Sets the version of the language to use for execution.
Expand All @@ -295,6 +305,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def add_file(self, file: File) -> Executor:
"""Adds a `File` containing the code to be executed.
Expand All @@ -308,7 +319,8 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...
def add_files(self, files: list[File]) -> Executor:

def add_files(self, files: t.List[File]) -> Executor:
"""Adds multiple `File`'s containing the code to be executed.
- Does not overwrite any existing files.
Expand All @@ -321,7 +333,8 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...
def set_files(self, files: list[File]) -> None:

def set_files(self, files: t.List[File]) -> None:
"""Adds multiple `File`'s containing the code to be executed.
- This method mutates the executor in place.
Expand All @@ -332,6 +345,7 @@ class Executor:
The files to replace existing files with.
"""
...

def set_stdin(self, stdin: str) -> Executor:
"""Sets the text to pass as `stdin` to the program.
Expand All @@ -343,6 +357,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def add_arg(self, arg: str) -> Executor:
"""Adds an arg to be passed as a command line argument.
Expand All @@ -356,7 +371,8 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...
def add_args(self, args: list[str]) -> Executor:

def add_args(self, args: t.List[str]) -> Executor:
"""Adds multiple args to be passed as a command line argument.
- Does not overwrite any existing args.
Expand All @@ -369,7 +385,8 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...
def set_args(self, args: list[str]) -> None:

def set_args(self, args: t.List[str]) -> None:
"""Adds multiple args to be passed as command line arguments.
- This method mutates the executor in place.
Expand All @@ -380,6 +397,7 @@ class Executor:
The args to replace existing args with.
"""
...

def set_compile_timeout(self, timeout: int) -> Executor:
"""Sets the maximum allowed time for compilation in
milliseconds.
Expand All @@ -392,6 +410,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def set_run_timeout(self, timeout: int) -> Executor:
"""Sets the maximum allowed time for execution in milliseconds.
Expand All @@ -403,6 +422,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def set_compile_memory_limit(self, limit: int) -> Executor:
"""Sets the maximum allowed memory usage for compilation in
bytes.
Expand All @@ -415,6 +435,7 @@ class Executor:
`Executor`: The executor, for chained method calls.
"""
...

def set_run_memory_limit(self, limit: int) -> Executor:
"""Sets the maximum allowed memory usage for execution in bytes.
Expand Down Expand Up @@ -443,7 +464,7 @@ class Client:
"""

url: str = field(init=False, default="https://emkc.org/api/v2/piston")
headers: dict[str, str] = field(
headers: t.Dict[str, str] = field(
init=False,
default_factory=lambda: {
"Accept": "application/json",
Expand All @@ -462,6 +483,7 @@ class Client:
`Client`: The new client.
"""
...

@staticmethod
def with_url(url: str) -> Client:
"""Creates a new client with a custom url.
Expand All @@ -474,6 +496,7 @@ class Client:
`Client`: The new client.
"""
...

@staticmethod
def with_url_and_key(url: str, key: str) -> Client:
"""Creates a new client with a custom url, and an api key.
Expand All @@ -488,21 +511,8 @@ class Client:
`Client`: The new client.
"""
...
def get_headers(self) -> dict[str, str]:
"""The headers being sent with requests.

Returns:
`dict[str, str]`: The headers.
"""
...
def get_url(self) -> str:
"""The base url for the Piston v2 api.
Returns:
`str`: The url.
"""
...
async def fetch_runtimes(self) -> list[Runtime]:
async def fetch_runtimes(self) -> t.List[Runtime]:
"""`async` Fetches the runtimes from Piston. This is an http
request.
Expand All @@ -514,6 +524,7 @@ class Client:
`RuntimeError`: If the request to Piston failed.
"""
...

async def execute(self, executor: Executor) -> ExecResponse:
"""`async` Executes code using a given executor. This is an http
request.
Expand Down
35 changes: 30 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
[project]
name = "piston_rspy"
version = "0.4.1"
version = "0.4.2"
description = "Python bindings for piston_rs."
requires-python = ">=3.7,<3.12"
requires-python = ">=3.8,<3.13"
authors = [{ name = "Jonxslays" }]
license = { file = "LICENSE" }
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: AsyncIO",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Rust",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]

[project.urls]
homepage = "https://github.com/Jonxslays/piston_rspy"
repository = "https://github.com/Jonxslays/piston_rspy"
documentation = "https://jonxslays.github.io/piston_rspy/piston_rspy/"

[tool.maturin]
strip = true

[tool.pyright]
typeCheckingMode = "strict"
Expand All @@ -13,6 +39,5 @@ include = ["piston_rspy"]
line-length = 99

[build-system]
# requires = ["maturin>=0.12,<0.13"]
# build-backend = "maturin"
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["maturin~=1.4.0"]
build-backend = "maturin"
Loading

0 comments on commit adbb265

Please sign in to comment.