Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_shimmed_dist_utils.py46 linesDownload Raw Back to cffi
1"""2Temporary shim module to indirect the bits of distutils we need from setuptools/distutils while providing useful3error messages beyond `No module named 'distutils' on Python >= 3.12, or when setuptools' vendored distutils is broken.4 5This 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"""7import sys8 9try:10    # import setuptools first; this is the most robust way to ensure its embedded distutils is available11    # (the .pth shim should usually work, but this is even more robust)12    import setuptools13except Exception as ex:14    if sys.version_info >= (3, 12):15        # Python 3.12 has no built-in distutils to fall back on, so any import problem is fatal16        raise Exception("This CFFI feature requires setuptools on Python >= 3.12. The setuptools module is missing or non-functional.") from ex17 18    # silently ignore on older Pythons (support fallback to stdlib distutils where available)19else:20    del setuptools21 22try:23    # bring in just the bits of distutils we need, whether they really came from setuptools or stdlib-embedded distutils24    from distutils import log, sysconfig25    from distutils.ccompiler import CCompiler26    from distutils.command.build_ext import build_ext27    from distutils.core import Distribution, Extension28    from distutils.dir_util import mkpath29    from distutils.errors import DistutilsSetupError, CompileError, LinkError30    from distutils.log import set_threshold, set_verbosity31 32    if sys.platform == 'win32':33        try:34            # FUTURE: msvc9compiler module was removed in setuptools 74; consider removing, as it's only used by an ancient patch in `recompiler`35            from distutils.msvc9compiler import MSVCCompiler36        except ImportError:37            MSVCCompiler = None38except 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 ex41 42    # anything older, just let the underlying distutils import error fly43    raise Exception("This CFFI feature requires distutils. Please install the distutils or setuptools package.") from ex44 45del sys46 
codekingpro/portable-devtools · Team Ai