comparison venv/lib/python2.7/site-packages/pip/utils/build.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 from __future__ import absolute_import
2
3 import os.path
4 import tempfile
5
6 from pip.utils import rmtree
7
8
9 class BuildDirectory(object):
10
11 def __init__(self, name=None, delete=None):
12 # If we were not given an explicit directory, and we were not given an
13 # explicit delete option, then we'll default to deleting.
14 if name is None and delete is None:
15 delete = True
16
17 if name is None:
18 # We realpath here because some systems have their default tmpdir
19 # symlinked to another directory. This tends to confuse build
20 # scripts, so we canonicalize the path by traversing potential
21 # symlinks here.
22 name = os.path.realpath(tempfile.mkdtemp(prefix="pip-build-"))
23 # If we were not given an explicit directory, and we were not given
24 # an explicit delete option, then we'll default to deleting.
25 if delete is None:
26 delete = True
27
28 self.name = name
29 self.delete = delete
30
31 def __repr__(self):
32 return "<{} {!r}>".format(self.__class__.__name__, self.name)
33
34 def __enter__(self):
35 return self.name
36
37 def __exit__(self, exc, value, tb):
38 self.cleanup()
39
40 def cleanup(self):
41 if self.delete:
42 rmtree(self.name)