Move check_invalid_constraint_type to req_install.py

This commit is contained in:
Pradyun Gedam 2020-07-04 17:55:49 +05:30
parent ace5485836
commit 20431888cb
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
2 changed files with 33 additions and 33 deletions

View File

@ -864,3 +864,35 @@ class InstallRequirement(object):
raise
self.install_succeeded = success
def check_invalid_constraint_type(req):
# type: (InstallRequirement) -> str
# Check for unsupported forms
problem = ""
if not req.name:
problem = "Unnamed requirements are not allowed as constraints"
elif req.link:
problem = "Links are not allowed as constraints"
elif req.extras:
problem = "Constraints cannot have extras"
if problem:
deprecated(
reason=(
"Constraints are only allowed to take the form of a package "
"name and a version specifier. Other forms were originally "
"permitted as an accident of the implementation, but were "
"undocumented. The new implementation of the resolver no "
"longer supports these forms."
),
replacement=(
"replacing the constraint with a requirement."
),
# No plan yet for when the new resolver becomes default
gone_in=None,
issue=8210
)
return problem

View File

@ -7,10 +7,10 @@ from pip._vendor.resolvelib import BaseReporter, ResolutionImpossible
from pip._vendor.resolvelib import Resolver as RLResolver
from pip._internal.exceptions import InstallationError
from pip._internal.req.req_install import check_invalid_constraint_type
from pip._internal.req.req_set import RequirementSet
from pip._internal.resolution.base import BaseResolver
from pip._internal.resolution.resolvelib.provider import PipProvider
from pip._internal.utils.deprecation import deprecated
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from .factory import Factory
@ -32,38 +32,6 @@ if MYPY_CHECK_RUNNING:
logger = logging.getLogger(__name__)
def check_invalid_constraint_type(req):
# type: (InstallRequirement) -> str
# Check for unsupported forms
problem = ""
if not req.name:
problem = "Unnamed requirements are not allowed as constraints"
elif req.link:
problem = "Links are not allowed as constraints"
elif req.extras:
problem = "Constraints cannot have extras"
if problem:
deprecated(
reason=(
"Constraints are only allowed to take the form of a package "
"name and a version specifier. Other forms were originally "
"permitted as an accident of the implementation, but were "
"undocumented. The new implementation of the resolver no "
"longer supports these forms."
),
replacement=(
"replacing the constraint with a requirement."
),
# No plan yet for when the new resolver becomes default
gone_in=None,
issue=8210
)
return problem
class Resolver(BaseResolver):
_allowed_strategies = {"eager", "only-if-needed", "to-satisfy-only"}