diff --git a/docs/guide.rst b/docs/guide.rst index fdd39a4c..22c1a2c6 100644 --- a/docs/guide.rst +++ b/docs/guide.rst @@ -246,3 +246,9 @@ Freezing apps In wgpu a PyInstaller-hook is provided to help simplify the freezing process (it e.g. ensures that the wgpu-native DLL is included). This hook requires PyInstaller version 4+. + +Our hook also includes ``glfw`` when it is available, so code using ``wgpu.gui.auto`` +should Just Work. + +Note that PyInstaller needs ``wgpu`` to be installed in `site-packages` for +the hook to work (i.e. it seems not to work with a ``pip -e .`` dev install). diff --git a/wgpu/_coreutils.py b/wgpu/_coreutils.py index 1365412e..2dbbd8b9 100644 --- a/wgpu/_coreutils.py +++ b/wgpu/_coreutils.py @@ -3,13 +3,26 @@ """ import re +import sys +import atexit import logging -from pkg_resources import resource_filename +import importlib.resources +from contextlib import ExitStack + + +_resource_files = ExitStack() +atexit.register(_resource_files.close) def get_resource_filename(name): """Get the filename to a wgpu resource.""" - return resource_filename("wgpu.resources", name) + if sys.version_info < (3, 9): + context = importlib.resources.path("wgpu.resources", name) + else: + ref = importlib.resources.files("wgpu.resources") / name + context = importlib.resources.as_file(ref) + path = _resource_files.enter_context(context) + return str(path) class WGPULogger(logging.getLoggerClass()): diff --git a/wgpu/resources/__init__.py b/wgpu/resources/__init__.py index 3e6de0fc..eca5e0ff 100644 --- a/wgpu/resources/__init__.py +++ b/wgpu/resources/__init__.py @@ -1,2 +1,2 @@ -""" This module exists to have setuptools recognize the folder as a module +""" This module exists to have importlib.resources and setuptools recognize the folder as a module. """