diff --git a/.gitignore b/.gitignore index d18e22c..8198ebd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # IDE Files +*.code-workspace .vscode .idea diff --git a/arc/Cargo.toml b/arc/Cargo.toml index 86c6c72..21b3eb7 100644 --- a/arc/Cargo.toml +++ b/arc/Cargo.toml @@ -9,3 +9,7 @@ license.workspace = true [lib] path = "lib.rs" + +[[bin]] +name = "arc" +path = "bin/main.rs" diff --git a/arc/__init__.py b/arc/__init__.py new file mode 100644 index 0000000..22be8cc --- /dev/null +++ b/arc/__init__.py @@ -0,0 +1,32 @@ +from typing import Callable + +class Gamepad(object): + _id: str + def __repr__(self) -> str: + return f"" + +class Op(object): + gamepad: Gamepad + name: str + def __init__(self, name: str) -> None: + self.name = name + def __repr__(self) -> str: + return f"" + +def _stub_op(op: Op) -> None: print("!!!OP IS NOT DEFINED!!!") + +_op: Callable[[Op], bool | int | str | None] | None = _stub_op + +OK = True +def OP(func: Callable[[Op], bool | int | str | None]) -> None: + _op = func + +def run_op() -> None: + op = Op("auto") + result = _op(op) + if result == OK: return + if result is None: return + + print(f"Program exited unsucessfully: {result}!") + +run_op() diff --git a/arc/__init__.pyi b/arc/__init__.pyi index de28fc9..2f0ccc9 100644 --- a/arc/__init__.pyi +++ b/arc/__init__.pyi @@ -1,6 +1,15 @@ from typing import Callable -type RunResult = bool +type RunResult = bool | int | str | None +class Gamepad(object): + pass + +class Op(object): + gamepad: Gamepad + name: str + def __init__(self, name: str) -> None: ... + def __repr__(self) -> str: ... OK: RunResult = True -FAIL: RunResult = False -def MAIN(func: Callable[[], RunResult]) -> None: ... +def OP(func: Callable[[Op], RunResult]) -> None: """ +Run the given function as the main function of the program. +""" diff --git a/arc/bin/main.rs b/arc/bin/main.rs new file mode 100644 index 0000000..e2e3117 --- /dev/null +++ b/arc/bin/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("ARC"); +} \ No newline at end of file diff --git a/examples/auto.py b/examples/auto.py index 3cb10a0..e39f399 100644 --- a/examples/auto.py +++ b/examples/auto.py @@ -1,7 +1,8 @@ from arc import * -def main() -> RunResult: - print("Hello, world!") +def auto(op: Op) -> RunResult: + op.gamepad + return OK -MAIN(main) +OP(auto) diff --git a/libs/robot/Cargo.toml b/libs/robot/Cargo.toml index 182d0ce..867eff3 100644 --- a/libs/robot/Cargo.toml +++ b/libs/robot/Cargo.toml @@ -9,3 +9,11 @@ license.workspace = true [lib] path = "lib.rs" + +[[bin]] +name = "arcrobot" +path = "bin/main.rs" + +[dependencies.hardware] +package = "arc-robot-hardware" +path = "./hardware" diff --git a/libs/robot/bin/main.rs b/libs/robot/bin/main.rs new file mode 100644 index 0000000..24514bf --- /dev/null +++ b/libs/robot/bin/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("ARC Robot"); +} \ No newline at end of file diff --git a/libs/robot/hardware/Cargo.toml b/libs/robot/hardware/Cargo.toml new file mode 100644 index 0000000..4973e80 --- /dev/null +++ b/libs/robot/hardware/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "arc-robot-hardware" +description = "ARC Robot hardware" +repository.workspace = true +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true + +[lib] +path = "lib.rs" diff --git a/libs/robot/hardware/lib.rs b/libs/robot/hardware/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/libs/scripts/__init__.py b/libs/scripts/__init__.py index d500221..19d75e8 100644 --- a/libs/scripts/__init__.py +++ b/libs/scripts/__init__.py @@ -1,16 +1,18 @@ from libs.scripts.build import build from libs.scripts.clean import clean from libs.scripts.doc import doc -from libs.scripts.test import test from libs.scripts.fmt import fmt +from libs.scripts.run import run +from libs.scripts.test import test def run_cmd(cmd: str, cwd: str, args: list[str]) -> str | int | None: if cmd == "help" or cmd == "--help" or cmd == "-h": return hlp() if cmd == "build": return build(cwd, args) if cmd == "clean": return clean(cwd, args) if cmd == "doc": return doc(cwd, args) - if cmd == "test": return test(cwd, args) if cmd == "fmt": return fmt(cwd, args) + if cmd == "run": return run(cwd, args) + if cmd == "test": return test(cwd, args) return f"Unknown command: {cmd}" @@ -18,9 +20,23 @@ def hlp() -> str | int | None: print("""\033[35mUsage: \033[36m./epearl \033[32m \033[96m[args]\033[0m \033[35mCommands: \033[32mbuild \033[0mBuild the project + \033[96m--release\033[0m Build in release mode + \033[32mrun \033[0mRun an OpMode + \033[32m \033[0mThe file to run + \033[32mtest \033[0mRun the tests + \033[96m--tarpaulin\033[0m Run the tests with tarpaulin + \033[96m--llvm \033[0m Run the tests with llvm coverage + \033[96m--all \033[0m Run the tests with both tarpaulin and llvm coverage \033[32mclean \033[0mClean the project + \033[96m--deep \033[0mRemoves all generated files and folders \033[32mdoc \033[0mGenerate the documentation - \033[32mtest \033[0mRun the tests - \033[32mfmt \033[0mFormat the code - \033[32mhelp \033[0mDisplay this message""") + \033[96m--open \033[0mOpen the documentation in the browser + \033[32mfmt \033[0mFix formatting issues in the code + \033[96m--check \033[0mCheck if the code is formatted correctly + \033[32mhelp \033[0mDisplay this message +\033[35mExamples: + \033[0mRun the example OpMode: \033[36m./epearl \033[32mrun \033[32m./examples/auto.py + \033[0mBuild the project: \033[36m./epearl \033[32mbuild \033[96m--release + \033[0mRun the tests: \033[36m./epearl \033[32mtest \033[96m--all +\033[0m""") return \ No newline at end of file diff --git a/libs/scripts/run.py b/libs/scripts/run.py new file mode 100644 index 0000000..c63b746 --- /dev/null +++ b/libs/scripts/run.py @@ -0,0 +1,12 @@ +def run(cd: str, args: list[str]) -> str | int | None: + import subprocess + + binary = "arc" + if len(args) > 0: + if '--bin=' in args[0]: + binary = args[0].split('=')[1] + args = args[1:] + + cmd = ["cargo", "run", "--bin", binary] + res = subprocess.run(cmd, cwd=cd) + if res.returncode != 0: return res.returncode diff --git a/libs/scripts/test.py b/libs/scripts/test.py index c42fba9..8f006fc 100644 --- a/libs/scripts/test.py +++ b/libs/scripts/test.py @@ -1,12 +1,16 @@ def test(cd: str, args: list[str]) -> str | int | None: if len(args) == 0: return "No test type specified" - if 'tarpaulin' == args[0]: + + if '--release' in args: + return "Release mode is not supported for tests" + + if '--tarpaulin' in args: args.pop(0) return tarpaulin_test(cd, args) - elif 'llvm' == args[0]: + elif '--llvm' in args: args.pop(0) return llvm_test(cd, args) - elif 'all' == args[0]: + elif '--all' in args: args.pop(0) tarpaulin_test_res = tarpaulin_test(cd, args) if tarpaulin_test_res != None: return tarpaulin_test_res diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f11280c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[project] +name = "arc" +version = "0.0.1-dev" +description = "Advanced Robot Controller" +requires-python = ">=3.11"