diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index e37375b08b..4afeb689f2 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, @@ -74,6 +65,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 @@ -177,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 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 diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 288b705688..1b27f15f52 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -385,7 +385,8 @@ import ctypes, ctypes.util from os.path import split, join, dirname import sysconfig -import pkg_resources +from importlib import resources +from pathlib import PurePath import inspect if not hasattr(sys.modules[__name__], '__file__'): @@ -415,17 +416,17 @@ 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'), + PurePath(sysconfig.get_path('platlib')), "/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64'] for _path in _path_list: 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" 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',