Skip to content

Commit f183810

Browse files
AnteloxArusekk
andauthored
Python bindings: Port pkg_resources to importlib_resources for python < 3.9 (#2123)
* Python bindings: Port pkg_resources to importlib_resources for python < 3.9 Co-authored-by: Arusekk <[email protected]> * GitHub Workflow: Bump uraimo/run-on-arch-action to v3 --------- Co-authored-by: Arusekk <[email protected]>
1 parent 9da2fec commit f183810

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

.github/workflows/Nuget-publishing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ jobs:
288288
289289
- name: '🚧 Linux ppc64le build'
290290
if: contains(matrix.config.arch, 'ppc64le')
291-
uses: uraimo/run-on-arch-action@v2
291+
uses: uraimo/run-on-arch-action@v3
292292
with:
293293
arch: ${{ matrix.config.arch }}
294294
distro: ${{ matrix.config.distro }}

.github/workflows/build-uc2.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ jobs:
494494
495495
- name: '🚧 Linux ppc64le build'
496496
if: contains(matrix.config.arch, 'ppc64le')
497-
uses: uraimo/run-on-arch-action@v2
497+
uses: uraimo/run-on-arch-action@v3
498498
with:
499499
arch: ${{ matrix.config.arch }}
500500
distro: ${{ matrix.config.distro }}

.github/workflows/build-wheels-publish.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,9 @@ jobs:
296296

297297
- name: Build SDist
298298
run: |
299-
cd bindings/python
300299
python3 -m pip install -U pip build
301-
python3 -m build --sdist
302-
python3 -m pip install dist/*.tar.gz
303-
cd ~
300+
python3 -m build --sdist bindings/python
301+
python3 -m pip install bindings/python/dist/*.tar.gz
304302
python3 -c 'import unicorn; print(f"Unicorn version installed from sdist: {unicorn.__version__}")'
305303
306304
- uses: actions/upload-artifact@v4

bindings/python/pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ build-backend = "setuptools.build_meta"
66
name = "unicorn"
77
dynamic = ["version"]
88
requires-python = ">= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.*, != 3.5.*, != 3.6.*"
9+
dependencies = [
10+
"importlib_resources; python_version < '3.9'"
11+
]
912
authors = [
1013
{ name = "Nguyen Anh Quynh", email = "[email protected]" },
1114
]

bindings/python/unicorn/unicorn_py3/unicorn.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,17 @@ def _load_lib(path: Path, lib_name: str):
109109

110110
# Loading attempts, in order
111111
# - user-provided environment variable
112-
# - pkg_resources can get us the path to the local libraries
112+
# - importlib.resources/importlib_resources can get us the path to the local libraries
113113
# - we can get the path to the local libraries by parsing our filename
114114
# - global load
115115
# - python's lib directory
116116

117-
if sys.version_info.minor >= 12:
118-
from importlib import resources
119-
120-
canonicals = resources.files('unicorn') / 'lib'
117+
if sys.version_info >= (3, 9):
118+
import importlib.resources as resources
121119
else:
122-
import pkg_resources
120+
import importlib_resources as resources
123121

124-
canonicals = pkg_resources.resource_filename('unicorn', 'lib')
122+
canonicals = resources.files('unicorn') / 'lib'
125123

126124
lib_locations = [
127125
os.getenv('LIBUNICORN_PATH'),

0 commit comments

Comments
 (0)