mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Failing exit status when no requirements specified (#4210)
* add failing tests for #2720 * fix #2720: exit status when no requirements specified * Don't fail when blank requirements files specified
This commit is contained in:
parent
ca14080260
commit
20326d8b24
8 changed files with 69 additions and 20 deletions
|
@ -3,6 +3,9 @@
|
||||||
* Use pkg_resources to parse the entry points file to allow names with
|
* Use pkg_resources to parse the entry points file to allow names with
|
||||||
colons (:pull:`3901`)
|
colons (:pull:`3901`)
|
||||||
|
|
||||||
|
* Return a failing exit status when `pip install`, `pip download`, or
|
||||||
|
`pip wheel` is called with no requirements. (:issue:`2720`, :pull:`2721`)
|
||||||
|
|
||||||
**9.0.1 (2016-11-06)**
|
**9.0.1 (2016-11-06)**
|
||||||
|
|
||||||
* Correct the deprecation message when not specifying a --format so that it
|
* Correct the deprecation message when not specifying a --format so that it
|
||||||
|
|
|
@ -287,29 +287,27 @@ class RequirementCommand(Command):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
found_req_in_file = False
|
|
||||||
for filename in options.requirements:
|
for filename in options.requirements:
|
||||||
for req in parse_requirements(
|
for req in parse_requirements(
|
||||||
filename,
|
filename,
|
||||||
finder=finder, options=options, session=session,
|
finder=finder, options=options, session=session,
|
||||||
wheel_cache=wheel_cache):
|
wheel_cache=wheel_cache):
|
||||||
found_req_in_file = True
|
|
||||||
requirement_set.add_requirement(req)
|
requirement_set.add_requirement(req)
|
||||||
# If --require-hashes was a line in a requirements file, tell
|
# If --require-hashes was a line in a requirements file, tell
|
||||||
# RequirementSet about it:
|
# RequirementSet about it:
|
||||||
requirement_set.require_hashes = options.require_hashes
|
requirement_set.require_hashes = options.require_hashes
|
||||||
|
|
||||||
if not (args or options.editables or found_req_in_file):
|
if not (args or options.editables or options.requirements):
|
||||||
opts = {'name': name}
|
opts = {'name': name}
|
||||||
if options.find_links:
|
if options.find_links:
|
||||||
msg = ('You must give at least one requirement to '
|
raise CommandError(
|
||||||
'%(name)s (maybe you meant "pip %(name)s '
|
'You must give at least one requirement to %(name)s '
|
||||||
'%(links)s"?)' %
|
'(maybe you meant "pip %(name)s %(links)s"?)' %
|
||||||
dict(opts, links=' '.join(options.find_links)))
|
dict(opts, links=' '.join(options.find_links)))
|
||||||
else:
|
else:
|
||||||
msg = ('You must give at least one requirement '
|
raise CommandError(
|
||||||
'to %(name)s (see "pip help %(name)s")' % opts)
|
'You must give at least one requirement to %(name)s '
|
||||||
logger.warning(msg)
|
'(see "pip help %(name)s")' % opts)
|
||||||
|
|
||||||
def _build_package_finder(self, options, session,
|
def _build_package_finder(self, options, session,
|
||||||
platform=None, python_versions=None,
|
platform=None, python_versions=None,
|
||||||
|
|
|
@ -192,9 +192,6 @@ class DownloadCommand(RequirementCommand):
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
if not requirement_set.has_requirements:
|
|
||||||
return
|
|
||||||
|
|
||||||
requirement_set.prepare_files(finder)
|
requirement_set.prepare_files(finder)
|
||||||
|
|
||||||
downloaded = ' '.join([
|
downloaded = ' '.join([
|
||||||
|
|
|
@ -313,9 +313,6 @@ class InstallCommand(RequirementCommand):
|
||||||
wheel_cache
|
wheel_cache
|
||||||
)
|
)
|
||||||
|
|
||||||
if not requirement_set.has_requirements:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if (options.download_dir or not wheel or not
|
if (options.download_dir or not wheel or not
|
||||||
options.cache_dir):
|
options.cache_dir):
|
||||||
|
|
|
@ -185,9 +185,6 @@ class WheelCommand(RequirementCommand):
|
||||||
wheel_cache
|
wheel_cache
|
||||||
)
|
)
|
||||||
|
|
||||||
if not requirement_set.has_requirements:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# build wheels
|
# build wheels
|
||||||
wb = WheelBuilder(
|
wb = WheelBuilder(
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import textwrap
|
import textwrap
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from pip.status_codes import ERROR
|
||||||
from tests.lib.path import Path
|
from tests.lib.path import Path
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,3 +555,22 @@ def test_download_specify_implementation(script, data):
|
||||||
'fake',
|
'fake',
|
||||||
expect_error=True,
|
expect_error=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_exit_status_code_when_no_requirements(script):
|
||||||
|
"""
|
||||||
|
Test download exit status code when no requirements specified
|
||||||
|
"""
|
||||||
|
result = script.pip('download', expect_error=True)
|
||||||
|
assert (
|
||||||
|
"You must give at least one requirement to download" in result.stderr
|
||||||
|
)
|
||||||
|
assert result.returncode == ERROR
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_exit_status_code_when_blank_requirements_file(script):
|
||||||
|
"""
|
||||||
|
Test download exit status code when blank requirements file specified
|
||||||
|
"""
|
||||||
|
script.scratch_path.join("blank.txt").write("\n")
|
||||||
|
script.pip('download', '-r', 'blank.txt')
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
|
|
||||||
from pip import pep425tags
|
from pip import pep425tags
|
||||||
from pip.utils import appdirs, rmtree
|
from pip.utils import appdirs, rmtree
|
||||||
|
from pip.status_codes import ERROR
|
||||||
from tests.lib import (pyversion, pyversion_tuple,
|
from tests.lib import (pyversion, pyversion_tuple,
|
||||||
_create_test_package, _create_svn_repo, path_to_url,
|
_create_test_package, _create_svn_repo, path_to_url,
|
||||||
requirements_file)
|
requirements_file)
|
||||||
|
@ -83,6 +84,23 @@ def test_pip_second_command_line_interface_works(script, data):
|
||||||
assert initools_folder in result.files_created, str(result)
|
assert initools_folder in result.files_created, str(result)
|
||||||
|
|
||||||
|
|
||||||
|
def test_install_exit_status_code_when_no_requirements(script):
|
||||||
|
"""
|
||||||
|
Test install exit status code when no requirements specified
|
||||||
|
"""
|
||||||
|
result = script.pip('install', expect_error=True)
|
||||||
|
assert "You must give at least one requirement to install" in result.stderr
|
||||||
|
assert result.returncode == ERROR
|
||||||
|
|
||||||
|
|
||||||
|
def test_install_exit_status_code_when_blank_requirements_file(script):
|
||||||
|
"""
|
||||||
|
Test install exit status code when blank requirements file specified
|
||||||
|
"""
|
||||||
|
script.scratch_path.join("blank.txt").write("\n")
|
||||||
|
script.pip('install', '-r', 'blank.txt')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.network
|
@pytest.mark.network
|
||||||
def test_install_from_pypi(script):
|
def test_install_from_pypi(script):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,7 +5,7 @@ import pytest
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
|
||||||
from pip.locations import write_delete_marker_file
|
from pip.locations import write_delete_marker_file
|
||||||
from pip.status_codes import PREVIOUS_BUILD_DIR_ERROR
|
from pip.status_codes import ERROR, PREVIOUS_BUILD_DIR_ERROR
|
||||||
from tests.lib import pyversion
|
from tests.lib import pyversion
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,25 @@ def test_pip_wheel_fails_without_wheel(script, data):
|
||||||
assert "'pip wheel' requires the 'wheel' package" in result.stderr
|
assert "'pip wheel' requires the 'wheel' package" in result.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def test_wheel_exit_status_code_when_no_requirements(script):
|
||||||
|
"""
|
||||||
|
Test wheel exit status code when no requirements specified
|
||||||
|
"""
|
||||||
|
script.pip('install', 'wheel')
|
||||||
|
result = script.pip('wheel', expect_error=True)
|
||||||
|
assert "You must give at least one requirement to wheel" in result.stderr
|
||||||
|
assert result.returncode == ERROR
|
||||||
|
|
||||||
|
|
||||||
|
def test_wheel_exit_status_code_when_blank_requirements_file(script):
|
||||||
|
"""
|
||||||
|
Test wheel exit status code when blank requirements file specified
|
||||||
|
"""
|
||||||
|
script.pip('install', 'wheel')
|
||||||
|
script.scratch_path.join("blank.txt").write("\n")
|
||||||
|
script.pip('wheel', '-r', 'blank.txt')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.network
|
@pytest.mark.network
|
||||||
def test_pip_wheel_success(script, data):
|
def test_pip_wheel_success(script, data):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue