From 225de5fb090d7a73f4e8c01bac19532ca73c4233 Mon Sep 17 00:00:00 2001 From: Ben Bolte Date: Thu, 24 Oct 2024 16:29:29 -0700 Subject: [PATCH] reorganize project (#37) * reorganize project * update robstride package * Bump version to 0.0.25 * un-bump version --- .github/workflows/publish.yml | 46 +++++++++++++++---- Cargo.toml | 12 +++-- actuator/__init__.py | 4 +- actuator/{rust => }/bindings.pyi | 0 actuator/{rust => }/bindings/Cargo.toml | 3 ++ actuator/{rust => }/bindings/bindings.pyi | 0 actuator/{rust => }/bindings/pyproject.toml | 1 - .../{rust => }/bindings/src/bin/stub_gen.rs | 0 actuator/{rust => }/bindings/src/lib.rs | 0 actuator/robstride/Cargo.toml | 35 ++++++++++++++ actuator/robstride/README.md | 5 ++ .../{rust => }/robstride/src/bin/motors.rs | 0 .../robstride/src/bin/multimotors.rs | 0 .../robstride/src/bin/multisupervisor.rs | 0 .../robstride/src/bin/supervisor.rs | 0 actuator/{rust => }/robstride/src/lib.rs | 0 actuator/{rust => }/robstride/src/port.rs | 0 actuator/rust/README.md | 39 ---------------- actuator/rust/__init__.py | 0 actuator/rust/robstride/Cargo.toml | 22 --------- actuator/sim/robstride.py | 5 +- pyproject.toml | 2 +- setup.py | 4 +- 23 files changed, 96 insertions(+), 82 deletions(-) rename actuator/{rust => }/bindings.pyi (100%) rename actuator/{rust => }/bindings/Cargo.toml (99%) rename actuator/{rust => }/bindings/bindings.pyi (100%) rename actuator/{rust => }/bindings/pyproject.toml (99%) rename actuator/{rust => }/bindings/src/bin/stub_gen.rs (100%) rename actuator/{rust => }/bindings/src/lib.rs (100%) create mode 100644 actuator/robstride/Cargo.toml create mode 100644 actuator/robstride/README.md rename actuator/{rust => }/robstride/src/bin/motors.rs (100%) rename actuator/{rust => }/robstride/src/bin/multimotors.rs (100%) rename actuator/{rust => }/robstride/src/bin/multisupervisor.rs (100%) rename actuator/{rust => }/robstride/src/bin/supervisor.rs (100%) rename actuator/{rust => }/robstride/src/lib.rs (100%) rename actuator/{rust => }/robstride/src/port.rs (100%) delete mode 100644 actuator/rust/README.md delete mode 100644 actuator/rust/__init__.py delete mode 100644 actuator/rust/robstride/Cargo.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 170fd4a..3455bf2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,13 +14,9 @@ concurrency: cancel-in-progress: true jobs: - publish: + publish-python: timeout-minutes: 10 name: Build and publish - - # We don't need to run on all platforms since this package is - # platform-agnostic. The output wheel is something like - # "monotonic_attention--py3-none-any.whl". runs-on: ubuntu-latest steps: @@ -47,6 +43,40 @@ jobs: - name: Publish package uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # user: __token__ - # password: ${{ secrets.PYPI_API_TOKEN }} + + publish-rust: + timeout-minutes: 10 + name: Build and publish + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Cache Cargo registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry + restore-keys: | + ${{ runner.os }}-cargo-registry + + - name: Cache Cargo index + uses: actions/cache@v2 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index + restore-keys: | + ${{ runner.os }}-cargo-index + + - name: Publish Robstride package to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + cd actuator/robstride + cargo publish diff --git a/Cargo.toml b/Cargo.toml index e24c20b..0dd84b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,18 @@ [workspace] + members = [ - "actuator/rust/bindings", - "actuator/rust/robstride", + "actuator/bindings", + "actuator/robstride", ] resolver = "2" [workspace.package] + version = "0.1.0" +authors = ["Wesley Maa ", "Pawel Budzianowski ", "Benjamin Bolte "] edition = "2021" - description = "Actuator package" -authors = ["K-Scale Labs "] -repository = "https://github.com/kscalelabs/actuator" license = "MIT" +repository = "https://github.com/kscalelabs/actuator" +documentation = "https://docs.kscale.dev/software/actuators/overview" readme = "README.md" diff --git a/actuator/__init__.py b/actuator/__init__.py index 618a48d..0928e69 100644 --- a/actuator/__init__.py +++ b/actuator/__init__.py @@ -1,8 +1,8 @@ """Defines the top-level API for the actuator package.""" -__version__ = "0.0.23" +__version__ = "0.0.24" -from .rust.bindings import ( +from .bindings import ( PyRobstrideMotorConfig as RobstrideMotorConfig, PyRobstrideMotorControlParams as RobstrideMotorControlParams, PyRobstrideMotorFeedback as RobstrideMotorFeedback, diff --git a/actuator/rust/bindings.pyi b/actuator/bindings.pyi similarity index 100% rename from actuator/rust/bindings.pyi rename to actuator/bindings.pyi diff --git a/actuator/rust/bindings/Cargo.toml b/actuator/bindings/Cargo.toml similarity index 99% rename from actuator/rust/bindings/Cargo.toml rename to actuator/bindings/Cargo.toml index 8288f6d..7b43db2 100644 --- a/actuator/rust/bindings/Cargo.toml +++ b/actuator/bindings/Cargo.toml @@ -1,4 +1,5 @@ [package] + name = "bindings" version.workspace = true edition.workspace = true @@ -9,10 +10,12 @@ license.workspace = true readme.workspace = true [lib] + name = "bindings" crate-type = ["cdylib", "rlib"] [dependencies] + pyo3 = { version = ">= 0.21.0", features = ["extension-module"] } pyo3-stub-gen = ">= 0.6.0" tokio = { version = "1.28.0", features = ["full"] } diff --git a/actuator/rust/bindings/bindings.pyi b/actuator/bindings/bindings.pyi similarity index 100% rename from actuator/rust/bindings/bindings.pyi rename to actuator/bindings/bindings.pyi diff --git a/actuator/rust/bindings/pyproject.toml b/actuator/bindings/pyproject.toml similarity index 99% rename from actuator/rust/bindings/pyproject.toml rename to actuator/bindings/pyproject.toml index 949561a..4117fe1 100644 --- a/actuator/rust/bindings/pyproject.toml +++ b/actuator/bindings/pyproject.toml @@ -6,6 +6,5 @@ build-backend = "maturin" name = "bindings" requires-python = ">=3.9" - [project.optional-dependencies] test = ["pytest", "pyright", "ruff"] diff --git a/actuator/rust/bindings/src/bin/stub_gen.rs b/actuator/bindings/src/bin/stub_gen.rs similarity index 100% rename from actuator/rust/bindings/src/bin/stub_gen.rs rename to actuator/bindings/src/bin/stub_gen.rs diff --git a/actuator/rust/bindings/src/lib.rs b/actuator/bindings/src/lib.rs similarity index 100% rename from actuator/rust/bindings/src/lib.rs rename to actuator/bindings/src/lib.rs diff --git a/actuator/robstride/Cargo.toml b/actuator/robstride/Cargo.toml new file mode 100644 index 0000000..ccd558d --- /dev/null +++ b/actuator/robstride/Cargo.toml @@ -0,0 +1,35 @@ +[package] + +name = "robstride" +readme = "README.md" +version = "0.1.1" +description = "Robstride crate" + +authors.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[lib] + +name = "robstride" +crate-type = ["cdylib", "rlib"] + +[dependencies] + +serialport = "^4.5.1" +ctrlc = "^3.4.5" +lazy_static = "^1.4.0" +spin_sleep = "^1.2.1" +nix = "^0.26.2" +log = "^0.4.22" + +[[bin]] + +name = "motors" +path = "src/bin/motors.rs" + +[dependencies.clap] + +version = "4.3" +features = ["derive"] diff --git a/actuator/robstride/README.md b/actuator/robstride/README.md new file mode 100644 index 0000000..1a1a025 --- /dev/null +++ b/actuator/robstride/README.md @@ -0,0 +1,5 @@ +# robstride + +This crate contains the code for controlling the Robstride actuators. + +For more information, see the documentation [here](https://docs.kscale.dev/software/actuators/robstride). diff --git a/actuator/rust/robstride/src/bin/motors.rs b/actuator/robstride/src/bin/motors.rs similarity index 100% rename from actuator/rust/robstride/src/bin/motors.rs rename to actuator/robstride/src/bin/motors.rs diff --git a/actuator/rust/robstride/src/bin/multimotors.rs b/actuator/robstride/src/bin/multimotors.rs similarity index 100% rename from actuator/rust/robstride/src/bin/multimotors.rs rename to actuator/robstride/src/bin/multimotors.rs diff --git a/actuator/rust/robstride/src/bin/multisupervisor.rs b/actuator/robstride/src/bin/multisupervisor.rs similarity index 100% rename from actuator/rust/robstride/src/bin/multisupervisor.rs rename to actuator/robstride/src/bin/multisupervisor.rs diff --git a/actuator/rust/robstride/src/bin/supervisor.rs b/actuator/robstride/src/bin/supervisor.rs similarity index 100% rename from actuator/rust/robstride/src/bin/supervisor.rs rename to actuator/robstride/src/bin/supervisor.rs diff --git a/actuator/rust/robstride/src/lib.rs b/actuator/robstride/src/lib.rs similarity index 100% rename from actuator/rust/robstride/src/lib.rs rename to actuator/robstride/src/lib.rs diff --git a/actuator/rust/robstride/src/port.rs b/actuator/robstride/src/port.rs similarity index 100% rename from actuator/rust/robstride/src/port.rs rename to actuator/robstride/src/port.rs diff --git a/actuator/rust/README.md b/actuator/rust/README.md deleted file mode 100644 index fa9299c..0000000 --- a/actuator/rust/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Rust - -To build the Rust extension: - -```bash -cargo build -``` - -To run the stub generator: - -```bash -cargo run --bin stub_gen -``` - -On Linux, you may need to install libudev-dev for Rust to properly build. - -```bash -sudo apt-get install libudev-dev -``` - -To run the profiling script: - -```bash -cargo run --bin profile -``` - -To run the stand script: - -(make sure that the right leg is ttyCH341USB0 and the left leg is ttyCH341USB1) - -```bash -cargo run --bin stand -``` - -Also set the baud rate to 921600 with - -```bash -sudo stty -F /dev/ttyCH341USB0 921600 -``` diff --git a/actuator/rust/__init__.py b/actuator/rust/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/actuator/rust/robstride/Cargo.toml b/actuator/rust/robstride/Cargo.toml deleted file mode 100644 index 6a5f12b..0000000 --- a/actuator/rust/robstride/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "robstride" -version.workspace = true -edition.workspace = true -description.workspace = true -authors.workspace = true -repository.workspace = true -license.workspace = true -readme.workspace = true - -[lib] -name = "robstride" -crate-type = ["cdylib", "rlib"] - -[dependencies] -serialport = "4.5.1" -ctrlc = "3.4.5" -lazy_static = "1.4.0" -spin_sleep = "1.2.1" -nix = "0.26.2" -clap = { version = "4.3", features = ["derive"] } -log = "0.4.22" diff --git a/actuator/sim/robstride.py b/actuator/sim/robstride.py index a459214..bfdfef5 100644 --- a/actuator/sim/robstride.py +++ b/actuator/sim/robstride.py @@ -33,7 +33,6 @@ def get_feedback(self) -> RobstrideMotorFeedback: class RobstrideMotorsSim: def __init__(self, port_name: str, motor_infos: dict[int, str], verbose: bool = False) -> None: self.port_name = port_name - # breakpoint() self.motor_configs = { id: ROBSTRIDE_CONFIGS[RobstrideMotorType.from_str(motor_type)] for id, motor_type in motor_infos.items() } @@ -53,7 +52,9 @@ def send_starts(self) -> None: print("Motors started") def send_motor_controls( - self, motor_controls: dict[int, RobstrideMotorControlParams], serial: bool + self, + motor_controls: dict[int, RobstrideMotorControlParams], + serial: bool, ) -> dict[int, RobstrideMotorFeedback]: feedback: dict[int, RobstrideMotorFeedback] = {} for motor_id, params in motor_controls.items(): diff --git a/pyproject.toml b/pyproject.toml index 3b9250f..ca999df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ ignore_missing_imports = true [[tool.mypy.overrides]] -module = ["actuator.rust.bindings"] +module = ["actuator.bindings"] disable_error_code = ["no-untyped-def"] diff --git a/setup.py b/setup.py index 8f0b05a..1c2a130 100644 --- a/setup.py +++ b/setup.py @@ -49,8 +49,8 @@ def run(self) -> None: url="https://github.com/kscalelabs/actuator", rust_extensions=[ RustExtension( - target="actuator.rust.bindings", - path="actuator/rust/bindings/Cargo.toml", + target="actuator.bindings", + path="actuator/bindings/Cargo.toml", binding=Binding.PyO3, ), ],