| | """ |
| | Temporary shim module to indirect the bits of distutils we need from setuptools/distutils while providing useful |
| | error messages beyond `No module named 'distutils' on Python >= 3.12, or when setuptools' vendored distutils is broken. |
| | |
| | This is a compromise to avoid a hard-dep on setuptools for Python >= 3.12, since many users don't need runtime compilation support from CFFI. |
| | """ |
| | import sys |
| |
|
| | try: |
| | |
| | |
| | import setuptools |
| | except Exception as ex: |
| | if sys.version_info >= (3, 12): |
| | |
| | raise Exception("This CFFI feature requires setuptools on Python >= 3.12. The setuptools module is missing or non-functional.") from ex |
| |
|
| | |
| | else: |
| | del setuptools |
| |
|
| | try: |
| | |
| | from distutils import log, sysconfig |
| | from distutils.ccompiler import CCompiler |
| | from distutils.command.build_ext import build_ext |
| | from distutils.core import Distribution, Extension |
| | from distutils.dir_util import mkpath |
| | from distutils.errors import DistutilsSetupError, CompileError, LinkError |
| | from distutils.log import set_threshold, set_verbosity |
| |
|
| | if sys.platform == 'win32': |
| | try: |
| | |
| | from distutils.msvc9compiler import MSVCCompiler |
| | except ImportError: |
| | MSVCCompiler = None |
| | except Exception as ex: |
| | if sys.version_info >= (3, 12): |
| | raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex |
| |
|
| | |
| | raise Exception("This CFFI feature requires distutils. Please install the distutils or setuptools package.") from ex |
| |
|
| | del sys |
| |
|