Skip to content

Commit

Permalink
Replace pkg_resources with importlib.resources
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Nov 17, 2023
1 parent 071f0f0 commit 9dcb556
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
17 changes: 15 additions & 2 deletions wgpu/_coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion wgpu/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""

0 comments on commit 9dcb556

Please sign in to comment.