Source code for state_space_setup_assistant.resources

"""Resource resolution: package:// URIs and containment-guarded mesh paths."""

import os
from typing import Optional

from urdf_state_space.config import resolve_resource, _read_urdf  # noqa: F401


[docs] def load_urdf(source: str, base_dir: str = '.') -> tuple: """Resolve ``source`` (path or package:// URI) and return (absolute_path, processed_urdf_xml). Runs xacro on .xacro files.""" path = resolve_resource(source, base_dir) path = os.path.abspath(path) if not os.path.isfile(path): raise FileNotFoundError(f'URDF not found: {path} (from {source!r})') return path, _read_urdf(path)
[docs] def safe_share_path(package: str, relative: str) -> Optional[str]: """Absolute path of ``relative`` inside ``package``'s share directory, or None if it escapes the share dir (traversal) or does not exist. Raises LookupError if the package itself is unknown (workspace not built/sourced). """ from ament_index_python.packages import ( get_package_share_directory, PackageNotFoundError) try: share = os.path.realpath(get_package_share_directory(package)) except PackageNotFoundError as exc: raise LookupError( f'package {package!r} not found -- build and source the ' 'workspace so its share directory is on the ament index') from exc candidate = os.path.realpath(os.path.join(share, relative)) if not (candidate == share or candidate.startswith(share + os.sep)): return None if not os.path.isfile(candidate): return None return candidate