Skip to content

Commit 731622e

Browse files
authored
Remove pkg_resources as a dependency (#286)
* Clean imports in control_window.py * Remove use of pkg_resources * Add importlib_resources as dependency * Add conditional import statement for python <=3.8 support * Simplify render_window importlib usage
1 parent 5e6c676 commit 731622e

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

python/py_package/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616
#
1717
from warnings import warn
18-
import pkg_resources
1918
import os
19+
import sys
2020
from pathlib import Path
2121
import platform
2222
from .version import __version__
@@ -47,12 +47,17 @@
4747
from .wrapper.articulation_builder import ArticulationBuilder
4848
from .wrapper.pinocchio_model import PinocchioModel
4949

50-
import pkg_resources
50+
if sys.version_info >= (3, 9):
51+
import importlib.resources as resources
52+
else:
53+
import importlib_resources as resources
5154

5255
try:
5356
render.set_imgui_ini_filename(str(Path.home() / ".sapien" / "imgui.ini"))
5457
pysapien.render._internal_set_shader_search_path(
55-
pkg_resources.resource_filename("sapien", "vulkan_shader")
58+
str(
59+
resources.files("sapien") / "vulkan_shader"
60+
)
5661
)
5762
render.set_viewer_shader_dir("default")
5863
render.set_camera_shader_dir("default")

python/py_package/__init__.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ from __future__ import annotations
22
from _warnings import warn
33
import os as os
44
from pathlib._local import Path
5-
import pkg_resources as pkg_resources
65
import platform as platform
76
from sapien.pysapien import Component
87
from sapien.pysapien import CudaArray
@@ -33,6 +32,5 @@ from . import render
3332
from . import utils
3433
from . import version
3534
from . import wrapper
36-
__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']
35+
__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']
3736
__version__: str = '3.0.0.dev20251208+67ae2a67'
38-
__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}

python/py_package/_vulkan_tricks.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
import pkg_resources
18-
from warnings import warn
19-
import platform
2017
import os
18+
import platform
19+
import sys
20+
from warnings import warn
21+
22+
if sys.version_info >= (3, 9):
23+
import importlib.resources as resources
24+
else:
25+
import importlib_resources as resources
2126

2227

2328
def _ensure_libvulkan_linux():
@@ -30,8 +35,8 @@ def _ensure_libvulkan_linux():
3035
return
3136

3237
# add our vulkan to LD_LIBRARY_PATH
33-
vulkan_library_path = pkg_resources.resource_filename(
34-
"sapien", "vulkan_library/libvulkan.so.1.3.224"
38+
vulkan_library_path = str(
39+
resources.files("sapien") / "vulkan_library/libvulkan.so.1.3.224"
3540
)
3641

3742
warn("Failed to find system libvulkan. Fallback to SAPIEN builtin libvulkan.")
@@ -51,8 +56,8 @@ def _ensure_libvulkan_mac():
5156
if os.path.isfile(libPath):
5257
os.environ["SAPIEN_VULKAN_LIBRARY_PATH"] = libPath
5358
return
54-
vulkan_library_path = pkg_resources.resource_filename(
55-
"sapien", "vulkan_library/libvulkan.1.3.290.dylib"
59+
vulkan_library_path = str(
60+
resources.files("sapien") / "vulkan_library/libvulkan.1.3.290.dylib"
5661
)
5762

5863
warn("Failed to find system libvulkan. Fallback to SAPIEN builtin libvulkan.")
@@ -73,8 +78,8 @@ def _ensure_vulkan_icd():
7378
warn(
7479
"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."
7580
)
76-
os.environ["VK_ICD_FILENAMES"] = pkg_resources.resource_filename(
77-
"sapien", "vulkan_library/nvidia_icd.json"
81+
os.environ["VK_ICD_FILENAMES"] = str(
82+
resources.files("sapien") / "vulkan_library/nvidia_icd.json"
7883
)
7984

8085

@@ -96,8 +101,8 @@ def _ensure_egl_icd():
96101
"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."
97102
)
98103

99-
os.environ["__EGL_VENDOR_LIBRARY_FILENAMES"] = pkg_resources.resource_filename(
100-
"sapien", "vulkan_library/10_nvidia.json"
104+
os.environ["__EGL_VENDOR_LIBRARY_FILENAMES"] = str(
105+
resources.files("sapien") / "vulkan_library/10_nvidia.json"
101106
)
102107

103108

python/py_package/utils/viewer/control_window.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
# limitations under the License.
1616
#
1717
import os
18-
from pathlib import Path
19-
from typing import List
2018

2119
import numpy as np
22-
import pkg_resources
2320
import sapien
2421
from sapien import internal_renderer as R
25-
from transforms3d.quaternions import mat2quat
2622
from transforms3d.euler import quat2euler
23+
from transforms3d.quaternions import mat2quat
2724

2825
from .camera_control import ArcRotateCameraController, FPSCameraController
2926
from .plugin import Plugin, copy_to_clipboard

python/py_package/utils/viewer/render_window.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17+
import sys
1718
from pathlib import Path
1819

1920
import numpy as np
20-
import pkg_resources
2121
import sapien
2222
from sapien import internal_renderer as R
2323

2424
from .plugin import Plugin
2525

26+
if sys.version_info >= (3, 9):
27+
import importlib.resources as resources
28+
else:
29+
import importlib_resources as resources
2630

2731
class RenderOptionsWindow(Plugin):
2832
def __init__(self):
@@ -156,10 +160,7 @@ def _setup_shader_dir(self):
156160
self.shader_types = []
157161

158162
try:
159-
all_shader_dir = Path(
160-
pkg_resources.resource_filename("sapien", "vulkan_shader")
161-
)
162-
163+
all_shader_dir = Path(str(resources.files("sapien") / "vulkan_shader"))
163164
for f in all_shader_dir.iterdir():
164165
if f.is_dir():
165166
if any("gbuffer.frag" in x.name for x in f.iterdir()):

python/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ networkx
66
pyperclip
77
opencv-python>=4.0
88
setuptools
9+
importlib_resources

0 commit comments

Comments
 (0)