Problem Description
The current import handling for MuJoCo and Bullet engines masks actual import errors that occur within the farms_mujoco and farms_bullet modules. This makes debugging dependency issues difficult.
https://github.com/farmsim/farms_sim/blob/ccd742b292849748dc8e9819b3d5bb9becc25ff3/farms_sim/simulation.py#L15
Current Code
ENGINE_MUJOCO = False
try:
from farms_mujoco.simulation.simulation import (
Simulation as MuJoCoSimulation,
)
ENGINE_MUJOCO = True
except ImportError:
MuJoCoSimulation = None
ENGINE_BULLET = False
try:
from farms_bullet.simulation.simulation import (
AnimatSimulation as PybulletSimulation
)
ENGINE_BULLET = True
except ImportError:
PybulletSimulation = None
if not ENGINE_MUJOCO and not ENGINE_BULLET:
raise ImportError('Neither MuJoCo nor Bullet are installed')
Issue
When farms_mujoco or farms_bullet packages are installed but have internal dependency issues (missing libraries, version mismatches, etc.), the broad except ImportError catches these errors and treats them as if the packages aren't installed at all. This leads to:
- Silent failures: Real configuration problems are hidden
- Misleading error messages: Users get "Neither MuJoCo nor Bullet are installed" instead of the actual error
- Difficult debugging: Developers can't see what's actually wrong
Expected Behavior
The code should distinguish between:
- Package not installed (expected case)
- Package installed but failing to import due to internal errors (needs user attention)
Proposed Solution
Approach using ModuleNotFoundError :
ENGINE_MUJOCO = False
try:
from farms_mujoco.simulation.simulation import (
Simulation as MuJoCoSimulation,
)
ENGINE_MUJOCO = True
except ModuleNotFoundError:
# Package not installed - this is expected
MuJoCoSimulation = None
except ImportError as e:
# Package exists but has internal import issues - re-raise with context
raise ImportError(f"farms_mujoco is installed but failed to import: {e}") from e
ENGINE_BULLET = False
try:
from farms_bullet.simulation.simulation import (
AnimatSimulation as PybulletSimulation
)
ENGINE_BULLET = True
except ModuleNotFoundError:
# Package not installed - this is expected
PybulletSimulation = None
except ImportError as e:
# Package exists but has internal import issues - re-raise with context
raise ImportError(f"farms_bullet is installed but failed to import: {e}") from e
if not ENGINE_MUJOCO and not ENGINE_BULLET:
raise ImportError('Neither MuJoCo nor Bullet packages are installed')
Reproduction Steps
To reproduce the current issue:
- Install
farms_mujoco with missing system dependencies
- Try to import - you'll get the generic "Neither MuJoCo nor Bullet are installed" message
- The actual dependency error is hidden
Problem Description
The current import handling for MuJoCo and Bullet engines masks actual import errors that occur within the
farms_mujocoandfarms_bulletmodules. This makes debugging dependency issues difficult.https://github.com/farmsim/farms_sim/blob/ccd742b292849748dc8e9819b3d5bb9becc25ff3/farms_sim/simulation.py#L15
Current Code
Issue
When
farms_mujocoorfarms_bulletpackages are installed but have internal dependency issues (missing libraries, version mismatches, etc.), the broadexcept ImportErrorcatches these errors and treats them as if the packages aren't installed at all. This leads to:Expected Behavior
The code should distinguish between:
Proposed Solution
Approach using
ModuleNotFoundError:Reproduction Steps
To reproduce the current issue:
farms_mujocowith missing system dependencies