Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.1"
version: "0.13.7"
enable-cache: true
- run: uvx ruff@0.16.1 check --diff
- run: uvx ruff@0.16.1 format --diff
- run: uvx ruff@0.17.4 check --diff
- run: uvx ruff@0.17.4 format --diff

tests:
runs-on: ubuntu-latest
Expand All @@ -31,19 +31,23 @@ jobs:
python-version: ["3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.1"
version: "0.13.7"
python-version: ${{ matrix.python-version }}
enable-cache: true
- run: uv run pytest

pyright:
ty:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.1"
version: "0.13.7"
python-version: ${{ matrix.python-version }}
enable-cache: true
- run: uv run pyright
- run: uv run ty check
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.12.1"
version: "0.13.7"
- name: Install Python 3.13
run: uv python install 3.13
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```sh
make format # Format and lint (ruff)
make type # Type check (pyright)
make type # Type check (ty)
make check # make format && make type
make test # Run tests
```
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ format:

.PHONY: type
type:
uv run pyright
uv run ty check

.PHONY: check
check: format type
Expand Down
15 changes: 5 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["uv_build>=0.12.1,<0.13.0"]
requires = ["uv_build>=0.13.7,<0.14.0"]
build-backend = "uv_build"

[project]
Expand Down Expand Up @@ -45,14 +45,14 @@ mjviser = "mjviser.__main__:main"
[project.optional-dependencies]
dev = [
"pytest",
"ruff==0.16.1",
"ruff==0.17.4",
]

[dependency-groups]
dev = [
"pyright>=1.1.411",
"pytest>=9.1.1",
"ruff==0.16.1",
"ruff==0.17.4",
"ty>=0.0.101",
]

[tool.uv]
Expand All @@ -74,14 +74,9 @@ exclude = [
select = ["E4", "E7", "E9", "F", "I", "B"]
ignore = ["B011"]

[tool.pyright]
pythonVersion = "3.11"
ignore = ["./typings", "./examples"]
stubPath = "typings"

[tool.ty.environment]
extra-paths = ["typings"]

[tool.ty.src]
include = ["src"]
include = ["src", "tests"]
exclude = ["typings"]
2 changes: 1 addition & 1 deletion src/mjviser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _pick(prompt: str, options: list[str]) -> int:
def _resolve_from_robot_descriptions(name: str) -> Path | None:
"""Try to resolve a model name via the robot_descriptions package."""
try:
from robot_descriptions import DESCRIPTIONS # type: ignore[import-not-found]
from robot_descriptions import DESCRIPTIONS # ty: ignore[import-not-found]
except ImportError:
return None

Expand Down
19 changes: 15 additions & 4 deletions src/mjviser/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict
from collections.abc import Callable
from threading import RLock
from typing import Literal

import mujoco
import numpy as np
Expand Down Expand Up @@ -54,7 +55,8 @@ class _MeshGroup:
# Visualization flag commands: (label, hotkey, flag). Hotkeys match MuJoCo's
# simulate. None means MuJoCo's key is one viser reserves for camera movement
# (W/A/S/D/Q/E), so the command is only reachable from the command palette.
_VIS_FLAG_COMMANDS: list[tuple[str, str | None, int]] = [
_VisKey = Literal["C", "F", "P", "J", "I", "V", "M", "U"]
_VIS_FLAG_COMMANDS: list[tuple[str, _VisKey | None, int]] = [
("Contact Point", "C", int(mujoco.mjtVisFlag.mjVIS_CONTACTPOINT)),
("Contact Force", "F", int(mujoco.mjtVisFlag.mjVIS_CONTACTFORCE)),
("Contact Split", "P", int(mujoco.mjtVisFlag.mjVIS_CONTACTSPLIT)),
Expand All @@ -67,6 +69,15 @@ class _MeshGroup:
("Auto Connect", None, int(mujoco.mjtVisFlag.mjVIS_AUTOCONNECT)), # MuJoCo: A
]

_GEOM_GROUP_KEYS: tuple[Literal["0", "1", "2", "3", "4", "5"], ...] = (
"0",
"1",
"2",
"3",
"4",
"5",
)

# Geom type constants (avoid repeated int() casts).
_CYLINDER = int(mjtGeom.mjGEOM_CYLINDER)
_CAPSULE = int(mjtGeom.mjGEOM_CAPSULE)
Expand Down Expand Up @@ -934,11 +945,11 @@ def register_keybindings(self) -> None:
"""Register single-letter keyboard shortcuts for visualization toggles."""
server = self.server
for label, key, flag_idx in _VIS_FLAG_COMMANDS:
cmd = server.gui.add_command(f"Toggle {label}", hotkey=key) # type: ignore[arg-type]
cmd = server.gui.add_command(f"Toggle {label}", hotkey=key)
cmd.on_trigger(lambda _, _idx=flag_idx: self._toggle_vis_flag(_idx))

for i in range(6):
cmd = server.gui.add_command(f"Toggle Geom Group {i}", hotkey=str(i)) # type: ignore[arg-type]
for i, key in enumerate(_GEOM_GROUP_KEYS):
cmd = server.gui.add_command(f"Toggle Geom Group {i}", hotkey=key)
cmd.on_trigger(
lambda _, _idx=i: self._toggle_group(self._geom_group_checkboxes, _idx)
)
Expand Down
6 changes: 3 additions & 3 deletions typings/generate_mujoco_stubs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Generate type stubs for MuJoCo using pybind11-stubgen
# This helps suppress pyright errors for MuJoCo's C++ bindings
# This helps suppress ty errors for MuJoCo's C++ bindings

set -e

Expand All @@ -17,5 +17,5 @@ uv run pybind11-stubgen mujoco.viewer -o "$SCRIPT_DIR" --ignore-all-errors
echo "MuJoCo stubs generated successfully in $SCRIPT_DIR/mujoco/"
echo ""
echo "Make sure your pyproject.toml includes:"
echo " [tool.pyright]"
echo " stubPath = \"typings\""
echo " [tool.ty.environment]"
echo " extra-paths = [\"typings\"]"
Loading
Loading