You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.py 1.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import absolute_import
  2. import os.path
  3. import tempfile
  4. from pip.utils import rmtree
  5. class BuildDirectory(object):
  6. def __init__(self, name=None, delete=None):
  7. # If we were not given an explicit directory, and we were not given an
  8. # explicit delete option, then we'll default to deleting.
  9. if name is None and delete is None:
  10. delete = True
  11. if name is None:
  12. # We realpath here because some systems have their default tmpdir
  13. # symlinked to another directory. This tends to confuse build
  14. # scripts, so we canonicalize the path by traversing potential
  15. # symlinks here.
  16. name = os.path.realpath(tempfile.mkdtemp(prefix="pip-build-"))
  17. # If we were not given an explicit directory, and we were not given
  18. # an explicit delete option, then we'll default to deleting.
  19. if delete is None:
  20. delete = True
  21. self.name = name
  22. self.delete = delete
  23. def __repr__(self):
  24. return "<{} {!r}>".format(self.__class__.__name__, self.name)
  25. def __enter__(self):
  26. return self.name
  27. def __exit__(self, exc, value, tb):
  28. self.cleanup()
  29. def cleanup(self):
  30. if self.delete:
  31. rmtree(self.name)