Skip to content

Commit 06cd38c

Browse files
committed
Handle distutils without distutils.msvc9compiler.MSVCCompiler class
1 parent 9ba9c1e commit 06cd38c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/cffi/_shimmed_dist_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
from distutils.log import set_threshold, set_verbosity
3131

3232
if sys.platform == 'win32':
33-
from distutils.msvc9compiler import MSVCCompiler
33+
try:
34+
from distutils.msvc9compiler import MSVCCompiler
35+
except ImportError:
36+
MSVCCompiler = None
3437
except Exception as ex:
3538
if sys.version_info >= (3, 12):
3639
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex

src/cffi/recompiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,9 @@ def _patch_for_embedding(patchlist):
14841484
if sys.platform == 'win32':
14851485
# we must not remove the manifest when building for embedding!
14861486
from cffi._shimmed_dist_utils import MSVCCompiler
1487-
_patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref',
1488-
lambda self, manifest_file: manifest_file)
1487+
if MSVCCompiler is not None:
1488+
_patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref',
1489+
lambda self, manifest_file: manifest_file)
14891490

14901491
if sys.platform == 'darwin':
14911492
# we must not make a '-bundle', but a '-dynamiclib' instead

0 commit comments

Comments
 (0)