Unverified Commit ff4b4d02 authored by AutonomousHansen's avatar AutonomousHansen Committed by GitHub

Adds string checking to `orbit.sim.utils` function calls (#429)

# Description

Adds string checking to the functions which accept path-types, casting
them to a `str` if they are not already. Closing #421 in favor of this
fix, see discussion for initial rationale. This solution is superior
because this addresses all of the changes, not just the one causing a
test to fail.

Fixes #420 

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have run all the tests with `./orbit.sh --test` and they pass
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Signed-off-by: 's avatarAutonomousHansen <50837800+AutonomousHansen@users.noreply.github.com>
parent e1534550
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.10.24"
version = "0.10.25"
# Description
title = "ORBIT framework for Robot Learning"
......
Changelog
---------
0.10.25 (2024-02-26)
~~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Ensures that all path arguments in :mod:`omni.isaac.orbit.sim.utils` are cast to ``str``. Previously we had handled path types as strings without casting.
0.10.24 (2024-02-26)
~~~~~~~~~~~~~~~~~~~~
......
......@@ -147,7 +147,7 @@ def apply_nested(func: Callable) -> Callable:
"""
@functools.wraps(func)
def wrapper(prim_path: str, *args, **kwargs):
def wrapper(prim_path: str | Sdf.Path, *args, **kwargs):
# map args and kwargs to function signature so we can get the stage
# note: we do this to check if stage is given in arg or kwarg
sig = inspect.signature(func)
......@@ -216,7 +216,9 @@ def clone(func: Callable) -> Callable:
"""
@functools.wraps(func)
def wrapper(prim_path: str, cfg: SpawnerCfg, *args, **kwargs):
def wrapper(prim_path: str | Sdf.Path, cfg: SpawnerCfg, *args, **kwargs):
# cast prim_path to str type in case its an Sdf.Path
prim_path = str(prim_path)
# check prim path is global
if not prim_path.startswith("/"):
raise ValueError(f"Prim path '{prim_path}' is not global. It must start with '/'.")
......@@ -291,7 +293,10 @@ Material bindings.
@apply_nested
def bind_visual_material(
prim_path: str, material_path: str, stage: Usd.Stage | None = None, stronger_than_descendants: bool = True
prim_path: str | Sdf.Path,
material_path: str | Sdf.Path,
stage: Usd.Stage | None = None,
stronger_than_descendants: bool = True,
):
"""Bind a visual material to a prim.
......@@ -343,7 +348,10 @@ def bind_visual_material(
@apply_nested
def bind_physics_material(
prim_path: str, material_path: str, stage: Usd.Stage | None = None, stronger_than_descendants: bool = True
prim_path: str | Sdf.Path,
material_path: str | Sdf.Path,
stage: Usd.Stage | None = None,
stronger_than_descendants: bool = True,
):
"""Bind a physics material to a prim.
......@@ -413,7 +421,12 @@ Exporting.
"""
def export_prim_to_file(path: str, source_prim_path: str, target_prim_path: str = None, stage: Usd.Stage | None = None):
def export_prim_to_file(
path: str | Sdf.Path,
source_prim_path: str | Sdf.Path,
target_prim_path: str | Sdf.Path | None = None,
stage: Usd.Stage | None = None,
):
"""Exports a prim from a given stage to a USD file.
The function creates a new layer at the provided path and copies the prim to the layer.
......@@ -431,7 +444,13 @@ def export_prim_to_file(path: str, source_prim_path: str, target_prim_path: str
Raises:
ValueError: If the prim paths are not global (i.e: do not start with '/').
"""
# check prim path is global
# automatically casting to str in case args
# are path types
path = str(path)
source_prim_path = str(source_prim_path)
if target_prim_path is not None:
target_prim_path = str(target_prim_path)
if not source_prim_path.startswith("/"):
raise ValueError(f"Source prim path '{source_prim_path}' is not global. It must start with '/'.")
if target_prim_path is not None and not target_prim_path.startswith("/"):
......@@ -474,7 +493,7 @@ USD Prim properties.
"""
def make_uninstanceable(prim_path: str, stage: Usd.Stage | None = None):
def make_uninstanceable(prim_path: str | Sdf.Path, stage: Usd.Stage | None = None):
"""Check if a prim and its descendants are instanced and make them uninstanceable.
This function checks if the prim at the specified prim path and its descendants are instanced.
......@@ -490,6 +509,8 @@ def make_uninstanceable(prim_path: str, stage: Usd.Stage | None = None):
Raises:
ValueError: If the prim path is not global (i.e: does not start with '/').
"""
# make paths str type if they aren't already
prim_path = str(prim_path)
# check if prim path is global
if not prim_path.startswith("/"):
raise ValueError(f"Prim path '{prim_path}' is not global. It must start with '/'.")
......@@ -520,7 +541,7 @@ USD Stage traversal.
def get_first_matching_child_prim(
prim_path: str, predicate: Callable[[Usd.Prim], bool], stage: Usd.Stage | None = None
prim_path: str | Sdf.Path, predicate: Callable[[Usd.Prim], bool], stage: Usd.Stage | None = None
) -> Usd.Prim | None:
"""Recursively get the first USD Prim at the path string that passes the predicate function
......@@ -535,6 +556,8 @@ def get_first_matching_child_prim(
Raises:
ValueError: If the prim path is not global (i.e: does not start with '/').
"""
# make paths str type if they aren't already
prim_path = str(prim_path)
# check if prim path is global
if not prim_path.startswith("/"):
raise ValueError(f"Prim path '{prim_path}' is not global. It must start with '/'.")
......@@ -560,7 +583,7 @@ def get_first_matching_child_prim(
def get_all_matching_child_prims(
prim_path: str,
prim_path: str | Sdf.Path,
predicate: Callable[[Usd.Prim], bool] = lambda _: True,
depth: int | None = None,
stage: Usd.Stage | None = None,
......@@ -581,6 +604,8 @@ def get_all_matching_child_prims(
Raises:
ValueError: If the prim path is not global (i.e: does not start with '/').
"""
# make paths str type if they aren't already
prim_path = str(prim_path)
# check if prim path is global
if not prim_path.startswith("/"):
raise ValueError(f"Prim path '{prim_path}' is not global. It must start with '/'.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment