diff --git a/news/8288.removal b/news/8288.removal new file mode 100644 index 00000000000..830d91aab95 --- /dev/null +++ b/news/8288.removal @@ -0,0 +1 @@ +Add deprecation warning for invalid requirements format "base>=1.0[extra]" diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 7ca3370110f..43b7324462b 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -23,6 +23,7 @@ from pip._internal.models.wheel import Wheel from pip._internal.pyproject import make_pyproject_path from pip._internal.req.req_install import InstallRequirement +from pip._internal.utils.deprecation import deprecated from pip._internal.utils.filetypes import ARCHIVE_EXTENSIONS from pip._internal.utils.misc import is_installable_dir, splitext from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -368,6 +369,14 @@ def with_source(text): if add_msg: msg += '\nHint: {}'.format(add_msg) raise InstallationError(msg) + else: + # Check that specifiers are PEP-440 compliant + for spec in req.specifier: + if not isinstance(spec, Specifier): + msg = "Invalid version specifier '{}'".format(str(spec)) + replace = ("using PEP 440-compatible specifiers. " + "https://www.python.org/dev/peps/pep-0440") + deprecated(msg, replacement=replace, gone_in="21.0") else: req = None diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py index 4874874e788..74aa1bddd80 100644 --- a/tests/functional/test_new_resolver.py +++ b/tests/functional/test_new_resolver.py @@ -200,8 +200,6 @@ def test_new_resolver_ignore_dependencies(script): [ "base[add]", "base[add] >= 0.1.0", - # Non-standard syntax. To deprecate, see pypa/pip#8288. - "base >= 0.1.0[add]", ], ) def test_new_resolver_installs_extras(tmpdir, script, root_dep): @@ -228,6 +226,32 @@ def test_new_resolver_installs_extras(tmpdir, script, root_dep): assert_installed(script, base="0.1.0", dep="0.1.0") +def test_new_resolver_installs_extras_deprecated(tmpdir, script): + req_file = tmpdir.joinpath("requirements.txt") + req_file.write_text("base >= 0.1.0[add]") + + create_basic_wheel_for_package( + script, + "base", + "0.1.0", + extras={"add": ["dep"]}, + ) + create_basic_wheel_for_package( + script, + "dep", + "0.1.0", + ) + result = script.pip( + "install", "--unstable-feature=resolver", + "--no-cache-dir", "--no-index", + "--find-links", script.scratch_path, + "-r", req_file, + expect_stderr=True + ) + assert "DEPRECATION: Invalid version specifier" in result.stderr + assert_installed(script, base="0.1.0", dep="0.1.0") + + def test_new_resolver_installs_extras_warn_missing(script): create_basic_wheel_for_package( script,