Skip to content

Commit 369bbea

Browse files
committed
We no longer need to handle a static build directory
1 parent aee9b33 commit 369bbea

File tree

3 files changed

+3
-145
lines changed

3 files changed

+3
-145
lines changed

pip/locations.py

+2-48
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66
import os.path
77
import site
88
import sys
9-
import tempfile
109

1110
from distutils import sysconfig
12-
from distutils.command.install import install, SCHEME_KEYS
11+
from distutils.command.install import install, SCHEME_KEYS # noqa
1312

14-
from pip.compat import get_path_uid, WINDOWS
13+
from pip.compat import WINDOWS
1514
from pip.utils import appdirs
16-
from pip import exceptions
17-
18-
19-
# Hack for flake8
20-
install
2115

2216

2317
# CA Bundle Locations
@@ -108,48 +102,9 @@ def __get_username():
108102
return pwd.getpwuid(os.geteuid()).pw_name
109103

110104

111-
def _get_build_prefix():
112-
""" Returns a safe build_prefix """
113-
path = os.path.join(
114-
tempfile.gettempdir(),
115-
'pip_build_%s' % __get_username().replace(' ', '_')
116-
)
117-
if WINDOWS:
118-
""" on windows(tested on 7) temp dirs are isolated """
119-
return path
120-
try:
121-
os.mkdir(path)
122-
write_delete_marker_file(path)
123-
except OSError:
124-
file_uid = None
125-
try:
126-
# raises OSError for symlinks
127-
# https://github.com/pypa/pip/pull/935#discussion_r5307003
128-
file_uid = get_path_uid(path)
129-
except OSError:
130-
file_uid = None
131-
132-
if file_uid != os.geteuid():
133-
msg = (
134-
"The temporary folder for building (%s) is either not owned by"
135-
" you, or is a symlink." % path
136-
)
137-
print(msg)
138-
print(
139-
"pip will not work until the temporary folder is either "
140-
"deleted or is a real directory owned by your user account."
141-
)
142-
raise exceptions.InstallationError(msg)
143-
return path
144-
145105
if running_under_virtualenv():
146-
build_prefix = os.path.join(sys.prefix, 'build')
147106
src_prefix = os.path.join(sys.prefix, 'src')
148107
else:
149-
# Note: intentionally NOT using mkdtemp
150-
# See https://github.com/pypa/pip/issues/906 for plan to move to mkdtemp
151-
build_prefix = _get_build_prefix()
152-
153108
# FIXME: keep src in cwd for now (it is not a temporary folder)
154109
try:
155110
src_prefix = os.path.join(os.getcwd(), 'src')
@@ -162,7 +117,6 @@ def _get_build_prefix():
162117
# under Mac OS X + virtualenv sys.prefix is not properly resolved
163118
# it is something like /path/to/python/bin/..
164119
# Note: using realpath due to tmp dirs on OSX being symlinks
165-
build_prefix = os.path.abspath(os.path.realpath(build_prefix))
166120
src_prefix = os.path.abspath(src_prefix)
167121

168122
# FIXME doesn't account for venv linked to global site-packages

pip/req/req_set.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
from pip.download import (url_to_path, unpack_url)
1414
from pip.exceptions import (InstallationError, BestVersionAlreadyInstalled,
1515
DistributionNotFound, PreviousBuildDirError)
16-
from pip.locations import (PIP_DELETE_MARKER_FILENAME, build_prefix)
1716
from pip.req.req_install import InstallRequirement
18-
from pip.utils import (display_path, rmtree, dist_in_usersite, normalize_path)
17+
from pip.utils import display_path, dist_in_usersite, normalize_path
1918
from pip.utils.logging import indent_log
2019
from pip.vcs import vcs
2120

@@ -558,18 +557,6 @@ def cleanup_files(self):
558557
for req in self.reqs_to_cleanup:
559558
req.remove_temporary_source()
560559

