Skip to content

Commit

Permalink
Merge pull request #2396 from twizmwazin/python/remove-deprecated-pac…
Browse files Browse the repository at this point in the history
…kaging

Python/remove deprecated packaging
  • Loading branch information
Rot127 authored Jul 19, 2024
2 parents de5120e + 8ddb2b9 commit 5ba4ca4
Show file tree
Hide file tree
Showing 41 changed files with 73 additions and 788 deletions.
80 changes: 6 additions & 74 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,59 +30,30 @@ 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',
enable-asan: 'OFF'
}
- {
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',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.9 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',
name: 'ubuntu-22.04 x64 cmake',
os: ubuntu-22.04,
arch: x64,
python-arch: x64,
python-version: '3.11',
build-system: 'cmake',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.11 ASAN',
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
run: |
export LD_LIBRARY_PATH=`pwd`/tests/:$LD_LIBRARY_PATH
Expand Down Expand Up @@ -153,45 +124,6 @@ jobs:
python cstest_report.py -D -t build/cstest -f ../../tests/cs_details/issue.cs
cd ../../
- name: verify python binding
if: matrix.config.enable-asan == 'OFF'
run: |
mkdir -p bindings/python/capstone/lib && cp libcapstone.so.5.* bindings/python/capstone/lib/libcapstone.so
cd bindings/python
# check if the generated *_const.py files are up-to-date
mkdir capstone_old && cp capstone/*_const.py capstone_old/
make gen_const
for f in ./capstone/*_const.py; do
diff -u -w "$f" "./capstone_old/`basename $f`"
if [ ! $? -eq 0 ]; then
exit 1
fi
done
rm -rf capstone_old
# smoke test api usage
make check
- name: run python binding test
if: matrix.config.enable-asan == 'OFF'
run: |
cp libcapstone.* bindings/python/prebuilt
cd bindings/python
make install
cd ..
BUILD_TESTS=no make tests
- name: run cython binding test
if: matrix.config.enable-asan == 'OFF'
run: |
pip install cython
cd bindings/python
make install_cython
cd ..
python -c "import capstone;print(capstone.debug())" | grep Cython
BUILD_TESTS=no make tests
Windows:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.name }}
Expand All @@ -214,7 +146,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 @@ -8,45 +8,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
11 changes: 1 addition & 10 deletions bindings/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PYTHON3 ?= python3

.PHONY: gen_const install install_cython sdist bdist clean check
.PHONY: gen_const install sdist bdist clean check

gen_const:
cd .. && $(PYTHON3) const_generator.py python
Expand All @@ -13,15 +13,6 @@ install:
$(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 \
$(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
12 changes: 9 additions & 3 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,15 @@
import ctypes, ctypes.util
from os.path import split, join, dirname
import sysconfig
import pkg_resources
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 @@ -421,14 +427,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'),
str(resources.files(__name__) / "lib"),
join(split(__file__)[0], 'lib'),
'',
sysconfig.get_path('platlib'),
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.

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

This file was deleted.

Loading

0 comments on commit 5ba4ca4

Please sign in to comment.