diff --git a/python/py_package/__init__.py b/python/py_package/__init__.py index 6b14f396..2db413c3 100644 --- a/python/py_package/__init__.py +++ b/python/py_package/__init__.py @@ -15,8 +15,8 @@ # limitations under the License. # from warnings import warn -import pkg_resources import os +import sys from pathlib import Path import platform from .version import __version__ @@ -47,12 +47,17 @@ from .wrapper.articulation_builder import ArticulationBuilder from .wrapper.pinocchio_model import PinocchioModel -import pkg_resources +if sys.version_info >= (3, 9): + import importlib.resources as resources +else: + import importlib_resources as resources try: render.set_imgui_ini_filename(str(Path.home() / ".sapien" / "imgui.ini")) pysapien.render._internal_set_shader_search_path( - pkg_resources.resource_filename("sapien", "vulkan_shader") + str( + resources.files("sapien") / "vulkan_shader" + ) ) render.set_viewer_shader_dir("default") render.set_camera_shader_dir("default") diff --git a/python/py_package/__init__.pyi b/python/py_package/__init__.pyi index caadffe4..6c974275 100644 --- a/python/py_package/__init__.pyi +++ b/python/py_package/__init__.pyi @@ -2,7 +2,6 @@ from __future__ import annotations from _warnings import warn import os as os from pathlib._local import Path -import pkg_resources as pkg_resources import platform as platform from sapien.pysapien import Component from sapien.pysapien import CudaArray @@ -33,6 +32,5 @@ from . import render from . import utils from . import version from . import wrapper -__all__ = ['ActorBuilder', 'ArticulationBuilder', 'Component', 'CudaArray', 'Device', 'Engine', 'Entity', 'Path', 'PinocchioModel', 'Pose', 'SapienRenderer', 'Scene', 'SceneConfig', 'System', 'Widget', 'asset', 'internal_renderer', 'math', 'os', 'physx', 'pkg_resources', 'platform', 'profile', 'pysapien', 'pysapien_pinocchio', 'render', 'set_log_level', 'simsense', 'utils', 'version', 'warn', 'wrapper'] +__all__ = ['ActorBuilder', 'ArticulationBuilder', 'Component', 'CudaArray', 'Device', 'Engine', 'Entity', 'Path', 'PinocchioModel', 'Pose', 'SapienRenderer', 'Scene', 'SceneConfig', 'System', 'Widget', 'asset', 'internal_renderer', 'math', 'os', 'physx', 'platform', 'profile', 'pysapien', 'pysapien_pinocchio', 'render', 'set_log_level', 'simsense', 'utils', 'version', 'warn', 'wrapper'] __version__: str = '3.0.0.dev20251208+67ae2a67' -__warningregistry__: dict = {'version': 0, ('pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.', UserWarning, 18): True} diff --git a/python/py_package/_vulkan_tricks.py b/python/py_package/_vulkan_tricks.py index d9e2cf16..d5933632 100644 --- a/python/py_package/_vulkan_tricks.py +++ b/python/py_package/_vulkan_tricks.py @@ -14,10 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import pkg_resources -from warnings import warn -import platform import os +import platform +import sys +from warnings import warn + +if sys.version_info >= (3, 9): + import importlib.resources as resources +else: + import importlib_resources as resources def _ensure_libvulkan_linux(): @@ -30,8 +35,8 @@ def _ensure_libvulkan_linux(): return # add our vulkan to LD_LIBRARY_PATH - vulkan_library_path = pkg_resources.resource_filename( - "sapien", "vulkan_library/libvulkan.so.1.3.224" + vulkan_library_path = str( + resources.files("sapien") / "vulkan_library/libvulkan.so.1.3.224" ) warn("Failed to find system libvulkan. Fallback to SAPIEN builtin libvulkan.") @@ -51,8 +56,8 @@ def _ensure_libvulkan_mac(): if os.path.isfile(libPath): os.environ["SAPIEN_VULKAN_LIBRARY_PATH"] = libPath return - vulkan_library_path = pkg_resources.resource_filename( - "sapien", "vulkan_library/libvulkan.1.3.290.dylib" + vulkan_library_path = str( + resources.files("sapien") / "vulkan_library/libvulkan.1.3.290.dylib" ) warn("Failed to find system libvulkan. Fallback to SAPIEN builtin libvulkan.") @@ -73,8 +78,8 @@ def _ensure_vulkan_icd(): warn( "Failed to find Vulkan ICD file. This is probably due to an incorrect or partial installation of the NVIDIA driver. SAPIEN will attempt to provide an ICD file anyway but it may not work." ) - os.environ["VK_ICD_FILENAMES"] = pkg_resources.resource_filename( - "sapien", "vulkan_library/nvidia_icd.json" + os.environ["VK_ICD_FILENAMES"] = str( + resources.files("sapien") / "vulkan_library/nvidia_icd.json" ) @@ -96,8 +101,8 @@ def _ensure_egl_icd(): "Failed to find glvnd ICD file. This is probably due to an incorrect or partial installation of the NVIDIA driver. SAPIEN will attempt to provide an ICD file anyway but it may not work." ) - os.environ["__EGL_VENDOR_LIBRARY_FILENAMES"] = pkg_resources.resource_filename( - "sapien", "vulkan_library/10_nvidia.json" + os.environ["__EGL_VENDOR_LIBRARY_FILENAMES"] = str( + resources.files("sapien") / "vulkan_library/10_nvidia.json" ) diff --git a/python/py_package/utils/viewer/control_window.py b/python/py_package/utils/viewer/control_window.py index b6c98ecd..b8d9a2ab 100644 --- a/python/py_package/utils/viewer/control_window.py +++ b/python/py_package/utils/viewer/control_window.py @@ -15,15 +15,12 @@ # limitations under the License. # import os -from pathlib import Path -from typing import List import numpy as np -import pkg_resources import sapien from sapien import internal_renderer as R -from transforms3d.quaternions import mat2quat from transforms3d.euler import quat2euler +from transforms3d.quaternions import mat2quat from .camera_control import ArcRotateCameraController, FPSCameraController from .plugin import Plugin, copy_to_clipboard diff --git a/python/py_package/utils/viewer/render_window.py b/python/py_package/utils/viewer/render_window.py index 634ee47a..090235e9 100644 --- a/python/py_package/utils/viewer/render_window.py +++ b/python/py_package/utils/viewer/render_window.py @@ -14,15 +14,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys from pathlib import Path import numpy as np -import pkg_resources import sapien from sapien import internal_renderer as R from .plugin import Plugin +if sys.version_info >= (3, 9): + import importlib.resources as resources +else: + import importlib_resources as resources class RenderOptionsWindow(Plugin): def __init__(self): @@ -156,10 +160,7 @@ def _setup_shader_dir(self): self.shader_types = [] try: - all_shader_dir = Path( - pkg_resources.resource_filename("sapien", "vulkan_shader") - ) - + all_shader_dir = Path(str(resources.files("sapien") / "vulkan_shader")) for f in all_shader_dir.iterdir(): if f.is_dir(): if any("gbuffer.frag" in x.name for x in f.iterdir()): diff --git a/python/requirements.txt b/python/requirements.txt index c772184b..f6d45ca0 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -6,3 +6,4 @@ networkx pyperclip opencv-python>=4.0 setuptools +importlib_resources