Skip to content

Commit

Permalink
Deprecate requirements format "base>=1.0[extra]"
Browse files Browse the repository at this point in the history
This requirements format does not conform to PEP-508. Add deprecation
warning and fix the corresponding test.

Note that the actual added check ensures the specifier is compliant
with PEP-440 (the specifier version is invalid "1.0[extra]").
  • Loading branch information
Jussi Kukkonen committed Jun 11, 2020
1 parent bc6a3ef commit f17daa0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/8288.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add deprecation warning for invalid requirements format "base>=1.0[extra]"
9 changes: 9 additions & 0 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
28 changes: 26 additions & 2 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down

0 comments on commit f17daa0

Please sign in to comment.