Skip to content

Commit a009e30

Browse files
committed
Fix Python 3.8 to 3.11
Previous logic required old setuptools on py3.8 up to py3.11. So if new setuptools was installed, importing unicorn always failed with ImportError on these Python versions. It now tries to use old setuptools on py3.8, but falls back gracefully to not using anything. So it works on py3.9+ fully, and on py3.8 it also works but with more limited path discovery (I think it is enough, since no one complained yet). Fixes: 0c34496 ("Modify canonicals import") Ref: unicorn-engine@0c34496 Ref: Gallopsled/pwntools#2556
1 parent 2128e01 commit a009e30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bindings/python/unicorn/unicorn_py3/unicorn.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,17 @@ def _load_lib(path: Path, lib_name: str):
114114
# - global load
115115
# - python's lib directory
116116

117-
if sys.version_info.minor >= 12:
117+
if sys.version_info >= (3, 9):
118118
from importlib import resources
119119

120120
canonicals = resources.files('unicorn') / 'lib'
121121
else:
122-
import pkg_resources
122+
try:
123+
import pkg_resources
123124

124-
canonicals = pkg_resources.resource_filename('unicorn', 'lib')
125+
canonicals = pkg_resources.resource_filename('unicorn', 'lib')
126+
except ImportError:
127+
canonicals = None
125128

126129
lib_locations = [
127130
os.getenv('LIBUNICORN_PATH'),

0 commit comments

Comments
 (0)