From 06cd38c414088a46f227c55c833558027f77eeda Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Thu, 29 Aug 2024 01:53:11 -0600 Subject: [PATCH 1/2] Handle distutils without distutils.msvc9compiler.MSVCCompiler class --- src/cffi/_shimmed_dist_utils.py | 5 ++++- src/cffi/recompiler.py | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cffi/_shimmed_dist_utils.py b/src/cffi/_shimmed_dist_utils.py index 611bf40f4..49b48265d 100644 --- a/src/cffi/_shimmed_dist_utils.py +++ b/src/cffi/_shimmed_dist_utils.py @@ -30,7 +30,10 @@ from distutils.log import set_threshold, set_verbosity if sys.platform == 'win32': - from distutils.msvc9compiler import MSVCCompiler + try: + 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 733a4ed1b..fcf329385 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -1484,8 +1484,9 @@ def _patch_for_embedding(patchlist): if sys.platform == 'win32': # we must not remove the manifest when building for embedding! 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 From 1b4af98af986de0c421dae528b9a44f6f263a0d8 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 4 Sep 2024 10:26:59 -0700 Subject: [PATCH 2/2] add explanatory comments --- src/cffi/_shimmed_dist_utils.py | 1 + src/cffi/recompiler.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/cffi/_shimmed_dist_utils.py b/src/cffi/_shimmed_dist_utils.py index 49b48265d..c3d231281 100644 --- a/src/cffi/_shimmed_dist_utils.py +++ b/src/cffi/_shimmed_dist_utils.py @@ -31,6 +31,7 @@ if sys.platform == 'win32': 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 diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index fcf329385..b004b4edb 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -1483,6 +1483,8 @@ 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 if MSVCCompiler is not None: _patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref',