Cmds {install,wheel} should return proper error code

The `pip` executable was returning a successful status code (`0`) when
trying to install new packages with existing previous build directories.

Conflicts:
	tests/functional/test_install_cleanup.py
	tests/functional/test_wheel.py
This commit is contained in:
Lincoln de Sousa 2013-08-22 16:17:01 -04:00 committed by Marcus Smith
parent 37f2d9dae6
commit d6582a251e
7 changed files with 41 additions and 10 deletions

View File

@ -11,10 +11,11 @@ import optparse
from pip.log import logger
from pip.download import urlopen
from pip.exceptions import (BadCommand, InstallationError, UninstallationError,
CommandError)
CommandError, PreviousBuildDirError)
from pip.backwardcompat import StringIO
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.status_codes import SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND
from pip.status_codes import (SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,
PREVIOUS_BUILD_DIR_ERROR)
from pip.util import get_prog
@ -136,6 +137,12 @@ class Command(object):
# and when it is done, isinstance is not needed anymore
if isinstance(status, int):
exit = status
except PreviousBuildDirError:
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
store_log = True
exit = PREVIOUS_BUILD_DIR_ERROR
except (InstallationError, UninstallationError):
e = sys.exc_info()[1]
logger.fatal(str(e))

View File

@ -252,7 +252,8 @@ class InstallCommand(Command):
requirement_set.create_bundle(self.bundle_filename)
logger.notify('Created bundle in %s' % self.bundle_filename)
except PreviousBuildDirError:
return
options.no_clean = True
raise
finally:
# Clean up
if (not options.no_clean) and ((not options.no_install) or options.download_dir):

View File

@ -151,8 +151,8 @@ class WheelCommand(Command):
)
wb.build()
except PreviousBuildDirError:
return
options.no_clean = True
raise
finally:
if not options.no_clean:
requirement_set.cleanup_files()

View File

@ -1067,16 +1067,13 @@ class RequirementSet(object):
# inconsistencies are logged later, but do not fail the
# installation.
elif os.path.exists(os.path.join(location, 'setup.py')):
msg = textwrap.dedent("""
raise PreviousBuildDirError(textwrap.dedent("""
pip can't proceed with requirement '%s' due to a pre-existing build directory.
location: %s
This is likely due to a previous installation that failed.
pip is being responsible and not assuming it can delete this.
Please delete it and try again.
""" % (req_to_install, location))
e = PreviousBuildDirError(msg)
logger.fatal(msg)
raise e
""" % (req_to_install, location)))
else:
## FIXME: this won't upgrade when there's an existing package unpacked in `location`
if req_to_install.url is None:

View File

@ -2,4 +2,5 @@ SUCCESS = 0
ERROR = 1
UNKNOWN_ERROR = 2
VIRTUALENV_NOT_FOUND = 3
PREVIOUS_BUILD_DIR_ERROR = 4
NO_MATCHES_FOUND = 23

View File

@ -5,6 +5,8 @@ from tests.lib import (tests_data, reset_env, run_pip, pip_install_local,
write_file, mkdir, path_to_url, find_links)
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path
from pip.locations import write_delete_marker_file
from pip.status_codes import PREVIOUS_BUILD_DIR_ERROR
def test_cleanup_after_install():
@ -139,7 +141,10 @@ def test_cleanup_prevented_upon_build_dir_exception():
env = reset_env()
build = env.venv_path/'build'/'simple'
os.makedirs(build)
write_delete_marker_file(env.venv_path/'build')
write_file("setup.py", "#", dest=build)
result = run_pip('install', '-f', find_links, '--no-index', 'simple', expect_error=True)
assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
assert "pip can't proceed" in result.stdout, result.stdout
assert exists(build)

View File

@ -7,6 +7,8 @@ from os.path import exists
from nose import SkipTest
from pip import wheel
from pip.download import path_to_url as path_to_url_d
from pip.locations import write_delete_marker_file
from pip.status_codes import PREVIOUS_BUILD_DIR_ERROR
from tests.lib import tests_data, reset_env, run_pip, pyversion_nodot, write_file, path_to_url, find_links, pip_install_local
@ -98,3 +100,21 @@ def test_pip_wheel_source_deps():
assert "Successfully built source" in result.stdout, result.stdout
def test_pip_wheel_fail_cause_of_previous_build_dir():
"""Test when 'pip wheel' tries to install a package that has a previous build directory"""
env = reset_env()
pip_install_local('wheel')
# Given that I have a previous build dir of the `simple` package
build = env.venv_path / 'build' / 'simple'
os.makedirs(build)
write_delete_marker_file(env.venv_path / 'build')
write_file("setup.py", "#", dest=build)
# When I call pip trying to install things again
result = run_pip('wheel', '--no-index', '--find-links=%s' % find_links, 'simple==3.0', expect_error=True)
# Then I see that the error code is the right one
assert result.returncode == PREVIOUS_BUILD_DIR_ERROR