Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b0ab7fd

Browse files
AnteloxArusekk
andcommittedMar 3, 2025·
Python bindings: Port pkg_resources to importlib_resources for python < 3.9
Co-authored-by: Arusekk <floss@arusekk.pl>
1 parent 2128e01 commit b0ab7fd

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed
 

‎.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 = "quynh@gmail.com" },
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)
Please sign in to comment.