Skip to content

Commit

Permalink
Merge pull request #4600 from pypa/debt/msvc-monkey
Browse files Browse the repository at this point in the history
Remove monkeypatching of _msvccompiler.
  • Loading branch information
jaraco authored Aug 27, 2024
2 parents 5f8215d + 18a44d8 commit b4fb917
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 1,872 deletions.
1 change: 1 addition & 0 deletions newsfragments/4600.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the monkeypatching of distutils._msvccompiler. Now all compiler logic is consolidated in distutils.
37 changes: 0 additions & 37 deletions setuptools/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from __future__ import annotations

import functools
import inspect
import platform
import sys
import types
from importlib import import_module
from typing import Type, TypeVar, cast, overload

import distutils.filelist
Expand Down Expand Up @@ -91,8 +89,6 @@ def patch_all():
'distutils.command.build_ext'
].Extension = setuptools.extension.Extension

patch_for_msvc_specialized_compiler()


def _patch_distribution_metadata():
from . import _core_metadata
Expand Down Expand Up @@ -128,36 +124,3 @@ def patch_func(replacement, target_mod, func_name):

def get_unpatched_function(candidate):
return candidate.unpatched


def patch_for_msvc_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
"""
from . import msvc

if platform.system() != 'Windows':
# Compilers only available on Microsoft Windows
return

def patch_params(mod_name, func_name):
"""
Prepare the parameters for patch_func to patch indicated function.
"""
repl_prefix = 'msvc14_'
repl_name = repl_prefix + func_name.lstrip('_')
repl = getattr(msvc, repl_name)
mod = import_module(mod_name)
if not hasattr(mod, func_name):
raise ImportError(func_name)
return repl, mod, func_name

# Python 3.5+
msvc14 = functools.partial(patch_params, 'distutils._msvccompiler')

try:
# Patch distutils._msvccompiler._get_vc_env
patch_func(*msvc14('_get_vc_env'))
except ImportError:
pass
Loading

0 comments on commit b4fb917

Please sign in to comment.