Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove monkeypatching of _msvccompiler. #4600

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading