reachy2_sdk
ReachySDK package.
This package provides remote access (via socket) to a Reachy robot. It automatically handles the synchronization with the robot. In particular, you can easily get an always up-to-date robot state (joint positions, sensors value). You can also send joint commands, compute forward or inverse kinematics.
Simply do
from reachy2_sdk.reachy_sdk import ReachySDK
reachy = ReachySDK(host="ip_address")
And you're ready to use Reachy!
1"""ReachySDK package. 2 3This package provides remote access (via socket) to a Reachy robot. 4It automatically handles the synchronization with the robot. 5In particular, you can easily get an always up-to-date robot state (joint positions, sensors value). 6You can also send joint commands, compute forward or inverse kinematics. 7 8Simply do 9```python 10from reachy2_sdk.reachy_sdk import ReachySDK 11reachy = ReachySDK(host="ip_address") 12``` 13 14And you're ready to use Reachy! 15 16*Examples are available [here](https://github.com/pollen-robotics/reachy2-sdk/tree/develop/src/examples) 17 and tutorials [there](https://github.com/pollen-robotics/reachy2-tutorials) !* 18 19""" 20import configparser 21import os 22from importlib.metadata import PackageNotFoundError, version 23from typing import List 24 25import reachy2_sdk_api 26from packaging.requirements import Requirement 27from packaging.version import parse 28 29from .reachy_sdk import ReachySDK # noqa: F401 30 31__version__ = "1.0.10" 32 33 34def get_dependencies_from_setup_cfg() -> List[str]: 35 """Get dependencies from setup.cfg file.""" 36 setup_cfg_path = os.path.abspath(os.path.join(__file__, "../../..", "setup.cfg")) 37 38 config = configparser.ConfigParser() 39 config.read(setup_cfg_path) 40 41 if "options" in config and "install_requires" in config["options"]: 42 dependencies = config["options"]["install_requires"].strip().splitlines() 43 return [dep.strip() for dep in dependencies if dep.strip()] 44 45 return [] 46 47 48def check_reachy2_sdk_api_dependency(requirement: str) -> None: 49 """Check if the installed version of reachy2-sdk-api is compatible with the required one. 50 51 Also check if the used version of reachy2-sdk-api is higher than the minimal required version. 52 """ 53 api_requirement = Requirement(requirement) 54 55 try: 56 installed_version = reachy2_sdk_api.__version__ 57 except AttributeError: 58 try: 59 installed_version = version("reachy2-sdk-api") 60 except PackageNotFoundError: 61 raise ImportError("❌ reachy2-sdk-api is NOT installed!") 62 63 installed_parsed = parse(installed_version) 64 65 if installed_parsed in api_requirement.specifier: 66 min_required_version = None 67 for spec in api_requirement.specifier: 68 if spec.operator in (">=", "=="): 69 min_required_version = parse(spec.version) 70 break 71 72 if min_required_version is None: 73 raise ValueError(f"❌ No valid minimum version found in '{api_requirement}'") 74 75 if installed_parsed > min_required_version: 76 print( 77 f"Installed version of reachy2-sdk-api {installed_version} is higher than" 78 f" the minimal requirement {min_required_version}," 79 " a newer version of reachy2-sdk may be available." 80 ) 81 else: 82 raise ValueError( 83 f"⚠️ Version conflict for reachy2-sdk-api:" 84 f"\n\tInstalled {installed_version}," 85 f"\n\tRequired {api_requirement.specifier}" 86 ) 87 88 89def check_dependencies() -> None: 90 """Check if the installed dependencies are compatible with the required ones.""" 91 dependencies = get_dependencies_from_setup_cfg() 92 for requirement in dependencies: 93 try: 94 if requirement.startswith("reachy2-sdk-api"): 95 check_reachy2_sdk_api_dependency(requirement) 96 else: 97 req = Requirement(requirement) 98 installed_version = version(req.name) 99 if parse(installed_version) not in req.specifier: 100 raise ValueError( 101 f"⚠️ Version conflict for {req.name}: \n\tInstalled {installed_version}, \n\tRequired {req.specifier}" 102 ) 103 except PackageNotFoundError: 104 print(f"❌ Missing dependency: {requirement}") 105 except ValueError as e: 106 print(e) 107 108 109check_dependencies()
def
get_dependencies_from_setup_cfg() -> List[str]:
35def get_dependencies_from_setup_cfg() -> List[str]: 36 """Get dependencies from setup.cfg file.""" 37 setup_cfg_path = os.path.abspath(os.path.join(__file__, "../../..", "setup.cfg")) 38 39 config = configparser.ConfigParser() 40 config.read(setup_cfg_path) 41 42 if "options" in config and "install_requires" in config["options"]: 43 dependencies = config["options"]["install_requires"].strip().splitlines() 44 return [dep.strip() for dep in dependencies if dep.strip()] 45 46 return []
Get dependencies from setup.cfg file.
def
check_reachy2_sdk_api_dependency(requirement: str) -> None:
49def check_reachy2_sdk_api_dependency(requirement: str) -> None: 50 """Check if the installed version of reachy2-sdk-api is compatible with the required one. 51 52 Also check if the used version of reachy2-sdk-api is higher than the minimal required version. 53 """ 54 api_requirement = Requirement(requirement) 55 56 try: 57 installed_version = reachy2_sdk_api.__version__ 58 except AttributeError: 59 try: 60 installed_version = version("reachy2-sdk-api") 61 except PackageNotFoundError: 62 raise ImportError("❌ reachy2-sdk-api is NOT installed!") 63 64 installed_parsed = parse(installed_version) 65 66 if installed_parsed in api_requirement.specifier: 67 min_required_version = None 68 for spec in api_requirement.specifier: 69 if spec.operator in (">=", "=="): 70 min_required_version = parse(spec.version) 71 break 72 73 if min_required_version is None: 74 raise ValueError(f"❌ No valid minimum version found in '{api_requirement}'") 75 76 if installed_parsed > min_required_version: 77 print( 78 f"Installed version of reachy2-sdk-api {installed_version} is higher than" 79 f" the minimal requirement {min_required_version}," 80 " a newer version of reachy2-sdk may be available." 81 ) 82 else: 83 raise ValueError( 84 f"⚠️ Version conflict for reachy2-sdk-api:" 85 f"\n\tInstalled {installed_version}," 86 f"\n\tRequired {api_requirement.specifier}" 87 )
Check if the installed version of reachy2-sdk-api is compatible with the required one.
Also check if the used version of reachy2-sdk-api is higher than the minimal required version.
def
check_dependencies() -> None:
90def check_dependencies() -> None: 91 """Check if the installed dependencies are compatible with the required ones.""" 92 dependencies = get_dependencies_from_setup_cfg() 93 for requirement in dependencies: 94 try: 95 if requirement.startswith("reachy2-sdk-api"): 96 check_reachy2_sdk_api_dependency(requirement) 97 else: 98 req = Requirement(requirement) 99 installed_version = version(req.name) 100 if parse(installed_version) not in req.specifier: 101 raise ValueError( 102 f"⚠️ Version conflict for {req.name}: \n\tInstalled {installed_version}, \n\tRequired {req.specifier}" 103 ) 104 except PackageNotFoundError: 105 print(f"❌ Missing dependency: {requirement}") 106 except ValueError as e: 107 print(e)
Check if the installed dependencies are compatible with the required ones.