Skip to content

Commit

Permalink
Merge pull request #144 from traP-jp/refactor/#133-rename-python-api
Browse files Browse the repository at this point in the history
Refactor/#133 rename python api
  • Loading branch information
comavius authored Feb 24, 2025
2 parents 3550774 + ce3c736 commit 3811991
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 33 deletions.
26 changes: 13 additions & 13 deletions pylib/traopy/example/problems/addition/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"judge_env = traopy.PyProcedure()"
"builder = traopy.PRocedureBuilder()"
]
},
{
Expand All @@ -37,21 +37,21 @@
"outputs": [],
"source": [
"base_path = Path(\".\").resolve()\n",
"input_text = traopy.PyResourceKind.TextFile(\n",
"input_text = traopy.ResourceKind.TextFile(\n",
" traopy.PyText(\n",
" \"input\",\n",
" f\"{base_path}/testcases/input.txt\",\n",
" )\n",
")\n",
"output_text = traopy.PyResourceKind.TextFile(\n",
"output_text = traopy.ResourceKind.TextFile(\n",
" traopy.PyText(\n",
" \"output\",\n",
" f\"{base_path}/testcases/output.txt\",\n",
" )\n",
")\n",
"\n",
"input_result = judge_env.add_resource(input_text)\n",
"output_result = judge_env.add_resource(output_text)"
"input_result = builder.add_resource(input_text)\n",
"output_result = builder.add_resource(output_text)"
]
},
{
Expand All @@ -60,14 +60,14 @@
"metadata": {},
"outputs": [],
"source": [
"actual_output = traopy.PyResourceKind.RuntimeTextFile(\n",
"actual_output = traopy.ResourceKind.RuntimeTextFile(\n",
" traopy.PyRuntimeText(\n",
" \"actual\",\n",
" \"actual\"\n",
" )\n",
")\n",
"\n",
"actual_result = judge_env.add_resource(actual_output)"
"actual_result = builder.add_resource(actual_output)"
]
},
{
Expand All @@ -76,12 +76,12 @@
"metadata": {},
"outputs": [],
"source": [
"script = traopy.PyText(\n",
"script = traopy.Text(\n",
" \"script\",\n",
" f\"{base_path}/tester.py\",\n",
")\n",
"\n",
"script_result = judge_env.add_script(script)"
"script_result = builder.add_script(script)"
]
},
{
Expand All @@ -90,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"execution = traopy.PyExecution(\n",
"execution = traopy.Execution(\n",
" \"test\",\n",
" script_result,\n",
" [\n",
Expand All @@ -105,7 +105,7 @@
" ],\n",
")\n",
"\n",
"execution_result = judge_env.add_execution(execution)"
"execution_result = builder.add_execution(execution)"
]
},
{
Expand All @@ -114,7 +114,7 @@
"metadata": {},
"outputs": [],
"source": [
"judge_env.write_to(\"judge_procedure.json\")"
"builder.write_to(\"judge_procedure.json\")"
]
},
{
Expand All @@ -124,7 +124,7 @@
"outputs": [],
"source": [
"local_judge = traopy.LocalJudge(base_path.joinpath(\"tempdir\"))\n",
"result = await local_judge.run(judge_env, {\"actual\": \"3\\n\"})\n",
"result = await local_judge.run(builder, {\"actual\": \"3\\n\"})\n",
"import json\n",
"parsed = json.loads(result)\n",
"pretty = json.dumps(parsed, indent=4)\n",
Expand Down
40 changes: 20 additions & 20 deletions pylib/traopy/python/traopy/lowlevel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@ import pathlib
import typing
from enum import Enum, auto

class LocalJudge:
def __new__(cls,temp_dir:builtins.str | os.PathLike | pathlib.Path): ...
def run(self, procedure:PyProcedure, runtime_text_contents:typing.Mapping[builtins.str, builtins.str]) -> builtins.str:
...


class PyDependency:
def __new__(cls,ref_to:PyOutput, envvar_name:builtins.str): ...
class Dependency:
def __new__(cls,ref_to:Output, envvar_name:builtins.str): ...
...

class PyEmptyDirectory:
class EmptyDirectory:
def __new__(cls,name:builtins.str): ...
...

class PyExecution:
def __new__(cls,name:builtins.str, script:PyScriptOutput, depends_on:typing.Sequence[PyDependency]): ...
class Execution:
def __new__(cls,name:builtins.str, script:ScriptOutput, depends_on:typing.Sequence[Dependency]): ...
...

class PyOutput:
class LocalJudge:
def __new__(cls,temp_dir:builtins.str | os.PathLike | pathlib.Path): ...
def run(self, builder:ProcedureBuilder, runtime_text_contents:typing.Mapping[builtins.str, builtins.str]) -> builtins.str:
...


class Output:
...

class PyProcedure:
class ProcedureBuilder:
def __new__(cls,): ...
def add_resource(self, resource:PyResourceKind) -> PyOutput:
def add_resource(self, resource:ResourceKind) -> Output:
...

def add_script(self, script:PyText) -> PyScriptOutput:
def add_script(self, script:Text) -> ScriptOutput:
...

def add_execution(self, execution:PyExecution) -> PyOutput:
def add_execution(self, execution:Execution) -> Output:
...

def write_to(self, path:builtins.str | os.PathLike | pathlib.Path) -> None:
...


class PyRuntimeText:
class RuntimeText:
def __new__(cls,name:builtins.str, label:builtins.str): ...
...

class PyScriptOutput:
class ScriptOutput:
...

class PyText:
class Text:
def __new__(cls,name:builtins.str, path:builtins.str | os.PathLike | pathlib.Path): ...
...

class PyResourceKind(Enum):
class ResourceKind(Enum):
EmptyDirectory = auto()
RuntimeTextFile = auto()
TextFile = auto()
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "Dependency")]
#[derive(Debug, Clone)]
pub struct PyDependency {
pub ref_to: PyOutput,
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/empty_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "EmptyDirectory")]
#[derive(Debug, Clone)]
pub struct PyEmptyDirectory {
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "Execution")]
#[derive(Debug, Clone)]
pub struct PyExecution {
pub name: String,
Expand Down
2 changes: 2 additions & 0 deletions pylib/traopy/src/models/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "Output")]
#[derive(Debug, Clone)]
pub struct PyOutput {
pub(crate) name: String,
Expand All @@ -17,6 +18,7 @@ impl PyOutput {
#[gen_stub_pyclass]
#[pyclass]
#[derive(Debug, Clone)]
#[pyo3(name = "ScriptOutput")]
pub struct PyScriptOutput {
pub(crate) name: String,
}
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/resource_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass_enum]
#[pyclass]
#[pyo3(name = "ResourceKind")]
#[derive(Debug, Clone)]
pub enum PyResourceKind {
EmptyDirectory(PyEmptyDirectory),
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/runtime_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use pyo3_stub_gen::derive::*;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "RuntimeText")]
#[derive(Debug, Clone)]
pub struct PyRuntimeText {
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/models/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::PathBuf;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "Text")]
#[derive(Debug, Clone)]
pub struct PyText {
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions pylib/traopy/src/procedure_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::PathBuf;

#[gen_stub_pyclass]
#[pyclass]
#[pyo3(name = "ProcedureBuilder")]
#[derive(Debug, Clone)]
pub struct PyProcedureBuilder {
builder: procedure_builder::ProcedureBuilder,
Expand Down

0 comments on commit 3811991

Please sign in to comment.