Skip to content

Commit

Permalink
Remove distutils
Browse files Browse the repository at this point in the history
Removes distutils from the setup.py script for the python bindings, as
it is removed in Python 3.12 onwards.
  • Loading branch information
pyrox0 committed Jun 11, 2024
1 parent 673cfdd commit c37671c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
import sys
import platform

from distutils import log
import logging
from setuptools import setup
from distutils.util import get_platform
from sysconfig import get_platform
# Setuptools includes a bundled version of distutils, so we can use distutils here.
# Note that this is discouraged, and it's only done here
# because setuptools < 62.4.0 doesn't have setuptools.command.build.
# This should be changed once the project removes support for Python 3.6,
# as setuptools will have that module in the last 3.7-supporting release(68.0.0)
from distutils.command.build import build
from distutils.command.sdist import sdist
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
Expand Down Expand Up @@ -102,7 +110,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():
Expand All @@ -123,7 +131,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)
Expand Down Expand Up @@ -167,9 +175,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)

Expand All @@ -191,7 +199,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)

Expand Down

0 comments on commit c37671c

Please sign in to comment.