561-
if self._pip_has_created_build_dir():
562-
logger.debug('Removing temporary dir %s...', self.build_dir)
563-
rmtree(self.build_dir)
564-
565-
def _pip_has_created_build_dir(self):
566-
return (
567-
self.build_dir == build_prefix and
568-
os.path.exists(
569-
os.path.join(self.build_dir, PIP_DELETE_MARKER_FILENAME)
570-
)
571-
)
572-
573560
def _to_install(self):
574561
"""Create the installation order.
575562

tests/unit/test_locations.py

-83
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import tempfile
99
import getpass
1010

11-
import pytest
12-
1311
from mock import Mock
14-
import pip
1512

1613
from pip.locations import distutils_scheme
1714

@@ -77,86 +74,6 @@ def get_mock_getpwuid(self, uid):
7774
result.pw_name = self.username
7875
return result
7976

80-
def get_build_dir_location(self):
81-
""" returns a string pointing to the
82-
current build_prefix.
83-
"""
84-
return os.path.join(self.tempdir, 'pip_build_%s' % self.username)
85-
86-
def test_dir_path(self):
87-
""" test the path name for the build_prefix
88-
"""
89-
from pip import locations
90-
assert locations._get_build_prefix() == self.get_build_dir_location()
91-
92-
# skip on windows, build dir is not created
93-
@pytest.mark.skipif("sys.platform == 'win32'")
94-
@pytest.mark.skipif("not hasattr(os, 'O_NOFOLLOW')")
95-
def test_dir_created(self):
96-
""" test that the build_prefix directory is generated when
97-
_get_build_prefix is called.
98-
"""
99-
assert not os.path.exists(self.get_build_dir_location()), \
100-
"the build_prefix directory should not exist yet!"
101-
from pip import locations
102-
locations._get_build_prefix()
103-
assert os.path.exists(self.get_build_dir_location()), \
104-
"the build_prefix directory should now exist!"
105-
106-
# skip on windows, build dir is not created
107-
@pytest.mark.skipif("sys.platform == 'win32'")
108-
def test_dir_created_without_NOFOLLOW(self, monkeypatch):
109-
""" test that the build_prefix directory is generated when
110-
os.O_NOFOLLOW doen't exist
111-
"""
112-
if hasattr(os, 'O_NOFOLLOW'):
113-
monkeypatch.delattr("os.O_NOFOLLOW")
114-
assert not os.path.exists(self.get_build_dir_location()), \
115-
"the build_prefix directory should not exist yet!"
116-
from pip import locations
117-
locations._get_build_prefix()
118-
assert os.path.exists(self.get_build_dir_location()), \
119-
"the build_prefix directory should now exist!"
120-
121-
# skip on windows; this exception logic only runs on linux
122-
@pytest.mark.skipif("sys.platform == 'win32'")
123-
@pytest.mark.skipif("not hasattr(os, 'O_NOFOLLOW')")
124-
def test_error_raised_when_owned_by_another(self):
125-
""" test calling _get_build_prefix when there is a temporary
126-
directory owned by another user raises an InstallationError.
127-
"""
128-
from pip import locations
129-
os.geteuid = lambda: 1111
130-
os.mkdir(self.get_build_dir_location())
131-
132-
with pytest.raises(pip.exceptions.InstallationError):
133-
locations._get_build_prefix()
134-
135-
# skip on windows; this exception logic only runs on linux
136-
@pytest.mark.skipif("sys.platform == 'win32'")
137-
def test_error_raised_when_owned_by_another_without_NOFOLLOW(
138-
self, monkeypatch):
139-
""" test calling _get_build_prefix when there is a temporary
140-
directory owned by another user raises an InstallationError.
141-
(when os.O_NOFOLLOW doesn't exist
142-
"""
143-
if hasattr(os, 'O_NOFOLLOW'):
144-
monkeypatch.delattr("os.O_NOFOLLOW")
145-
from pip import locations
146-
os.geteuid = lambda: 1111
147-
os.mkdir(self.get_build_dir_location())
148-
149-
with pytest.raises(pip.exceptions.InstallationError):
150-
locations._get_build_prefix()
151-
152-
def test_no_error_raised_when_owned_by_you(self):
153-
""" test calling _get_build_prefix when there is a temporary
154-
directory owned by you raise no InstallationError.
155-
"""
156-
from pip import locations
157-
os.mkdir(self.get_build_dir_location())
158-
locations._get_build_prefix()
159-
16077

16178
class TestDisutilsScheme:
16279

0 commit comments

Comments
 (0)