Commit d6efc942 authored by Jason R. Coombs's avatar Jason R. Coombs

Introduce a new monkey module to encapsulate the monkeypatching.

parent 64b10c60
......@@ -5,7 +5,6 @@ import sys
import functools
import distutils.core
import distutils.filelist
from distutils.core import Command as _Command
from distutils.util import convert_path
from fnmatch import fnmatchcase
......@@ -13,7 +12,8 @@ from setuptools.extern.six.moves import filterfalse, map
import setuptools.version
from setuptools.extension import Extension
from setuptools.dist import Distribution, Feature, _get_unpatched
from setuptools.dist import Distribution, Feature
from setuptools.monkey import _get_unpatched
from setuptools.depends import Require
__all__ = [
......@@ -122,7 +122,7 @@ find_packages = PackageFinder.find
setup = distutils.core.setup
_Command = _get_unpatched(_Command)
_Command = _get_unpatched(distutils.core.Command)
class Command(_Command):
......
......@@ -9,7 +9,6 @@ import distutils.log
import distutils.core
import distutils.cmd
import distutils.dist
from distutils.core import Distribution as _Distribution
from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsSetupError)
from distutils.util import rfc822_escape
......@@ -20,25 +19,11 @@ from pkg_resources.extern import packaging
from setuptools.depends import Require
from setuptools import windows_support
from setuptools.monkey import _get_unpatched
import pkg_resources
def _get_unpatched(cls):
"""Protect against re-patching the distutils if reloaded
Also ensures that no other distutils extension monkeypatched the distutils
first.
"""
while cls.__module__.startswith('setuptools'):
cls, = cls.__bases__
if not cls.__module__.startswith('distutils'):
raise AssertionError(
"distutils has already been patched by %r" % cls
)
return cls
_Distribution = _get_unpatched(_Distribution)
_Distribution = _get_unpatched(distutils.core.Distribution)
def _patch_distribution_metadata_write_pkg_file():
......
......@@ -7,7 +7,7 @@ import distutils.extension
from setuptools.extern.six.moves import map
from .dist import _get_unpatched
from .monkey import _get_unpatched
from . import msvc
_Extension = _get_unpatched(distutils.core.Extension)
......
"""
Monkey patching of distutils.
"""
__all__ = []
"everything is private"
def _get_unpatched(cls):
"""Protect against re-patching the distutils if reloaded
Also ensures that no other distutils extension monkeypatched the distutils
first.
"""
while cls.__module__.startswith('setuptools'):
cls, = cls.__bases__
if not cls.__module__.startswith('distutils'):
raise AssertionError(
"distutils has already been patched by %r" % cls
)
return cls
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment