aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/easy_install.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-12-29 14:29:09 -0500
committerJason R. Coombs <jaraco@jaraco.com>2014-12-29 14:29:09 -0500
commit8826a85c8c2dd4b3b5080de725486b0b30e79e4f (patch)
treed704690abc6eab15ce91b479eae0a93262f47ebe /setuptools/command/easy_install.py
parent4a7ea62f3efc4297bcc8c2a8094fa687474fb5f1 (diff)
downloadexternal_python_setuptools-8826a85c8c2dd4b3b5080de725486b0b30e79e4f.tar.gz
external_python_setuptools-8826a85c8c2dd4b3b5080de725486b0b30e79e4f.tar.bz2
external_python_setuptools-8826a85c8c2dd4b3b5080de725486b0b30e79e4f.zip
Extract _patch_usage and re-implement as a context manager.
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-xsetuptools/command/easy_install.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index d368e1a3..125ceba2 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -34,6 +34,7 @@ import textwrap
import warnings
import site
import struct
+import contextlib
from setuptools import Command
from setuptools.sandbox import run_setup
@@ -2119,39 +2120,42 @@ def bootstrap():
def main(argv=None, **kw):
from setuptools import setup
from setuptools.dist import Distribution
- import distutils.core
-
- USAGE = textwrap.dedent("""
- usage: %(script)s [options] requirement_or_url ...
- or: %(script)s --help
- """).lstrip()
-
- def gen_usage(script_name):
- return USAGE % dict(
- script=os.path.basename(script_name),
- )
-
- def with_ei_usage(f):
- old_gen_usage = distutils.core.gen_usage
- try:
- distutils.core.gen_usage = gen_usage
- return f()
- finally:
- distutils.core.gen_usage = old_gen_usage
class DistributionWithoutHelpCommands(Distribution):
common_usage = ""
def _show_help(self, *args, **kw):
- with_ei_usage(lambda: Distribution._show_help(self, *args, **kw))
+ with _patch_usage():
+ Distribution._show_help(self, *args, **kw)
if argv is None:
argv = sys.argv[1:]
- with_ei_usage(
- lambda: setup(
+ with _patch_usage():
+ setup(
script_args=['-q', 'easy_install', '-v'] + argv,
script_name=sys.argv[0] or 'easy_install',
distclass=DistributionWithoutHelpCommands, **kw
)
- )
+
+
+@contextlib.contextmanager
+def _patch_usage():
+ import distutils.core
+ USAGE = textwrap.dedent("""
+ usage: %(script)s [options] requirement_or_url ...
+ or: %(script)s --help
+ """).lstrip()
+
+ def gen_usage(script_name):
+ return USAGE % dict(
+ script=os.path.basename(script_name),
+ )
+
+ saved = distutils.core.gen_usage
+ distutils.core.gen_usage = gen_usage
+ try:
+ yield
+ finally:
+ distutils.core.gen_usage = saved
+