Skip to content

Commit 5982be1

Browse files
Handle distutils without distutils.msvc9compiler.MSVCCompiler class (#118)
* Handle distutils without distutils.msvc9compiler.MSVCCompiler class * add explanatory comments --------- Co-authored-by: Matt Davis <[email protected]>
1 parent 9e9dffb commit 5982be1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/cffi/_shimmed_dist_utils.py

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

3232
if sys.platform == 'win32':
33-
from distutils.msvc9compiler import MSVCCompiler
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 MSVCCompiler
36+
except ImportError:
37+
MSVCCompiler = None
3438
except Exception as ex:
3539
if sys.version_info >= (3, 12):
3640
raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex

src/cffi/recompiler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,12 @@ def _unpatch_meths(patchlist):
14901490
def _patch_for_embedding(patchlist):
14911491
if sys.platform == 'win32':
14921492
# we must not remove the manifest when building for embedding!
1493+
# FUTURE: this module was removed in setuptools 74; this is likely dead code and should be removed,
1494+
# since the toolchain it supports (VS2005-2008) is also long dead.
14931495
from cffi._shimmed_dist_utils import MSVCCompiler
1494-
_patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref',
1495-
lambda self, manifest_file: manifest_file)
1496+
if MSVCCompiler is not None:
1497+
_patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref',
1498+
lambda self, manifest_file: manifest_file)
14961499

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

0 commit comments

Comments
 (0)