Skip to content

Commit

Permalink
Fix #725 and #729.
Browse files Browse the repository at this point in the history
Signed-off-by: David <db@d1b.org>
  • Loading branch information
d1b committed Nov 23, 2012
1 parent 854574f commit 61cc16d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pip/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import shutil
import tempfile
import getpass
from pip.backwardcompat import get_python_lib


Expand All @@ -26,14 +27,32 @@ def virtualenv_no_global():
if running_under_virtualenv() and os.path.isfile(no_global_file):
return True

def _get_build_prefix():
""" Returns a safe build_prefix """
path = os.path.join(tempfile.gettempdir(), 'pip-build-%s' % \
getpass.getuser())
if sys.platform == 'win32':
return path
try:
os.mkdir(path)
except OSError:
fd = os.open(path, os.O_RDONLY)
stat = os.fstat(fd)
if os.getuid() != stat.st_uid:
print ("The temporary folder for building (%s) " % path +
"is not owned by your user!")
print("pip will not work until the temporary folder is " + \
"either deleted or owned by your user account.")
sys.exit(1)
return path

if running_under_virtualenv():
build_prefix = os.path.join(sys.prefix, 'build')
src_prefix = os.path.join(sys.prefix, 'src')
else:
# Use tempfile to create a temporary folder for build
# Note: we are NOT using mkdtemp so we can have a consistent build dir
build_prefix = os.path.join(tempfile.gettempdir(), 'pip-build')
build_prefix = _get_build_prefix()

## FIXME: keep src in cwd for now (it is not a temporary folder)
try:
Expand Down

0 comments on commit 61cc16d

Please sign in to comment.