summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Lopes Tavares <hltbra@gmail.com>2011-12-02 21:04:26 -0200
committerHugo Lopes Tavares <hltbra@gmail.com>2011-12-02 21:04:26 -0200
commita8aecb5c27f3c86481fbfc34695f0207a84b0297 (patch)
treeb3c623be7de2461de317b85666772585d41c1a11
parent8d7d8a6fc55d44e6d4aee053e2cc3e55268f1d80 (diff)
downloadpip-a8aecb5c27f3c86481fbfc34695f0207a84b0297.tar.gz
Change src_prefix to always be in current working dir.
It does not make sense to put `src` folder in a temp location. First reason is that users using editable installations would always need that temp place, and it is not simple to find that dir while debugging installations.
-rw-r--r--pip/locations.py8
-rw-r--r--tests/test_locations.py28
2 files changed, 26 insertions, 10 deletions
diff --git a/pip/locations.py b/pip/locations.py
index 4bb3f6845..5d157f229 100644
--- a/pip/locations.py
+++ b/pip/locations.py
@@ -19,12 +19,12 @@ if running_under_virtualenv():
build_prefix = os.path.join(sys.prefix, 'build')
src_prefix = os.path.join(sys.prefix, 'src')
else:
+ # src is always in current dir
+ src_prefix = os.path.join(os.getcwd(), 'src')
if os.access(os.getcwd(), os.W_OK):
- _prefix_dir = os.getcwd()
+ build_prefix = os.path.join(os.getcwd(), 'build')
else:
- _prefix_dir = tempfile.mkdtemp()
- build_prefix = os.path.join(_prefix_dir, 'build')
- src_prefix = os.path.join(_prefix_dir, 'src')
+ build_prefix = os.path.join(tempfile.mkdtemp(), 'build')
# under Mac OS X + virtualenv sys.prefix is not properly resolved
# it is something like /path/to/python/bin/..
diff --git a/tests/test_locations.py b/tests/test_locations.py
index bbae6f436..6a92549f7 100644
--- a/tests/test_locations.py
+++ b/tests/test_locations.py
@@ -7,7 +7,7 @@ from tests.test_pip import without_real_prefix
@patch('os.access')
@without_real_prefix
-def test_should_use_os_access_to_check_write_permission_to_build_dir_and_src_dir(access_mock):
+def test_should_use_os_access_to_check_write_permission_to_build_dir(access_mock):
"""
Ensure `os.access` is called to see if user can write in the current dir
"""
@@ -21,10 +21,9 @@ def test_should_use_os_access_to_check_write_permission_to_build_dir_and_src_dir
@patch('tempfile.mkdtemp')
@patch('os.access')
@without_real_prefix
-def test_build_prefix_and_src_should_be_in_a_temp_build_dir_if_cwd_is_not_writable(access_mock, mkdtemp_mock):
+def test_build_prefix_should_be_in_a_temp_build_dir_if_cwd_is_not_writable(access_mock, mkdtemp_mock):
"""
- Test `build_prefix` and `src_prefix` are in a temporary directory
- when current working dir is not writable
+ Test `build_prefix` is in a temporary directory when current working dir is not writable
"""
access_mock.return_value = False
mkdtemp_mock.return_value = temp_dir = '/path/to/temp/dir'
@@ -32,10 +31,27 @@ def test_build_prefix_and_src_should_be_in_a_temp_build_dir_if_cwd_is_not_writab
# reload module because it was imported before the test method
import pip.locations
reload(pip.locations)
- from pip.locations import build_prefix, src_prefix
+ from pip.locations import build_prefix
assert_equal(build_prefix, os.path.join(temp_dir, 'build'))
- assert_equal(src_prefix, os.path.join(temp_dir, 'src'))
+
+
+@patch('tempfile.mkdtemp')
+@patch('os.access')
+@without_real_prefix
+def test_src_prefix_should_be_in_cwd_even_if_cwd_is_not_writable(access_mock, mkdtemp_mock):
+ """
+ Test `src_prefix` is in current working dir even if current working dir is not writable
+ """
+ access_mock.return_value = False
+ mkdtemp_mock.return_value = '/path/to/temp/dir'
+
+ # reload module because it was imported before the test method
+ import pip.locations
+ reload(pip.locations)
+ from pip.locations import src_prefix
+
+ assert_equal(src_prefix, os.path.join(os.getcwd(), 'src'))
@patch('os.access')