From 1c292c12d5e6595b6576ae0aa4935ea1e39552bf Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Wed, 4 Sep 2024 11:41:08 -0600 Subject: [PATCH] Handle distutils without distutils.msvc9compiler.MSVCCompiler class (#118) * Handle distutils without distutils.msvc9compiler.MSVCCompiler class * add explanatory comments --------- Co-authored-by: Matt Davis (cherry picked from commit 5982be1aebccaaea73b5b4cb171bc9214f8e994d) --- src/cffi/_shimmed_dist_utils.py | 6 +++++- src/cffi/recompiler.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cffi/_shimmed_dist_utils.py b/src/cffi/_shimmed_dist_utils.py index 611bf40f..c3d23128 100644 --- a/src/cffi/_shimmed_dist_utils.py +++ b/src/cffi/_shimmed_dist_utils.py @@ -30,7 +30,11 @@ from distutils.log import set_threshold, set_verbosity if sys.platform == 'win32': - from distutils.msvc9compiler import MSVCCompiler + try: + # FUTURE: msvc9compiler module was removed in setuptools 74; consider removing, as it's only used by an ancient patch in `recompiler` + 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 diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index 0af0ef36..3c427754 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -1490,9 +1490,12 @@ def _unpatch_meths(patchlist): def _patch_for_embedding(patchlist): if sys.platform == 'win32': # we must not remove the manifest when building for embedding! + # FUTURE: this module was removed in setuptools 74; this is likely dead code and should be removed, + # since the toolchain it supports (VS2005-2008) is also long dead. from cffi._shimmed_dist_utils import MSVCCompiler - _patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref', - lambda self, manifest_file: manifest_file) + if MSVCCompiler is not None: + _patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref', + lambda self, manifest_file: manifest_file) if sys.platform == 'darwin': # we must not make a '-bundle', but a '-dynamiclib' instead