Commit 674d5ecb authored by Jason R. Coombs's avatar Jason R. Coombs

Extract tmpdir as a context manager

parent 7f89e790
......@@ -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
......
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