-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/tmp/pip-build fixes #780
Merged
Merged
/tmp/pip-build fixes #780
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eeaa64d
Fix #725 and #729.
d1b e7bf29e
Clean up the _get_build_prefix code - close the open fd and print the…
d1b 61c444e
Update the code _get_build_prefix to raise an exception instead of sy…
d1b dc3a359
In the os.open call to get the fd to check if the user specific build…
d1b 8baeeba
Provide a test to cover the changes to pip/locations.py regarding the…
d1b 7f13624
Also un-patch the patched getpass.getuser method.
d1b 9868bc3
setup.py read function fix
qwcode 26c050a
update changelog and authors
qwcode 68d983d
update docs with new build dir
qwcode 4595613
windows and other misc test updates
qwcode 1af3f2b
changelog fix
qwcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
""" | ||
locations.py tests | ||
|
||
""" | ||
import os | ||
import sys | ||
import shutil | ||
import tempfile | ||
import getpass | ||
from mock import Mock | ||
from nose import SkipTest | ||
from nose.tools import assert_raises | ||
import pip | ||
|
||
class TestLocations: | ||
def setup(self): | ||
self.tempdir = tempfile.mkdtemp() | ||
self.st_uid = 9999 | ||
self.username = "example" | ||
self.patch() | ||
|
||
def tearDown(self): | ||
self.revert_patch() | ||
shutil.rmtree(self.tempdir, ignore_errors=True) | ||
|
||
def patch(self): | ||
""" first store and then patch python methods pythons """ | ||
self.tempfile_gettempdir = tempfile.gettempdir | ||
self.old_os_fstat = os.fstat | ||
if sys.platform != 'win32': | ||
# os.getuid not implemented on windows | ||
self.old_os_getuid = os.getuid | ||
self.old_getpass_getuser = getpass.getuser | ||
|
||
# now patch | ||
tempfile.gettempdir = lambda : self.tempdir | ||
getpass.getuser = lambda : self.username | ||
os.getuid = lambda : self.st_uid | ||
os.fstat = lambda fd : self.get_mock_fstat(fd) | ||
|
||
def revert_patch(self): | ||
""" revert the patches to python methods """ | ||
tempfile.gettempdir = self.tempfile_gettempdir | ||
getpass.getuser = self.old_getpass_getuser | ||
if sys.platform != 'win32': | ||
# os.getuid not implemented on windows | ||
os.getuid = self.old_os_getuid | ||
os.fstat = self.old_os_fstat | ||
|
||
def get_mock_fstat(self, fd): | ||
""" returns a basic mock fstat call result. | ||
Currently only the st_uid attribute has been set. | ||
""" | ||
result = Mock() | ||
result.st_uid = self.st_uid | ||
return result | ||
|
||
def get_build_dir_location(self): | ||
""" returns a string pointing to the | ||
current build_prefix. | ||
""" | ||
return os.path.join(self.tempdir, 'pip-build-%s' % self.username) | ||
|
||
def test_dir_path(self): | ||
""" test the path name for the build_prefix | ||
""" | ||
from pip import locations | ||
assert locations._get_build_prefix() == self.get_build_dir_location() | ||
|
||
def test_dir_created(self): | ||
""" test that the build_prefix directory is generated when | ||
_get_build_prefix is called. | ||
""" | ||
#skip on windows, build dir is not created | ||
if sys.platform == 'win32': | ||
raise SkipTest() | ||
assert not os.path.exists(self.get_build_dir_location() ), \ | ||
"the build_prefix directory should not exist yet!" | ||
from pip import locations | ||
locations._get_build_prefix() | ||
assert os.path.exists(self.get_build_dir_location() ), \ | ||
"the build_prefix directory should now exist!" | ||
|
||
def test_error_raised_when_owned_by_another(self): | ||
""" test calling _get_build_prefix when there is a temporary | ||
directory owned by another user raises an InstallationError. | ||
""" | ||
#skip on windows; this exception logic only runs on linux | ||
if sys.platform == 'win32': | ||
raise SkipTest() | ||
from pip import locations | ||
os.getuid = lambda : 1111 | ||
os.mkdir(self.get_build_dir_location() ) | ||
assert_raises(pip.exceptions.InstallationError, locations._get_build_prefix) | ||
|
||
def test_no_error_raised_when_owned_by_you(self): | ||
""" test calling _get_build_prefix when there is a temporary | ||
directory owned by you raise no InstallationError. | ||
""" | ||
from pip import locations | ||
os.mkdir(self.get_build_dir_location()) | ||
locations._get_build_prefix() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getpass.getuser() returns the value in the LOGNAME environment variable, so this doesn't work under sudo:
$ sudo LOGNAME=foo python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
This should be based off of os.geteuid()
$ sudo LOGNAME=foo python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue for this: #982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect LOGNAME to be 'root' under sudo.
I see that on ubuntu and centos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timjr yes it should have been based off os.geteuid(), but getpass.getuser() is supported on windows and linux and so I used that.