From dfcaafbc0d4952770a23c0f54d2cd98a6b7ab3f7 Mon Sep 17 00:00:00 2001 From: Ben Bolte Date: Fri, 1 Nov 2024 11:43:49 -0700 Subject: [PATCH] Version fixes (#41) * version fixes * update version --- actuator/__init__.py | 5 +- actuator/bindings/.gitignore | 3 + actuator/bindings/bindings.pyi | 152 --------------------------------- actuator/bindings/src/lib.rs | 9 +- setup.py | 13 +-- 5 files changed, 17 insertions(+), 165 deletions(-) create mode 100644 actuator/bindings/.gitignore delete mode 100644 actuator/bindings/bindings.pyi diff --git a/actuator/__init__.py b/actuator/__init__.py index 2b5a6f7..cbe9fd0 100644 --- a/actuator/__init__.py +++ b/actuator/__init__.py @@ -1,7 +1,5 @@ """Defines the top-level API for the actuator package.""" -__version__ = "0.0.25" - from .bindings import ( PyRobstrideMotorConfig as RobstrideMotorConfig, PyRobstrideMotorControlParams as RobstrideMotorControlParams, @@ -9,4 +7,7 @@ PyRobstrideMotors as RobstrideMotors, PyRobstrideMotorsSupervisor as RobstrideMotorsSupervisor, PyRobstrideMotorType as RobstrideMotorType, + get_version, ) + +__version__ = get_version() diff --git a/actuator/bindings/.gitignore b/actuator/bindings/.gitignore new file mode 100644 index 0000000..f7eab8d --- /dev/null +++ b/actuator/bindings/.gitignore @@ -0,0 +1,3 @@ +# .gitignore + +*.pyi diff --git a/actuator/bindings/bindings.pyi b/actuator/bindings/bindings.pyi deleted file mode 100644 index 5882e61..0000000 --- a/actuator/bindings/bindings.pyi +++ /dev/null @@ -1,152 +0,0 @@ -# This file is automatically generated by pyo3_stub_gen -# ruff: noqa: E501, F401 - -import typing - -class PyRobstrideMotorConfig: - p_min: float - p_max: float - v_min: float - v_max: float - kp_min: float - kp_max: float - kd_min: float - kd_max: float - t_min: float - t_max: float - zero_on_init: bool - can_timeout_command: int - can_timeout_factor: float - -class PyRobstrideMotorControlParams: - position: float - velocity: float - kp: float - kd: float - torque: float - def __new__(cls,position:float, velocity:float, kp:float, kd:float, torque:float): ... - def __repr__(self) -> str: - ... - - -class PyRobstrideMotorFeedback: - can_id: int - position: float - velocity: float - torque: float - mode: str - faults: int - def __repr__(self) -> str: - ... - - @staticmethod - def create_feedback(can_id:int, position:float, velocity:float, torque:float, mode:str, faults:int) -> PyRobstrideMotorFeedback: - ... - - -class PyRobstrideMotorType: - def __repr__(self) -> str: - ... - - @staticmethod - def from_str(s:str) -> PyRobstrideMotorType: - ... - - def __hash__(self) -> int: - ... - - def __eq__(self, other:typing.Any) -> bool: - ... - - -class PyRobstrideMotors: - def __new__(cls,port_name,motor_infos,verbose = ...): ... - def send_get_mode(self) -> dict[int, str]: - ... - - def send_resets(self) -> None: - ... - - def send_starts(self) -> None: - ... - - def send_motor_controls(self, motor_controls:typing.Mapping[int, PyRobstrideMotorControlParams], serial:bool) -> dict[int, PyRobstrideMotorFeedback]: - ... - - def __repr__(self) -> str: - ... - - @staticmethod - def get_default_configs() -> dict[PyRobstrideMotorType, PyRobstrideMotorConfig]: - ... - - -class PyRobstrideMotorsSupervisor: - total_commands: int - actual_update_rate: float - serial: bool - def __new__(cls,port_name,motor_infos,verbose = ...,target_update_rate = ...,zero_on_init = ...): ... - def set_position(self, motor_id:int, position:float) -> float: - ... - - def get_position(self, motor_id:int) -> float: - ... - - def set_velocity(self, motor_id:int, velocity:float) -> float: - ... - - def get_velocity(self, motor_id:int) -> float: - ... - - def set_kp(self, motor_id:int, kp:float) -> float: - ... - - def get_kp(self, motor_id:int) -> float: - ... - - def set_kd(self, motor_id:int, kd:float) -> float: - ... - - def get_kd(self, motor_id:int) -> float: - ... - - def set_torque(self, motor_id:int, torque:float) -> float: - ... - - def get_torque(self, motor_id:int) -> float: - ... - - def add_motor_to_zero(self, motor_id:int) -> None: - ... - - def get_latest_feedback(self) -> dict[int, PyRobstrideMotorFeedback]: - ... - - def toggle_pause(self) -> None: - ... - - def stop(self) -> None: - ... - - def __repr__(self) -> str: - ... - - def set_params(self, motor_id:int, params:PyRobstrideMotorControlParams) -> None: - ... - - def failed_commands_for(self, motor_id:int) -> int: - ... - - def reset_command_counters(self) -> None: - ... - - def is_running(self) -> bool: - ... - - def max_update_rate(self, rate:float) -> None: - ... - - def toggle_serial(self) -> bool: - ... - - diff --git a/actuator/bindings/src/lib.rs b/actuator/bindings/src/lib.rs index 44b09cb..038bcf7 100644 --- a/actuator/bindings/src/lib.rs +++ b/actuator/bindings/src/lib.rs @@ -1,6 +1,6 @@ use pyo3::prelude::*; use pyo3_stub_gen::define_stub_info_gatherer; -use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; +use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pyfunction, gen_stub_pymethods}; use robstride::{ motor_mode_from_str as robstride_motor_mode_from_str, motor_type_from_str as robstride_motor_type_from_str, MotorConfig as RobstrideMotorConfig, @@ -11,6 +11,12 @@ use robstride::{ use std::collections::HashMap; use std::hash::{Hash, Hasher}; +#[pyfunction] +#[gen_stub_pyfunction] +fn get_version() -> String { + env!("CARGO_PKG_VERSION").to_string() +} + #[gen_stub_pyclass] #[pyclass] struct PyRobstrideMotors { @@ -542,6 +548,7 @@ impl From for RobstrideMotorType { #[pymodule] fn bindings(m: &Bound) -> PyResult<()> { + m.add_function(wrap_pyfunction!(get_version, m)?)?; m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/setup.py b/setup.py index 1c2a130..ddca7a9 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ #!/usr/bin/env python """Setup script for the project.""" -import glob import re import subprocess @@ -22,16 +21,11 @@ requirements_dev: list[str] = f.read().splitlines() -with open("actuator/__init__.py", "r", encoding="utf-8") as fh: - version_re = re.search(r"^__version__ = \"([^\"]*)\"", fh.read(), re.MULTILINE) -assert version_re is not None, "Could not find version in actuator/__init__.py" +with open("Cargo.toml", "r", encoding="utf-8") as fh: + version_re = re.search(r"^version = \"([^\"]*)\"", fh.read(), re.MULTILINE) +assert version_re is not None, "Could not find version in Cargo.toml" version: str = version_re.group(1) -package_data = [f"actuator/{name}" for name in ("py.typed", "requirements.txt", "requirements-dev.txt")] -package_data.append("Cargo.toml") -for ext in ("pyi", "rs", "toml", "so"): - package_data.extend(glob.iglob(f"actuator/**/*.{ext}", recursive=True)) - class RustBuildExt(build_ext): def run(self) -> None: @@ -62,7 +56,6 @@ def run(self) -> None: install_requires=requirements, extras_require={"dev": requirements_dev}, include_package_data=True, - package_data={"actuator": package_data}, packages=find_packages(include=["actuator"]), cmdclass={"build_ext": RustBuildExt}, )