Skip to content

Commit

Permalink
Improved tooling, and getting started on the binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
AtomicGamer9523 committed Dec 14, 2023
1 parent c2171c2 commit e6a3c65
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# IDE Files
*.code-workspace
.vscode
.idea

Expand Down
4 changes: 4 additions & 0 deletions arc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ license.workspace = true

[lib]
path = "lib.rs"

[[bin]]
name = "arc"
path = "bin/main.rs"
32 changes: 32 additions & 0 deletions arc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Callable

class Gamepad(object):
_id: str
def __repr__(self) -> str:
return f"<Gamepad {self._id}>"

class Op(object):
gamepad: Gamepad
name: str
def __init__(self, name: str) -> None:
self.name = name
def __repr__(self) -> str:
return f"<Op {self.name}>"

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()
15 changes: 12 additions & 3 deletions arc/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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.
"""
3 changes: 3 additions & 0 deletions arc/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("ARC");
}
7 changes: 4 additions & 3 deletions examples/auto.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions libs/robot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions libs/robot/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("ARC Robot");
}
11 changes: 11 additions & 0 deletions libs/robot/hardware/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Empty file added libs/robot/hardware/lib.rs
Empty file.
26 changes: 21 additions & 5 deletions libs/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
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}"

def hlp() -> str | int | None:
print("""\033[35mUsage: \033[36m./epearl \033[32m<command> \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<file> \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
12 changes: 12 additions & 0 deletions libs/scripts/run.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions libs/scripts/test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
name = "arc"
version = "0.0.1-dev"
description = "Advanced Robot Controller"
requires-python = ">=3.11"

0 comments on commit e6a3c65

Please sign in to comment.