From 92b1bbbf82ea377224a4ba9420f9ed3d7da37c81 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 31 May 2024 13:55:45 -0700 Subject: [PATCH 1/7] Create pyproject.toml and add python 3.12 to CI --- .github/workflows/CITest.yml | 8 ++++++++ bindings/python/pyproject.toml | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 bindings/python/pyproject.toml diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index e37375b08b..d46454733f 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -74,6 +74,14 @@ jobs: build-system: 'cmake', enable-asan: 'ON' } + - { + name: 'ubuntu-22.04 x64 python3.12 cmake', + os: ubuntu-22.04, + arch: x64, + python-arch: x64, + python-version: '3.12', + build-system: 'cmake', + } steps: - uses: actions/checkout@v3 diff --git a/bindings/python/pyproject.toml b/bindings/python/pyproject.toml new file mode 100644 index 0000000000..9787c3bdf0 --- /dev/null +++ b/bindings/python/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" From c5d390d8ddb974ea6f977900544f967b44182353 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 31 May 2024 14:29:25 -0700 Subject: [PATCH 2/7] Remove pkg_resources --- bindings/python/capstone/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 288b705688..cc41466de9 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -385,7 +385,7 @@ import ctypes, ctypes.util from os.path import split, join, dirname import sysconfig -import pkg_resources +from importlib import resources import inspect if not hasattr(sys.modules[__name__], '__file__'): @@ -415,14 +415,14 @@ def _load_lib(path): # Loading attempts, in order # - user-provided environment variable -# - pkg_resources can get us the path to the local libraries +# - importlib.resources can get us the path to the local libraries # - we can get the path to the local libraries by parsing our filename # - global load # - python's lib directory # - last-gasp attempt at some hardcoded paths on darwin and linux _path_list = [os.getenv('LIBCAPSTONE_PATH', None), - pkg_resources.resource_filename(__name__, 'lib'), + resources.files(__name__) / "lib", join(split(__file__)[0], 'lib'), '', sysconfig.get_path('platlib'), From edc6bb06b9303accdcae3f9eb238e1abe9bc3b35 Mon Sep 17 00:00:00 2001 From: Pyrox Date: Mon, 10 Jun 2024 22:33:40 -0400 Subject: [PATCH 3/7] Remove distutils Removes distutils from the setup.py script for the python bindings, as it is removed in Python 3.12 onwards. --- bindings/python/setup.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 02f64f16f3..3ed19174fd 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -6,13 +6,16 @@ import sys import platform -from distutils import log +import logging from setuptools import setup -from distutils.util import get_platform -from distutils.command.build import build -from distutils.command.sdist import sdist +from sysconfig import get_platform +from setuptools.command.build import build +from setuptools.command.sdist import sdist from setuptools.command.bdist_egg import bdist_egg +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + SYSTEM = sys.platform # adapted from commit e504b81 of Nguyen Tan Cong @@ -102,7 +105,7 @@ def copy_sources(): for filename in src: outpath = os.path.join(SRC_DIR, os.path.basename(filename)) - log.info("%s -> %s" % (filename, outpath)) + logger.info("%s -> %s" % (filename, outpath)) shutil.copy(filename, outpath) def build_libraries(): @@ -123,7 +126,7 @@ def build_libraries(): # if prebuilt libraries are available, use those and cancel build if os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE)) and \ (not STATIC_LIBRARY_FILE or os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE))): - log.info('Using prebuilt libraries') + logger.info('Using prebuilt libraries') shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE), LIBS_DIR) if STATIC_LIBRARY_FILE is not None: shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE), LIBS_DIR) @@ -167,9 +170,9 @@ def run(self): class custom_build(build): def run(self): if 'LIBCAPSTONE_PATH' in os.environ: - log.info('Skipping building C extensions since LIBCAPSTONE_PATH is set') + logger.info('Skipping building C extensions since LIBCAPSTONE_PATH is set') else: - log.info('Building C extensions') + logger.info('Building C extensions') build_libraries() return build.run(self) @@ -191,7 +194,7 @@ def dummy_src(): from setuptools.command.develop import develop class custom_develop(develop): def run(self): - log.info("Building C extensions") + logger.info("Building C extensions") build_libraries() return develop.run(self) @@ -218,7 +221,7 @@ def run(self): url='https://www.capstone-engine.org', long_description=open('README.txt', encoding="utf8").read(), long_description_content_type='text/markdown', - python_requires='>=3.6', + python_requires='>=3.7', classifiers=[ 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 3', From 60c2a95ed6de310e0ae89520d3eab83be0db165f Mon Sep 17 00:00:00 2001 From: Pyrox Date: Sat, 15 Jun 2024 12:35:57 -0400 Subject: [PATCH 4/7] Remove python 3.6 from CI Tests Since support is removed per maintainer request, this should be removed from the test suite as well. --- .github/workflows/CITest.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index d46454733f..7d80d09276 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -29,15 +29,6 @@ jobs: fail-fast: false matrix: config: - - { - name: 'ubuntu-20.04 x64 python3.6 cmake', - os: ubuntu-20.04, - arch: x64, - python-arch: x64, - python-version: '3.6', - build-system: 'cmake', - enable-asan: 'OFF' - } - { name: 'ubuntu-22.04 x64 python3.9 make', os: ubuntu-22.04, From 70450ab768fc804ebf4b7a0e785bf90bece4d852 Mon Sep 17 00:00:00 2001 From: Pyrox Date: Mon, 17 Jun 2024 12:25:23 -0400 Subject: [PATCH 5/7] Add setuptools to python bindings tests Needed to fix a setuptools error on python 3.9 --- .github/workflows/CITest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 7d80d09276..4afeb689f2 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -176,6 +176,7 @@ jobs: - name: run python binding test if: matrix.config.enable-asan == 'OFF' run: | + pip install --upgrade setuptools cp libcapstone.* bindings/python/prebuilt cd bindings/python make install From 482478718d8d0d657fe935964534029a1ce75fdd Mon Sep 17 00:00:00 2001 From: Pyrox Date: Wed, 19 Jun 2024 11:57:24 -0400 Subject: [PATCH 6/7] Fix fuzz tests in CI --- .github/workflows/fuzz.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 86fcfe451a..f74438cc66 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -21,3 +21,5 @@ jobs: with: name: artifacts path: ./out/artifacts + - name: Install Python Dependencies + run: python -m pip install --upgrade setuptools build wheel From edde551eb329c3cb0c9f3297fe134fff8604b5f7 Mon Sep 17 00:00:00 2001 From: Pyrox Date: Wed, 19 Jun 2024 11:57:33 -0400 Subject: [PATCH 7/7] Fix cython bindings --- bindings/python/capstone/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index cc41466de9..1b27f15f52 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -386,6 +386,7 @@ from os.path import split, join, dirname import sysconfig from importlib import resources +from pathlib import PurePath import inspect if not hasattr(sys.modules[__name__], '__file__'): @@ -425,7 +426,7 @@ def _load_lib(path): resources.files(__name__) / "lib", join(split(__file__)[0], 'lib'), '', - sysconfig.get_path('platlib'), + PurePath(sysconfig.get_path('platlib')), "/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64'] for _path in _path_list: