summaryrefslogtreecommitdiff
path: root/setuptools/command/easy_install.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-xsetuptools/command/easy_install.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index e3b7161a..b9d41cb0 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -627,12 +627,24 @@ class easy_install(Command):
(spec.key, self.build_directory)
)
- def easy_install(self, spec, deps=False):
+ @contextlib.contextmanager
+ def _tmpdir(self):
tmpdir = tempfile.mkdtemp(prefix="easy_install-")
+ try:
+ yield tmpdir
+ finally:
+ if not os.path.exists(tmpdir):
+ return
+ # workaround for http://bugs.python.org/issue24672
+ if six.PY2:
+ tmpdir = tmpdir.decode('ascii')
+ rmtree(tmpdir)
+
+ def easy_install(self, spec, deps=False):
if not self.editable:
self.install_site_py()
- try:
+ with self._tmpdir() as tmpdir:
if not isinstance(spec, Requirement):
if URL_SCHEME(spec):
# It's a url, download it to tmpdir and process
@@ -664,13 +676,6 @@ class easy_install(Command):
else:
return self.install_item(spec, dist.location, tmpdir, deps)
- finally:
- if os.path.exists(tmpdir):
- # workaround for http://bugs.python.org/issue24672
- if six.PY2:
- tmpdir = tmpdir.decode('ascii')
- rmtree(tmpdir)
-
def install_item(self, spec, download, tmpdir, deps, install_needed=False):
# Installation is also needed if file in tmpdir or is not an egg