Skip to content

Commit

Permalink
Handle distutils without distutils.msvc9compiler.MSVCCompiler class (#…
Browse files Browse the repository at this point in the history
…118)

* Handle distutils without distutils.msvc9compiler.MSVCCompiler class

* add explanatory comments

---------

Co-authored-by: Matt Davis <nitzmahone@redhat.com>
(cherry picked from commit 5982be1)
  • Loading branch information
jameshilliard authored and nitzmahone committed Sep 4, 2024
1 parent 182ffc4 commit 1c292c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/cffi/_shimmed_dist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c292c1

Please sign in to comment.