Skip to content

Commit

Permalink
Remove deprecated packaging and cython (#2400)
Browse files Browse the repository at this point in the history
* Remove deprecated packaging and cython

* Fix some issues after cherry-picking

* Fix CI issues

* Remove test files added for v6

* Also remove test_alpha.py
  • Loading branch information
twizmwazin authored Jul 24, 2024
1 parent e90ef39 commit 1bd2a32
Show file tree
Hide file tree
Showing 38 changed files with 80 additions and 717 deletions.
39 changes: 11 additions & 28 deletions .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Run Test
on:
on:
push:
paths-ignore:
- ".gitignore"
- "docs/**"
- "ChangeLog"
- "ChangeLog"
- "CREDITS.TXT"
- "COMPILE.TXT"
- "COMPILE_MSVC.TXT"
Expand All @@ -30,46 +30,29 @@ jobs:
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',
}
- {
name: 'ubuntu-22.04 x64 python3.9 make',
name: 'ubuntu-22.04 x64 make',
os: ubuntu-22.04,
arch: x64,
python-arch: x64,
python-version: '3.9',
build-system: 'make',
}
}
- {
name: 'ubuntu-22.04 x64 python3.9 cmake',
name: 'ubuntu-22.04 x64 cmake',
os: ubuntu-22.04,
arch: x64,
python-arch: x64,
python-version: '3.9',
build-system: 'cmake',
}
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.11 cmake',
os: ubuntu-22.04,
name: 'ubuntu-22.04 x64 ASAN',
os: ubuntu-latest,
arch: x64,
python-arch: x64,
python-version: '3.11',
build-system: 'cmake',
enable-asan: 'ON'
}

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.config.python-version }}

- name: prepare
shell: 'script -q -e -c "bash {0}"'
run: |
Expand Down Expand Up @@ -135,7 +118,7 @@ jobs:

- name: '🛠️ Win MSVC 64 setup'
if: contains(matrix.config.name, 'MSVC 64')
uses: ilammy/msvc-dev-cmd@v1
uses: ilammy/msvc-dev-cmd@v1
with:
arch: 'x64'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ jobs:
with:
name: artifacts
path: ./out/artifacts
- name: Install Python Dependencies
run: python -m pip install --upgrade setuptools build wheel
32 changes: 32 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python Package CI

on:
push:
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, windows-2022, macOS-14]
python-version: ["3.8", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Setup MSVC
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1

- name: Build and install capstone
run: pip install ./bindings/python

- name: Run tests
run: python ./bindings/python/tests/test_all.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# python
bindings/python/build/
bindings/python/capstone.egg-info/
bindings/cython/capstone.egg-info/
*.pyc

# java
Expand Down
40 changes: 1 addition & 39 deletions bindings/python/BUILDING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,7 @@

To control the install destination, set the DESTDIR environment variable.

2. For better Python performance, install cython-based binding with:

$ sudo make install_cython

Note that this requires Cython installed first. To install Cython, see
below.

3. To install Cython, you have to ensure that the header files
and the static library for Python are installed beforehand.

E.g. on Ubuntu, do:

$ sudo apt-get install python-dev

Depending on if you already have pip or easy_install installed, install
Cython with either:

$ sudo pip install cython
or:
$ sudo easy_install cython

NOTE: Depending on your distribution you might also be able to
install the required Cython version using your repository.

E.g. on Ubuntu, do:

$ sudo apt-get install cython

However, our cython-based binding requires Cython version 0.19 or newer,
but sometimes distributions only provide older version. Make sure to
verify the current installed version before going into section 2 above.

E.g, on Ubuntu, you can verify the current Cython version with:

$ apt-cache policy cython

Which should at least print version 0.19

4. This directory contains some test code to show how to use the Capstone API.
2. The tests directory contains some test code to show how to use the Capstone API.

- test_basic.py
This code shows the most simple form of API where we only want to get basic
Expand Down
19 changes: 1 addition & 18 deletions bindings/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PYTHON2 ?= python2
PYTHON3 ?= python3

.PHONY: gen_const install install3 install_cython sdist sdist3 bdist bdist3 clean check
.PHONY: gen_const install sdist bdist clean check

gen_const:
cd .. && $(PYTHON2) const_generator.py python
Expand All @@ -22,23 +22,6 @@ install3:
$(PYTHON3) setup.py build install; \
fi

# NOTE: Newer cython can be installed by: sudo pip install --upgrade cython
install_cython:
rm -rf src/
if test -n "${DESTDIR}"; then \
$(PYTHON2) setup_cython.py build install --root="${DESTDIR}"; \
else \
$(PYTHON2) setup_cython.py build install; \
fi

install3_cython:
rm -rf src/
if test -n "${DESTDIR}"; then \
$(PYTHON3) setup_cython.py build install --root="${DESTDIR}"; \
else \
$(PYTHON3) setup_cython.py build install; \
fi

# build & upload PyPi package with source code of the core
sdist:
rm -rf src/ dist/
Expand Down
16 changes: 11 additions & 5 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,16 @@

import ctypes, ctypes.util
from os.path import split, join, dirname
import distutils.sysconfig
import pkg_resources
import sysconfig
from pathlib import PurePath

import inspect

if sys.version_info >= (3, 9):
import importlib.resources as resources
else:
import importlib_resources as resources

if not hasattr(sys.modules[__name__], '__file__'):
__file__ = inspect.getfile(inspect.currentframe())

Expand Down Expand Up @@ -379,17 +385,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'),
str(resources.files(__name__) / "lib"),
join(split(__file__)[0], 'lib'),
'',
distutils.sysconfig.get_python_lib(),
sysconfig.get_path('platlib'),
"/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64']

for _path in _path_list:
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
1 change: 0 additions & 1 deletion bindings/python/pyx/README

This file was deleted.

72 changes: 0 additions & 72 deletions bindings/python/pyx/ccapstone.pxd

This file was deleted.

Loading

0 comments on commit 1bd2a32

Please sign in to comment.