| 1 |
""" |
| 2 |
Temporary shim module to indirect the bits of distutils we need from setuptools/distutils while providing useful |
| 3 |
error messages beyond `No module named 'distutils' on Python >= 3.12, or when setuptools' vendored distutils is broken. |
| 4 |
|
| 5 |
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. |
| 6 |
""" |
| 7 |
import sys |
| 8 |
|
| 9 |
try: |
| 10 |
|
| 11 |
|
| 12 |
import setuptools |
| 13 |
except Exception as ex: |
| 14 |
if sys.version_info >= (3, 12): |
| 15 |
|
| 16 |
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. The setuptools module is missing or non-functional.") from ex |
| 17 |
|
| 18 |
|
| 19 |
else: |
| 20 |
del setuptools |
| 21 |
|
| 22 |
try: |
| 23 |
|
| 24 |
from distutils import log, sysconfig |
| 25 |
from distutils.ccompiler import CCompiler |
| 26 |
from distutils.command.build_ext import build_ext |
| 27 |
from distutils.core import Distribution, Extension |
| 28 |
from distutils.dir_util import mkpath |
| 29 |
from distutils.errors import DistutilsSetupError, CompileError, LinkError |
| 30 |
from distutils.log import set_threshold, set_verbosity |
| 31 |
|
| 32 |
if sys.platform == 'win32': |
| 33 |
try: |
| 34 |
|
| 35 |
from distutils.msvc9compiler import MSVCCompiler |
| 36 |
except ImportError: |
| 37 |
MSVCCompiler = None |
| 38 |
except Exception as ex: |
| 39 |
if sys.version_info >= (3, 12): |
| 40 |
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex |
| 41 |
|
| 42 |
|
| 43 |
raise Exception("This CFFI feature requires distutils. Please install the distutils or setuptools package.") from ex |
| 44 |
|
| 45 |
del sys |