mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-26 14:09:47 +00:00
is_available checks centralized
This commit is contained in:
@@ -23,7 +23,7 @@ from copy import deepcopy
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from lerobot.utils.import_utils import is_package_available, require_package
|
from lerobot.utils.import_utils import _dynamixel_sdk_available, require_package
|
||||||
|
|
||||||
from ..encoding_utils import decode_twos_complement, encode_twos_complement
|
from ..encoding_utils import decode_twos_complement, encode_twos_complement
|
||||||
from ..motors_bus import Motor, MotorCalibration, NameOrID, SerialMotorsBus, Value, get_address
|
from ..motors_bus import Motor, MotorCalibration, NameOrID, SerialMotorsBus, Value, get_address
|
||||||
@@ -36,8 +36,6 @@ from .tables import (
|
|||||||
MODEL_RESOLUTION,
|
MODEL_RESOLUTION,
|
||||||
)
|
)
|
||||||
|
|
||||||
_dynamixel_sdk_available = is_package_available("dynamixel-sdk", import_name="dynamixel_sdk")
|
|
||||||
|
|
||||||
if TYPE_CHECKING or _dynamixel_sdk_available:
|
if TYPE_CHECKING or _dynamixel_sdk_available:
|
||||||
import dynamixel_sdk as dxl
|
import dynamixel_sdk as dxl
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from enum import Enum
|
|||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from lerobot.utils.import_utils import is_package_available, require_package
|
from lerobot.utils.import_utils import _feetech_sdk_available, require_package
|
||||||
|
|
||||||
from ..encoding_utils import decode_sign_magnitude, encode_sign_magnitude
|
from ..encoding_utils import decode_sign_magnitude, encode_sign_magnitude
|
||||||
from ..motors_bus import Motor, MotorCalibration, NameOrID, SerialMotorsBus, Value, get_address
|
from ..motors_bus import Motor, MotorCalibration, NameOrID, SerialMotorsBus, Value, get_address
|
||||||
@@ -35,8 +35,6 @@ from .tables import (
|
|||||||
SCAN_BAUDRATES,
|
SCAN_BAUDRATES,
|
||||||
)
|
)
|
||||||
|
|
||||||
_feetech_sdk_available = is_package_available("feetech-servo-sdk", import_name="scservo_sdk")
|
|
||||||
|
|
||||||
if TYPE_CHECKING or _feetech_sdk_available:
|
if TYPE_CHECKING or _feetech_sdk_available:
|
||||||
import scservo_sdk as scs
|
import scservo_sdk as scs
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ import torch
|
|||||||
import torch.nn.functional as F # noqa: N812
|
import torch.nn.functional as F # noqa: N812
|
||||||
from torch import nn
|
from torch import nn
|
||||||
|
|
||||||
from lerobot.utils.import_utils import is_package_available, require_package
|
from lerobot.utils.import_utils import _diffusers_available, require_package
|
||||||
|
|
||||||
_diffusers_available = is_package_available("diffusers")
|
|
||||||
|
|
||||||
if TYPE_CHECKING or _diffusers_available:
|
if TYPE_CHECKING or _diffusers_available:
|
||||||
from diffusers import ConfigMixin, ModelMixin
|
from diffusers import ConfigMixin, ModelMixin
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ from torch.nn import CrossEntropyLoss
|
|||||||
from lerobot.utils.constants import ACTION, OBS_STATE
|
from lerobot.utils.constants import ACTION, OBS_STATE
|
||||||
from lerobot.utils.import_utils import (
|
from lerobot.utils.import_utils import (
|
||||||
_peft_available,
|
_peft_available,
|
||||||
|
_qwen_vl_utils_available,
|
||||||
|
_torchdiffeq_available,
|
||||||
_transformers_available,
|
_transformers_available,
|
||||||
is_package_available,
|
|
||||||
require_package,
|
require_package,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,8 +72,6 @@ from .constant import (
|
|||||||
TOKENIZER_MAX_LENGTH,
|
TOKENIZER_MAX_LENGTH,
|
||||||
)
|
)
|
||||||
|
|
||||||
_torchdiffeq_available = is_package_available("torchdiffeq")
|
|
||||||
_qwen_vl_utils_available = is_package_available("qwen-vl-utils", import_name="qwen_vl_utils")
|
|
||||||
_wallx_deps_available = (
|
_wallx_deps_available = (
|
||||||
_transformers_available and _peft_available and _torchdiffeq_available and _qwen_vl_utils_available
|
_transformers_available and _peft_available and _torchdiffeq_available and _qwen_vl_utils_available
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from typing import Any
|
|||||||
|
|
||||||
from lerobot.types import RobotAction
|
from lerobot.types import RobotAction
|
||||||
from lerobot.utils.decorators import check_if_already_connected, check_if_not_connected
|
from lerobot.utils.decorators import check_if_already_connected, check_if_not_connected
|
||||||
from lerobot.utils.import_utils import is_package_available
|
from lerobot.utils.import_utils import _pynput_available
|
||||||
|
|
||||||
from ..teleoperator import Teleoperator
|
from ..teleoperator import Teleoperator
|
||||||
from ..utils import TeleopEvents
|
from ..utils import TeleopEvents
|
||||||
@@ -33,7 +33,7 @@ from .configuration_keyboard import (
|
|||||||
KeyboardTeleopConfig,
|
KeyboardTeleopConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
PYNPUT_AVAILABLE = is_package_available("pynput")
|
PYNPUT_AVAILABLE = _pynput_available
|
||||||
keyboard = None
|
keyboard = None
|
||||||
if PYNPUT_AVAILABLE:
|
if PYNPUT_AVAILABLE:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -95,13 +95,29 @@ def require_package(pkg_name: str, extra: str, import_name: str | None = None) -
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ── Centralised availability flags ────────────────────────────────────────
|
||||||
|
# Every optional-dependency check lives here so that the rest of the codebase
|
||||||
|
# can simply ``from lerobot.utils.import_utils import _foo_available``.
|
||||||
|
# Do NOT define ad-hoc ``is_package_available(...)`` calls in other modules.
|
||||||
|
|
||||||
|
# ML / training
|
||||||
_transformers_available = is_package_available("transformers")
|
_transformers_available = is_package_available("transformers")
|
||||||
_peft_available = is_package_available("peft")
|
_peft_available = is_package_available("peft")
|
||||||
_scipy_available = is_package_available("scipy")
|
_scipy_available = is_package_available("scipy")
|
||||||
|
_diffusers_available = is_package_available("diffusers")
|
||||||
|
_torchdiffeq_available = is_package_available("torchdiffeq")
|
||||||
|
|
||||||
|
# Hardware SDKs
|
||||||
|
_dynamixel_sdk_available = is_package_available("dynamixel-sdk", import_name="dynamixel_sdk")
|
||||||
|
_feetech_sdk_available = is_package_available("feetech-servo-sdk", import_name="scservo_sdk")
|
||||||
_reachy2_sdk_available = is_package_available("reachy2_sdk")
|
_reachy2_sdk_available = is_package_available("reachy2_sdk")
|
||||||
_can_available = is_package_available("python-can", "can")
|
_can_available = is_package_available("python-can", "can")
|
||||||
_unitree_sdk_available = is_package_available("unitree-sdk2py", "unitree_sdk2py")
|
_unitree_sdk_available = is_package_available("unitree-sdk2py", "unitree_sdk2py")
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
_pynput_available = is_package_available("pynput")
|
||||||
_pygame_available = is_package_available("pygame")
|
_pygame_available = is_package_available("pygame")
|
||||||
|
_qwen_vl_utils_available = is_package_available("qwen-vl-utils", import_name="qwen_vl_utils")
|
||||||
|
|
||||||
|
|
||||||
def make_device_from_device_class(config: ChoiceRegistry) -> Any:
|
def make_device_from_device_class(config: ChoiceRegistry) -> Any:
|
||||||
|
|||||||
Reference in New Issue
Block a user