Skip to content

Commit 2200d71

Browse files
committed
Address OVPhysX compatibility review feedback
1 parent 50d8f16 commit 2200d71

3 files changed

Lines changed: 40 additions & 98 deletions

File tree

source/isaaclab_ov/isaaclab_ov/physics/ovphysx_compat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
logger = logging.getLogger(__name__)
2828

29-
# First OVPhysX version that uses the current lifecycle entry points.
30-
_CURRENT_LIFECYCLE_VERSION = Version("0.6")
29+
# First OVPhysX release line that uses the current lifecycle entry points.
30+
_CURRENT_LIFECYCLE_RELEASE = (0, 6)
3131

3232

3333
def detect_ovphysx_version() -> Version | None:
@@ -62,7 +62,7 @@ def uses_current_lifecycle_api(version: Version | None) -> bool:
6262
Returns:
6363
Whether ``version`` is OVPhysX 0.6 or newer.
6464
"""
65-
return version is not None and version >= _CURRENT_LIFECYCLE_VERSION
65+
return version is not None and version.release[:2] >= _CURRENT_LIFECYCLE_RELEASE
6666

6767

6868
def build_lifecycle_entry_points(version: Version | None) -> Mapping[str, str]:

source/isaaclab_ov/test/physics/test_ovphysx_compat.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
OVPHYSX_LIFECYCLE_ENTRY_POINTS,
3030
build_lifecycle_entry_points,
3131
detect_ovphysx_version,
32-
uses_current_lifecycle_api,
3332
)
3433
else:
3534
OVPHYSX_LIFECYCLE_ENTRY_POINTS = None
3635
build_lifecycle_entry_points = None
3736
detect_ovphysx_version = None
38-
uses_current_lifecycle_api = None
37+
38+
_LEGACY_ENTRY_POINTS = {"warmup": "warmup_gpu", "destroy": "release"}
39+
_CURRENT_ENTRY_POINTS = {"warmup": "warmup", "destroy": "destroy"}
3940

4041

4142
def test_detect_ovphysx_version_reads_distribution_metadata(monkeypatch: pytest.MonkeyPatch):
@@ -59,31 +60,16 @@ def test_detect_ovphysx_version_returns_none_for_unparseable_version(monkeypatch
5960
@pytest.mark.parametrize(
6061
("version", "expected"),
6162
[
62-
(None, False),
63-
(Version("0.5.11"), False),
64-
(Version("0.5.99"), False),
65-
(Version("0.6"), True),
66-
(Version("0.6.0+trunk.e15a64a2"), True),
67-
(Version("1.0"), True),
63+
(None, _LEGACY_ENTRY_POINTS),
64+
(Version("0.5.11"), _LEGACY_ENTRY_POINTS),
65+
(Version("0.6.0.dev1+trunk.e15a64a2"), _CURRENT_ENTRY_POINTS),
66+
(Version("0.6"), _CURRENT_ENTRY_POINTS),
67+
(Version("1.0"), _CURRENT_ENTRY_POINTS),
6868
],
6969
)
70-
def test_uses_current_lifecycle_api_switches_at_ovphysx_06(version: Version | None, expected: bool):
71-
assert uses_current_lifecycle_api(version) is expected
72-
73-
74-
@pytest.mark.parametrize("version", [None, Version("0.5.11")])
75-
def test_ovphysx_0511_lifecycle_entry_points(version: Version | None):
70+
def test_lifecycle_entry_points(version: Version | None, expected: dict[str, str]):
7671
entry_points = build_lifecycle_entry_points(version)
77-
assert dict(entry_points) == {"warmup": "warmup_gpu", "destroy": "release"}
78-
79-
80-
def test_ovphysx_06_lifecycle_entry_points():
81-
entry_points = build_lifecycle_entry_points(Version("0.6"))
82-
assert dict(entry_points) == {"warmup": "warmup", "destroy": "destroy"}
83-
84-
85-
def test_installed_entry_points_match_the_installed_version():
86-
assert dict(OVPHYSX_LIFECYCLE_ENTRY_POINTS) == dict(build_lifecycle_entry_points(detect_ovphysx_version()))
72+
assert dict(entry_points) == expected
8773

8874

8975
def test_published_entry_points_are_read_only():

source/isaaclab_ov/test/physics/test_ovphysx_scene_data_backend.py

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# CI jobs that need OVPhysX coverage install it explicitly.
1818
pytest.importorskip("ovphysx.types", reason="ovphysx wheel not installed")
1919

20+
_LEGACY_LIFECYCLE_ENTRY_POINTS = {"warmup": "warmup_gpu", "destroy": "release"}
21+
_CURRENT_LIFECYCLE_ENTRY_POINTS = {"warmup": "warmup", "destroy": "destroy"}
22+
2023

2124
@pytest.fixture(autouse=True)
2225
def _close_test_views():
@@ -467,6 +470,7 @@ def test_manager_attaches_and_releases_owned_ovstage(monkeypatch):
467470
from isaaclab_ov.physics import OvPhysxManager
468471

469472
events = []
473+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", _LEGACY_LIFECYCLE_ENTRY_POINTS)
470474

471475
class FakeWriteFloorOp:
472476
def __init__(self, ordinal):
@@ -544,92 +548,44 @@ def release(self):
544548
]
545549

546550

547-
def test_manager_uses_current_warmup_api(monkeypatch):
548-
"""The version-selected current warmup API wins when both methods are visible."""
549-
from isaaclab_ov.physics import OvPhysxManager
550-
from isaaclab_ov.physics import ovphysx_manager as om_mod
551-
552-
calls = []
553-
physx = SimpleNamespace(
554-
warmup=lambda: calls.append("warmup"),
555-
warmup_gpu=lambda: calls.append("warmup_gpu"),
556-
)
557-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
558-
559-
OvPhysxManager._warmup_physx(physx)
560-
561-
assert calls == ["warmup"]
562-
563-
564-
def test_manager_uses_legacy_warmup_api(monkeypatch):
565-
"""The version-selected 0.5.11 path uses the legacy method even if both are visible."""
551+
@pytest.mark.parametrize(
552+
("entry_points", "expected_calls"),
553+
[
554+
(_LEGACY_LIFECYCLE_ENTRY_POINTS, ["warmup_gpu", "release"]),
555+
(_CURRENT_LIFECYCLE_ENTRY_POINTS, ["warmup", "destroy"]),
556+
],
557+
)
558+
def test_manager_uses_version_selected_lifecycle_apis(monkeypatch, entry_points, expected_calls):
559+
"""The selected lifecycle generation controls both entry points."""
566560
from isaaclab_ov.physics import OvPhysxManager
567561
from isaaclab_ov.physics import ovphysx_manager as om_mod
568562

569563
calls = []
570564
physx = SimpleNamespace(
571565
warmup=lambda: calls.append("warmup"),
572566
warmup_gpu=lambda: calls.append("warmup_gpu"),
573-
)
574-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup_gpu", "destroy": "release"})
575-
576-
OvPhysxManager._warmup_physx(physx)
577-
578-
assert calls == ["warmup_gpu"]
579-
580-
581-
def test_manager_rejects_missing_warmup_api(monkeypatch):
582-
"""A runtime that lacks its version-selected warmup entry point reports it."""
583-
from isaaclab_ov.physics import OvPhysxManager
584-
from isaaclab_ov.physics import ovphysx_manager as om_mod
585-
586-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
587-
with pytest.raises(AttributeError, match=r"selected warmup\(\) lifecycle entry point"):
588-
OvPhysxManager._warmup_physx(SimpleNamespace())
589-
590-
591-
def test_manager_uses_current_destroy_api(monkeypatch):
592-
"""A current OVPhysX runtime tears down through destroy()."""
593-
from isaaclab_ov.physics import OvPhysxManager
594-
from isaaclab_ov.physics import ovphysx_manager as om_mod
595-
596-
calls = []
597-
physx = SimpleNamespace(
598567
destroy=lambda: calls.append("destroy"),
599568
release=lambda: calls.append("release"),
600569
)
601-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
602-
603-
OvPhysxManager._destroy_physx(physx)
604-
605-
assert calls == ["destroy"]
606-
607-
608-
def test_manager_uses_legacy_release_api(monkeypatch):
609-
"""The version-selected 0.5.11 path uses release() even if both methods are visible."""
610-
from isaaclab_ov.physics import OvPhysxManager
611-
from isaaclab_ov.physics import ovphysx_manager as om_mod
612-
613-
calls = []
614-
physx = SimpleNamespace(
615-
destroy=lambda: calls.append("destroy"),
616-
release=lambda: calls.append("release"),
617-
)
618-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup_gpu", "destroy": "release"})
570+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", entry_points)
619571

572+
OvPhysxManager._warmup_physx(physx)
620573
OvPhysxManager._destroy_physx(physx)
621574

622-
assert calls == ["release"]
575+
assert calls == expected_calls
623576

624577

625-
def test_manager_rejects_missing_destroy_api(monkeypatch):
626-
"""A runtime that lacks its version-selected destroy entry point reports it."""
578+
@pytest.mark.parametrize("operation", ["warmup", "destroy"])
579+
def test_manager_rejects_missing_lifecycle_api(monkeypatch, operation):
580+
"""A runtime that lacks its selected lifecycle entry point reports it."""
627581
from isaaclab_ov.physics import OvPhysxManager
628582
from isaaclab_ov.physics import ovphysx_manager as om_mod
629583

630-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
631-
with pytest.raises(AttributeError, match=r"selected destroy\(\) lifecycle entry point"):
632-
OvPhysxManager._destroy_physx(SimpleNamespace())
584+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", _CURRENT_LIFECYCLE_ENTRY_POINTS)
585+
entry_point = _CURRENT_LIFECYCLE_ENTRY_POINTS[operation]
586+
lifecycle_method = getattr(OvPhysxManager, f"_{operation}_physx")
587+
with pytest.raises(AttributeError, match=rf"selected {entry_point}\(\) lifecycle entry point"):
588+
lifecycle_method(SimpleNamespace())
633589

634590

635591
def test_manager_releases_legacy_owners_after_release_error(monkeypatch):
@@ -638,7 +594,7 @@ def test_manager_releases_legacy_owners_after_release_error(monkeypatch):
638594
from isaaclab_ov.physics import ovphysx_manager as om_mod
639595

640596
events = []
641-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup_gpu", "destroy": "release"})
597+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", _LEGACY_LIFECYCLE_ENTRY_POINTS)
642598

643599
class FakePhysX:
644600
def reset_stage(self):
@@ -679,7 +635,7 @@ def test_manager_retries_current_destroy_before_releasing_owners(monkeypatch):
679635
from isaaclab_ov.physics import ovphysx_manager as om_mod
680636

681637
events = []
682-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
638+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", _CURRENT_LIFECYCLE_ENTRY_POINTS)
683639

684640
class FakePhysX:
685641
fail_destroy = True
@@ -745,7 +701,7 @@ def test_manager_releases_owners_after_terminal_destroy_error(monkeypatch):
745701
from isaaclab_ov.physics import ovphysx_manager as om_mod
746702

747703
events = []
748-
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", {"warmup": "warmup", "destroy": "destroy"})
704+
monkeypatch.setattr(om_mod, "OVPHYSX_LIFECYCLE_ENTRY_POINTS", _CURRENT_LIFECYCLE_ENTRY_POINTS)
749705

750706
class FakePhysX:
751707
terminal = False

0 commit comments

Comments
 (0)