Skip to content

Commit 3811991

Browse files
authored
Merge pull request #144 from traP-jp/refactor/#133-rename-python-api
Refactor/#133 rename python api
2 parents 3550774 + ce3c736 commit 3811991

File tree

10 files changed

+42
-33
lines changed

10 files changed

+42
-33
lines changed

pylib/traopy/example/problems/addition/main.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30-
"judge_env = traopy.PyProcedure()"
30+
"builder = traopy.PRocedureBuilder()"
3131
]
3232
},
3333
{
@@ -37,21 +37,21 @@
3737
"outputs": [],
3838
"source": [
3939
"base_path = Path(\".\").resolve()\n",
40-
"input_text = traopy.PyResourceKind.TextFile(\n",
40+
"input_text = traopy.ResourceKind.TextFile(\n",
4141
" traopy.PyText(\n",
4242
" \"input\",\n",
4343
" f\"{base_path}/testcases/input.txt\",\n",
4444
" )\n",
4545
")\n",
46-
"output_text = traopy.PyResourceKind.TextFile(\n",
46+
"output_text = traopy.ResourceKind.TextFile(\n",
4747
" traopy.PyText(\n",
4848
" \"output\",\n",
4949
" f\"{base_path}/testcases/output.txt\",\n",
5050
" )\n",
5151
")\n",
5252
"\n",
53-
"input_result = judge_env.add_resource(input_text)\n",
54-
"output_result = judge_env.add_resource(output_text)"
53+
"input_result = builder.add_resource(input_text)\n",
54+
"output_result = builder.add_resource(output_text)"
5555
]
5656
},
5757
{
@@ -60,14 +60,14 @@
6060
"metadata": {},
6161
"outputs": [],
6262
"source": [
63-
"actual_output = traopy.PyResourceKind.RuntimeTextFile(\n",
63+
"actual_output = traopy.ResourceKind.RuntimeTextFile(\n",
6464
" traopy.PyRuntimeText(\n",
6565
" \"actual\",\n",
6666
" \"actual\"\n",
6767
" )\n",
6868
")\n",
6969
"\n",
70-
"actual_result = judge_env.add_resource(actual_output)"
70+
"actual_result = builder.add_resource(actual_output)"
7171
]
7272
},
7373
{
@@ -76,12 +76,12 @@
7676
"metadata": {},
7777
"outputs": [],
7878
"source": [
79-
"script = traopy.PyText(\n",
79+
"script = traopy.Text(\n",
8080
" \"script\",\n",
8181
" f\"{base_path}/tester.py\",\n",
8282
")\n",
8383
"\n",
84-
"script_result = judge_env.add_script(script)"
84+
"script_result = builder.add_script(script)"
8585
]
8686
},
8787
{
@@ -90,7 +90,7 @@
9090
"metadata": {},
9191
"outputs": [],
9292
"source": [
93-
"execution = traopy.PyExecution(\n",
93+
"execution = traopy.Execution(\n",
9494
" \"test\",\n",
9595
" script_result,\n",
9696
" [\n",
@@ -105,7 +105,7 @@
105105
" ],\n",
106106
")\n",
107107
"\n",
108-
"execution_result = judge_env.add_execution(execution)"
108+
"execution_result = builder.add_execution(execution)"
109109
]
110110
},
111111
{
@@ -114,7 +114,7 @@
114114
"metadata": {},
115115
"outputs": [],
116116
"source": [
117-
"judge_env.write_to(\"judge_procedure.json\")"
117+
"builder.write_to(\"judge_procedure.json\")"
118118
]
119119
},
120120
{
@@ -124,7 +124,7 @@
124124
"outputs": [],
125125
"source": [
126126
"local_judge = traopy.LocalJudge(base_path.joinpath(\"tempdir\"))\n",
127-
"result = await local_judge.run(judge_env, {\"actual\": \"3\\n\"})\n",
127+
"result = await local_judge.run(builder, {\"actual\": \"3\\n\"})\n",
128128
"import json\n",
129129
"parsed = json.loads(result)\n",
130130
"pretty = json.dumps(parsed, indent=4)\n",

pylib/traopy/python/traopy/lowlevel.pyi

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,54 @@ import pathlib
77
import typing
88
from enum import Enum, auto
99

10-
class LocalJudge:
11-
def __new__(cls,temp_dir:builtins.str | os.PathLike | pathlib.Path): ...
12-
def run(self, procedure:PyProcedure, runtime_text_contents:typing.Mapping[builtins.str, builtins.str]) -> builtins.str:
13-
...
14-
15-
16-
class PyDependency:
17-
def __new__(cls,ref_to:PyOutput, envvar_name:builtins.str): ...
10+
class Dependency:
11+
def __new__(cls,ref_to:Output, envvar_name:builtins.str): ...
1812
...
1913

20-
class PyEmptyDirectory:
14+
class EmptyDirectory:
2115
def __new__(cls,name:builtins.str): ...
2216
...
2317

24-
class PyExecution:
25-
def __new__(cls,name:builtins.str, script:PyScriptOutput, depends_on:typing.Sequence[PyDependency]): ...
18+
class Execution:
19+
def __new__(cls,name:builtins.str, script:ScriptOutput, depends_on:typing.Sequence[Dependency]): ...
2620
...
2721

28-
class PyOutput:
22+
class LocalJudge:
23+
def __new__(cls,temp_dir:builtins.str | os.PathLike | pathlib.Path): ...
24+
def run(self, builder:ProcedureBuilder, runtime_text_contents:typing.Mapping[builtins.str, builtins.str]) -> builtins.str:
25+
...
26+
27+
28+
class Output:
2929
...
3030

31-
class PyProcedure:
31+
class ProcedureBuilder:
3232
def __new__(cls,): ...
33-
def add_resource(self, resource:PyResourceKind) -> PyOutput:
33+
def add_resource(self, resource:ResourceKind) -> Output:
3434
...
3535

36-
def add_script(self, script:PyText) -> PyScriptOutput:
36+
def add_script(self, script:Text) -> ScriptOutput:
3737
...
3838

39-
def add_execution(self, execution:PyExecution) -> PyOutput:
39+
def add_execution(self, execution:Execution) -> Output:
4040
...
4141

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

4545

46-
class PyRuntimeText:
46+
class RuntimeText:
4747
def __new__(cls,name:builtins.str, label:builtins.str): ...
4848
...
4949

50-
class PyScriptOutput:
50+
class ScriptOutput:
5151
...
5252

53-
class PyText:
53+
class Text:
5454
def __new__(cls,name:builtins.str, path:builtins.str | os.PathLike | pathlib.Path): ...
5555
...
5656

57-
class PyResourceKind(Enum):
57+
class ResourceKind(Enum):
5858
EmptyDirectory = auto()
5959
RuntimeTextFile = auto()
6060
TextFile = auto()

pylib/traopy/src/models/dependency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;
55

66
#[gen_stub_pyclass]
77
#[pyclass]
8+
#[pyo3(name = "Dependency")]
89
#[derive(Debug, Clone)]
910
pub struct PyDependency {
1011
pub ref_to: PyOutput,

pylib/traopy/src/models/empty_directory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use pyo3_stub_gen::derive::*;
44

55
#[gen_stub_pyclass]
66
#[pyclass]
7+
#[pyo3(name = "EmptyDirectory")]
78
#[derive(Debug, Clone)]
89
pub struct PyEmptyDirectory {
910
pub name: String,

pylib/traopy/src/models/execution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;
55

66
#[gen_stub_pyclass]
77
#[pyclass]
8+
#[pyo3(name = "Execution")]
89
#[derive(Debug, Clone)]
910
pub struct PyExecution {
1011
pub name: String,

pylib/traopy/src/models/output.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use pyo3_stub_gen::derive::*;
33

44
#[gen_stub_pyclass]
55
#[pyclass]
6+
#[pyo3(name = "Output")]
67
#[derive(Debug, Clone)]
78
pub struct PyOutput {
89
pub(crate) name: String,
@@ -17,6 +18,7 @@ impl PyOutput {
1718
#[gen_stub_pyclass]
1819
#[pyclass]
1920
#[derive(Debug, Clone)]
21+
#[pyo3(name = "ScriptOutput")]
2022
pub struct PyScriptOutput {
2123
pub(crate) name: String,
2224
}

pylib/traopy/src/models/resource_kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pyo3_stub_gen::derive::*;
55

66
#[gen_stub_pyclass_enum]
77
#[pyclass]
8+
#[pyo3(name = "ResourceKind")]
89
#[derive(Debug, Clone)]
910
pub enum PyResourceKind {
1011
EmptyDirectory(PyEmptyDirectory),

pylib/traopy/src/models/runtime_text.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use pyo3_stub_gen::derive::*;
44

55
#[gen_stub_pyclass]
66
#[pyclass]
7+
#[pyo3(name = "RuntimeText")]
78
#[derive(Debug, Clone)]
89
pub struct PyRuntimeText {
910
pub name: String,

pylib/traopy/src/models/text.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::PathBuf;
55

66
#[gen_stub_pyclass]
77
#[pyclass]
8+
#[pyo3(name = "Text")]
89
#[derive(Debug, Clone)]
910
pub struct PyText {
1011
pub name: String,

pylib/traopy/src/procedure_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::PathBuf;
77

88
#[gen_stub_pyclass]
99
#[pyclass]
10+
#[pyo3(name = "ProcedureBuilder")]
1011
#[derive(Debug, Clone)]
1112
pub struct PyProcedureBuilder {
1213
builder: procedure_builder::ProcedureBuilder,

0 commit comments

Comments
 (0)