2020-03-26 15:53:24 +01:00
|
|
|
import logging
|
2020-04-01 12:14:36 +02:00
|
|
|
import sys
|
2020-03-26 15:53:24 +01:00
|
|
|
|
2020-04-01 12:14:36 +02:00
|
|
|
from pip._vendor.packaging.specifiers import InvalidSpecifier, SpecifierSet
|
2020-03-18 15:54:15 +01:00
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
2020-04-01 12:14:36 +02:00
|
|
|
from pip._vendor.packaging.version import Version
|
2020-03-18 15:54:15 +01:00
|
|
|
|
2020-06-16 08:53:07 +02:00
|
|
|
from pip._internal.exceptions import HashError, MetadataInconsistent
|
2020-08-02 18:33:14 +02:00
|
|
|
from pip._internal.models.wheel import Wheel
|
2020-04-04 11:51:43 +02:00
|
|
|
from pip._internal.req.constructors import (
|
|
|
|
install_req_from_editable,
|
|
|
|
install_req_from_line,
|
|
|
|
)
|
2020-03-12 16:18:47 +01:00
|
|
|
from pip._internal.req.req_install import InstallRequirement
|
2020-06-23 15:39:12 +02:00
|
|
|
from pip._internal.utils.misc import dist_is_editable, normalize_version_info
|
2020-04-01 12:14:36 +02:00
|
|
|
from pip._internal.utils.packaging import get_requires_python
|
2020-03-12 16:18:47 +01:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
|
|
|
2020-03-25 13:25:23 +01:00
|
|
|
from .base import Candidate, format_name
|
2020-03-12 16:18:47 +01:00
|
|
|
|
|
|
|
if MYPY_CHECK_RUNNING:
|
2020-05-19 11:04:15 +02:00
|
|
|
from typing import Any, FrozenSet, Iterable, Optional, Tuple, Union
|
2020-03-12 16:18:47 +01:00
|
|
|
|
|
|
|
from pip._vendor.packaging.version import _BaseVersion
|
|
|
|
from pip._vendor.pkg_resources import Distribution
|
|
|
|
|
2020-04-01 12:14:36 +02:00
|
|
|
from pip._internal.models.link import Link
|
|
|
|
|
2020-03-27 15:42:26 +01:00
|
|
|
from .base import Requirement
|
2020-03-27 15:40:05 +01:00
|
|
|
from .factory import Factory
|
|
|
|
|
2020-04-04 12:12:38 +02:00
|
|
|
BaseCandidate = Union[
|
|
|
|
"AlreadyInstalledCandidate",
|
|
|
|
"EditableCandidate",
|
|
|
|
"LinkCandidate",
|
|
|
|
]
|
|
|
|
|
2020-03-12 16:18:47 +01:00
|
|
|
|
2020-03-26 20:14:51 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
2020-03-12 16:18:47 +01:00
|
|
|
|
|
|
|
|
2020-05-27 17:54:00 +02:00
|
|
|
def make_install_req_from_link(link, template):
|
2020-03-12 16:18:47 +01:00
|
|
|
# type: (Link, InstallRequirement) -> InstallRequirement
|
2020-05-27 17:54:00 +02:00
|
|
|
assert not template.editable, "template is editable"
|
|
|
|
if template.req:
|
|
|
|
line = str(template.req)
|
2020-04-09 11:33:54 +02:00
|
|
|
else:
|
|
|
|
line = link.url
|
|
|
|
ireq = install_req_from_line(
|
|
|
|
line,
|
2020-05-16 11:38:57 +02:00
|
|
|
user_supplied=template.user_supplied,
|
2020-05-27 17:54:00 +02:00
|
|
|
comes_from=template.comes_from,
|
|
|
|
use_pep517=template.use_pep517,
|
|
|
|
isolated=template.isolated,
|
|
|
|
constraint=template.constraint,
|
2020-03-12 16:18:47 +01:00
|
|
|
options=dict(
|
2020-05-27 17:54:00 +02:00
|
|
|
install_options=template.install_options,
|
|
|
|
global_options=template.global_options,
|
|
|
|
hashes=template.hash_options
|
2020-03-12 16:18:47 +01:00
|
|
|
),
|
|
|
|
)
|
2020-06-02 13:12:42 +02:00
|
|
|
ireq.original_link = template.original_link
|
|
|
|
ireq.link = link
|
2020-04-09 11:33:54 +02:00
|
|
|
return ireq
|
2020-03-12 16:18:47 +01:00
|
|
|
|
|
|
|
|
2020-05-27 17:54:00 +02:00
|
|
|
def make_install_req_from_editable(link, template):
|
2020-04-04 11:51:43 +02:00
|
|
|
# type: (Link, InstallRequirement) -> InstallRequirement
|
2020-05-27 17:54:00 +02:00
|
|
|
assert template.editable, "template not editable"
|
2020-04-04 11:51:43 +02:00
|
|
|
return install_req_from_editable(
|
|
|
|
link.url,
|
2020-05-16 11:38:57 +02:00
|
|
|
user_supplied=template.user_supplied,
|
2020-05-27 17:54:00 +02:00
|
|
|
comes_from=template.comes_from,
|
|
|
|
use_pep517=template.use_pep517,
|
|
|
|
isolated=template.isolated,
|
|
|
|
constraint=template.constraint,
|
2020-04-04 11:51:43 +02:00
|
|
|
options=dict(
|
2020-05-27 17:54:00 +02:00
|
|
|
install_options=template.install_options,
|
|
|
|
global_options=template.global_options,
|
|
|
|
hashes=template.hash_options
|
2020-04-04 11:51:43 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-27 17:54:00 +02:00
|
|
|
def make_install_req_from_dist(dist, template):
|
2020-04-02 13:49:45 +02:00
|
|
|
# type: (Distribution, InstallRequirement) -> InstallRequirement
|
2020-05-03 20:19:12 +02:00
|
|
|
project_name = canonicalize_name(dist.project_name)
|
2020-05-27 17:54:00 +02:00
|
|
|
if template.req:
|
|
|
|
line = str(template.req)
|
|
|
|
elif template.link:
|
|
|
|
line = "{} @ {}".format(project_name, template.link.url)
|
2020-05-03 20:19:12 +02:00
|
|
|
else:
|
|
|
|
line = "{}=={}".format(project_name, dist.parsed_version)
|
2020-04-02 13:49:45 +02:00
|
|
|
ireq = install_req_from_line(
|
2020-05-03 20:19:12 +02:00
|
|
|
line,
|
2020-05-16 11:38:57 +02:00
|
|
|
user_supplied=template.user_supplied,
|
2020-05-27 17:54:00 +02:00
|
|
|
comes_from=template.comes_from,
|
|
|
|
use_pep517=template.use_pep517,
|
|
|
|
isolated=template.isolated,
|
|
|
|
constraint=template.constraint,
|
2020-04-02 13:49:45 +02:00
|
|
|
options=dict(
|
2020-05-27 17:54:00 +02:00
|
|
|
install_options=template.install_options,
|
|
|
|
global_options=template.global_options,
|
|
|
|
hashes=template.hash_options
|
2020-04-02 13:49:45 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
ireq.satisfied_by = dist
|
|
|
|
return ireq
|
|
|
|
|
|
|
|
|
2020-04-03 14:05:05 +02:00
|
|
|
class _InstallRequirementBackedCandidate(Candidate):
|
2020-05-28 05:18:47 +02:00
|
|
|
"""A candidate backed by an ``InstallRequirement``.
|
|
|
|
|
|
|
|
This represents a package request with the target not being already
|
|
|
|
in the environment, and needs to be fetched and installed. The backing
|
|
|
|
``InstallRequirement`` is responsible for most of the leg work; this
|
|
|
|
class exposes appropriate information to the resolver.
|
|
|
|
|
|
|
|
:param link: The link passed to the ``InstallRequirement``. The backing
|
|
|
|
``InstallRequirement`` will use this link to fetch the distribution.
|
|
|
|
:param source_link: The link this candidate "originates" from. This is
|
|
|
|
different from ``link`` when the link is found in the wheel cache.
|
|
|
|
``link`` would point to the wheel cache, while this points to the
|
|
|
|
found remote link (e.g. from pypi.org).
|
|
|
|
"""
|
2020-05-14 12:33:30 +02:00
|
|
|
is_installed = False
|
|
|
|
|
2020-04-03 12:23:35 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
link, # type: Link
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link, # type: Link
|
2020-04-03 14:05:05 +02:00
|
|
|
ireq, # type: InstallRequirement
|
2020-04-03 12:23:35 +02:00
|
|
|
factory, # type: Factory
|
|
|
|
name=None, # type: Optional[str]
|
|
|
|
version=None, # type: Optional[_BaseVersion]
|
|
|
|
):
|
|
|
|
# type: (...) -> None
|
2020-05-28 05:18:47 +02:00
|
|
|
self._link = link
|
|
|
|
self._source_link = source_link
|
2020-03-27 15:40:05 +01:00
|
|
|
self._factory = factory
|
2020-04-03 14:05:05 +02:00
|
|
|
self._ireq = ireq
|
2020-04-03 12:23:35 +02:00
|
|
|
self._name = name
|
|
|
|
self._version = version
|
2020-03-12 16:18:47 +01:00
|
|
|
self._dist = None # type: Optional[Distribution]
|
|
|
|
|
2020-11-21 14:53:37 +01:00
|
|
|
def __str__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{} {}".format(self.name, self.version)
|
|
|
|
|
2020-04-07 14:53:25 +02:00
|
|
|
def __repr__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{class_name}({link!r})".format(
|
|
|
|
class_name=self.__class__.__name__,
|
2020-05-28 05:18:47 +02:00
|
|
|
link=str(self._link),
|
2020-04-07 14:53:25 +02:00
|
|
|
)
|
|
|
|
|
2020-05-19 11:04:15 +02:00
|
|
|
def __hash__(self):
|
|
|
|
# type: () -> int
|
2020-05-28 05:18:47 +02:00
|
|
|
return hash((self.__class__, self._link))
|
2020-05-19 11:04:15 +02:00
|
|
|
|
2020-03-19 11:53:15 +01:00
|
|
|
def __eq__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
if isinstance(other, self.__class__):
|
2020-05-28 05:18:47 +02:00
|
|
|
return self._link == other._link
|
2020-03-19 11:53:15 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Needed for Python 2, which does not implement this by default
|
|
|
|
def __ne__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
2020-05-28 05:18:47 +02:00
|
|
|
@property
|
|
|
|
def source_link(self):
|
|
|
|
# type: () -> Optional[Link]
|
|
|
|
return self._source_link
|
|
|
|
|
2020-03-12 16:18:47 +01:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
# type: () -> str
|
2020-03-19 11:53:15 +01:00
|
|
|
"""The normalised name of the project the candidate refers to"""
|
2020-03-12 16:18:47 +01:00
|
|
|
if self._name is None:
|
2020-03-18 15:54:15 +01:00
|
|
|
self._name = canonicalize_name(self.dist.project_name)
|
2020-03-12 16:18:47 +01:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def version(self):
|
|
|
|
# type: () -> _BaseVersion
|
|
|
|
if self._version is None:
|
|
|
|
self._version = self.dist.parsed_version
|
|
|
|
return self._version
|
|
|
|
|
2020-06-05 13:56:43 +02:00
|
|
|
def format_for_error(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{} {} (from {})".format(
|
|
|
|
self.name,
|
|
|
|
self.version,
|
2020-06-18 15:01:49 +02:00
|
|
|
self._link.file_path if self._link.is_file else self._link
|
2020-06-05 13:56:43 +02:00
|
|
|
)
|
|
|
|
|
2020-07-26 12:13:04 +02:00
|
|
|
def _prepare_distribution(self):
|
|
|
|
# type: () -> Distribution
|
2020-04-03 14:05:05 +02:00
|
|
|
raise NotImplementedError("Override in subclass")
|
|
|
|
|
Don't set _dist until it has been validated
Previously a call to `_fetch_metadata` could result in several possible
outcomes:
1. `_dist` set, `_provided` not set, dist returned - for lazy wheels
2. `_dist` set, `_provided` not set, exception - for bad lazy wheels
3. `_dist` not set, `_provided` not set, exception - for non-lazy req
exceptions
4. `_dist` set, `_provided` not set, exception - for bad non-lazy reqs
5. `_dist` set, `_provided` set, dist returned - for non-lazy reqs
and probably more.
Our intent is to use `_dist` being set as the indicator of "this
requirement has been fully processed successfully" and discard
`_prepared`, since we don't actually rely on any of the other states
(they simply lead to a failure or in the future a retry).
2020-08-02 17:04:27 +02:00
|
|
|
def _check_metadata_consistency(self, dist):
|
|
|
|
# type: (Distribution) -> None
|
2020-07-21 10:54:09 +02:00
|
|
|
"""Check for consistency of project name and version of dist."""
|
|
|
|
# TODO: (Longer term) Rather than abort, reject this candidate
|
|
|
|
# and backtrack. This would need resolvelib support.
|
|
|
|
name = canonicalize_name(dist.project_name)
|
|
|
|
if self._name is not None and self._name != name:
|
|
|
|
raise MetadataInconsistent(self._ireq, "name", dist.project_name)
|
|
|
|
version = dist.parsed_version
|
|
|
|
if self._version is not None and self._version != version:
|
|
|
|
raise MetadataInconsistent(self._ireq, "version", dist.version)
|
|
|
|
|
2020-04-08 20:27:37 +02:00
|
|
|
def _prepare(self):
|
|
|
|
# type: () -> None
|
2020-08-02 17:11:00 +02:00
|
|
|
if self._dist is not None:
|
2020-04-08 20:27:37 +02:00
|
|
|
return
|
2020-06-16 08:53:07 +02:00
|
|
|
try:
|
2020-08-02 17:44:42 +02:00
|
|
|
dist = self._prepare_distribution()
|
2020-06-16 08:53:07 +02:00
|
|
|
except HashError as e:
|
|
|
|
e.req = self._ireq
|
|
|
|
raise
|
|
|
|
|
Don't set _dist until it has been validated
Previously a call to `_fetch_metadata` could result in several possible
outcomes:
1. `_dist` set, `_provided` not set, dist returned - for lazy wheels
2. `_dist` set, `_provided` not set, exception - for bad lazy wheels
3. `_dist` not set, `_provided` not set, exception - for non-lazy req
exceptions
4. `_dist` set, `_provided` not set, exception - for bad non-lazy reqs
5. `_dist` set, `_provided` set, dist returned - for non-lazy reqs
and probably more.
Our intent is to use `_dist` being set as the indicator of "this
requirement has been fully processed successfully" and discard
`_prepared`, since we don't actually rely on any of the other states
(they simply lead to a failure or in the future a retry).
2020-08-02 17:04:27 +02:00
|
|
|
assert dist is not None, "Distribution already installed"
|
|
|
|
self._check_metadata_consistency(dist)
|
|
|
|
self._dist = dist
|
2020-04-08 20:27:37 +02:00
|
|
|
|
2020-03-12 16:18:47 +01:00
|
|
|
@property
|
|
|
|
def dist(self):
|
|
|
|
# type: () -> Distribution
|
2020-07-21 11:00:28 +02:00
|
|
|
if self._dist is None:
|
2020-08-02 17:10:00 +02:00
|
|
|
self._prepare()
|
2020-03-12 16:18:47 +01:00
|
|
|
return self._dist
|
|
|
|
|
2020-08-14 02:41:42 +02:00
|
|
|
def _get_requires_python_dependency(self):
|
|
|
|
# type: () -> Optional[Requirement]
|
2020-04-01 12:14:36 +02:00
|
|
|
requires_python = get_requires_python(self.dist)
|
|
|
|
if requires_python is None:
|
|
|
|
return None
|
|
|
|
try:
|
|
|
|
spec = SpecifierSet(requires_python)
|
|
|
|
except InvalidSpecifier as e:
|
2020-08-14 02:41:42 +02:00
|
|
|
message = "Package %r has an invalid Requires-Python: %s"
|
|
|
|
logger.warning(message, self.name, e)
|
2020-04-01 12:14:36 +02:00
|
|
|
return None
|
2020-08-14 02:41:42 +02:00
|
|
|
return self._factory.make_requires_python_requirement(spec)
|
2020-04-01 12:14:36 +02:00
|
|
|
|
2020-08-02 23:28:10 +02:00
|
|
|
def iter_dependencies(self, with_requires):
|
2020-08-02 02:22:04 +02:00
|
|
|
# type: (bool) -> Iterable[Optional[Requirement]]
|
2020-08-14 02:41:42 +02:00
|
|
|
requires = self.dist.requires() if with_requires else ()
|
|
|
|
for r in requires:
|
2020-05-21 09:39:16 +02:00
|
|
|
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
|
2020-08-14 02:41:42 +02:00
|
|
|
yield self._get_requires_python_dependency()
|
2020-03-25 12:41:33 +01:00
|
|
|
|
|
|
|
def get_install_requirement(self):
|
2020-03-26 12:19:10 +01:00
|
|
|
# type: () -> Optional[InstallRequirement]
|
2020-04-08 20:27:37 +02:00
|
|
|
self._prepare()
|
2020-03-25 12:41:33 +01:00
|
|
|
return self._ireq
|
2020-03-25 13:25:23 +01:00
|
|
|
|
|
|
|
|
2020-04-03 14:05:05 +02:00
|
|
|
class LinkCandidate(_InstallRequirementBackedCandidate):
|
2020-06-23 15:39:12 +02:00
|
|
|
is_editable = False
|
|
|
|
|
2020-04-03 14:05:05 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
link, # type: Link
|
2020-05-27 17:54:00 +02:00
|
|
|
template, # type: InstallRequirement
|
2020-04-03 14:05:05 +02:00
|
|
|
factory, # type: Factory
|
|
|
|
name=None, # type: Optional[str]
|
|
|
|
version=None, # type: Optional[_BaseVersion]
|
|
|
|
):
|
|
|
|
# type: (...) -> None
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link = link
|
2020-05-07 12:06:16 +02:00
|
|
|
cache_entry = factory.get_wheel_cache_entry(link, name)
|
|
|
|
if cache_entry is not None:
|
|
|
|
logger.debug("Using cached wheel link: %s", cache_entry.link)
|
|
|
|
link = cache_entry.link
|
2020-05-27 17:54:00 +02:00
|
|
|
ireq = make_install_req_from_link(link, template)
|
2020-08-02 20:07:06 +02:00
|
|
|
assert ireq.link == link
|
|
|
|
if ireq.link.is_wheel and not ireq.link.is_file:
|
|
|
|
wheel = Wheel(ireq.link.filename)
|
|
|
|
wheel_name = canonicalize_name(wheel.name)
|
|
|
|
assert name == wheel_name, (
|
2020-08-14 02:41:42 +02:00
|
|
|
"{!r} != {!r} for wheel".format(name, wheel_name)
|
2020-08-02 20:07:06 +02:00
|
|
|
)
|
|
|
|
# Version may not be present for PEP 508 direct URLs
|
|
|
|
if version is not None:
|
2020-11-01 18:16:58 +01:00
|
|
|
wheel_version = Version(wheel.version)
|
|
|
|
assert version == wheel_version, (
|
2020-08-02 20:07:06 +02:00
|
|
|
"{!r} != {!r} for wheel {}".format(
|
2020-11-01 18:16:58 +01:00
|
|
|
version, wheel_version, name
|
2020-08-02 20:07:06 +02:00
|
|
|
)
|
|
|
|
)
|
2020-05-07 12:06:16 +02:00
|
|
|
|
|
|
|
if (cache_entry is not None and
|
|
|
|
cache_entry.persistent and
|
2020-05-27 17:54:00 +02:00
|
|
|
template.link is template.original_link):
|
2020-05-07 12:06:16 +02:00
|
|
|
ireq.original_link_is_in_wheel_cache = True
|
|
|
|
|
2020-04-03 14:05:05 +02:00
|
|
|
super(LinkCandidate, self).__init__(
|
|
|
|
link=link,
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link=source_link,
|
2020-05-07 12:06:16 +02:00
|
|
|
ireq=ireq,
|
2020-04-03 14:05:05 +02:00
|
|
|
factory=factory,
|
|
|
|
name=name,
|
|
|
|
version=version,
|
|
|
|
)
|
|
|
|
|
2020-07-26 12:13:04 +02:00
|
|
|
def _prepare_distribution(self):
|
|
|
|
# type: () -> Distribution
|
2020-06-03 18:48:14 +02:00
|
|
|
return self._factory.preparer.prepare_linked_requirement(
|
|
|
|
self._ireq, parallel_builds=True,
|
|
|
|
)
|
2020-04-03 14:05:05 +02:00
|
|
|
|
|
|
|
|
2020-04-04 11:51:43 +02:00
|
|
|
class EditableCandidate(_InstallRequirementBackedCandidate):
|
2020-06-23 15:39:12 +02:00
|
|
|
is_editable = True
|
|
|
|
|
2020-04-04 11:51:43 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
link, # type: Link
|
2020-05-27 17:54:00 +02:00
|
|
|
template, # type: InstallRequirement
|
2020-04-04 11:51:43 +02:00
|
|
|
factory, # type: Factory
|
|
|
|
name=None, # type: Optional[str]
|
|
|
|
version=None, # type: Optional[_BaseVersion]
|
|
|
|
):
|
|
|
|
# type: (...) -> None
|
|
|
|
super(EditableCandidate, self).__init__(
|
|
|
|
link=link,
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link=link,
|
2020-05-27 17:54:00 +02:00
|
|
|
ireq=make_install_req_from_editable(link, template),
|
2020-04-04 11:51:43 +02:00
|
|
|
factory=factory,
|
|
|
|
name=name,
|
|
|
|
version=version,
|
|
|
|
)
|
|
|
|
|
2020-07-26 12:13:04 +02:00
|
|
|
def _prepare_distribution(self):
|
|
|
|
# type: () -> Distribution
|
2020-04-04 11:51:43 +02:00
|
|
|
return self._factory.preparer.prepare_editable_requirement(self._ireq)
|
|
|
|
|
|
|
|
|
2020-04-02 19:27:34 +02:00
|
|
|
class AlreadyInstalledCandidate(Candidate):
|
2020-05-14 12:33:30 +02:00
|
|
|
is_installed = True
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link = None
|
2020-05-14 12:33:30 +02:00
|
|
|
|
2020-04-02 13:49:45 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
dist, # type: Distribution
|
2020-05-27 17:54:00 +02:00
|
|
|
template, # type: InstallRequirement
|
2020-04-02 13:49:45 +02:00
|
|
|
factory, # type: Factory
|
|
|
|
):
|
|
|
|
# type: (...) -> None
|
|
|
|
self.dist = dist
|
2020-05-27 17:54:00 +02:00
|
|
|
self._ireq = make_install_req_from_dist(dist, template)
|
2020-04-02 13:49:45 +02:00
|
|
|
self._factory = factory
|
|
|
|
|
|
|
|
# This is just logging some messages, so we can do it eagerly.
|
|
|
|
# The returned dist would be exactly the same as self.dist because we
|
|
|
|
# set satisfied_by in make_install_req_from_dist.
|
|
|
|
# TODO: Supply reason based on force_reinstall and upgrade_strategy.
|
|
|
|
skip_reason = "already satisfied"
|
|
|
|
factory.preparer.prepare_installed_requirement(self._ireq, skip_reason)
|
|
|
|
|
2020-11-21 14:53:37 +01:00
|
|
|
def __str__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return str(self.dist)
|
|
|
|
|
2020-04-07 14:53:25 +02:00
|
|
|
def __repr__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{class_name}({distribution!r})".format(
|
|
|
|
class_name=self.__class__.__name__,
|
|
|
|
distribution=self.dist,
|
|
|
|
)
|
|
|
|
|
2020-05-19 11:04:15 +02:00
|
|
|
def __hash__(self):
|
|
|
|
# type: () -> int
|
|
|
|
return hash((self.__class__, self.name, self.version))
|
|
|
|
|
2020-04-04 09:17:56 +02:00
|
|
|
def __eq__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
if isinstance(other, self.__class__):
|
|
|
|
return self.name == other.name and self.version == other.version
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Needed for Python 2, which does not implement this by default
|
|
|
|
def __ne__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
2020-04-02 13:49:45 +02:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
# type: () -> str
|
|
|
|
return canonicalize_name(self.dist.project_name)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def version(self):
|
|
|
|
# type: () -> _BaseVersion
|
|
|
|
return self.dist.parsed_version
|
|
|
|
|
2020-06-23 15:39:12 +02:00
|
|
|
@property
|
|
|
|
def is_editable(self):
|
|
|
|
# type: () -> bool
|
|
|
|
return dist_is_editable(self.dist)
|
|
|
|
|
2020-06-05 13:56:43 +02:00
|
|
|
def format_for_error(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{} {} (Installed)".format(self.name, self.version)
|
|
|
|
|
2020-08-02 23:28:10 +02:00
|
|
|
def iter_dependencies(self, with_requires):
|
2020-08-02 02:22:04 +02:00
|
|
|
# type: (bool) -> Iterable[Optional[Requirement]]
|
2020-08-02 23:28:10 +02:00
|
|
|
if not with_requires:
|
2020-08-02 02:22:04 +02:00
|
|
|
return
|
2020-05-21 09:39:16 +02:00
|
|
|
for r in self.dist.requires():
|
|
|
|
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
|
2020-04-02 13:49:45 +02:00
|
|
|
|
|
|
|
def get_install_requirement(self):
|
|
|
|
# type: () -> Optional[InstallRequirement]
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
class ExtrasCandidate(Candidate):
|
2020-03-26 12:19:55 +01:00
|
|
|
"""A candidate that has 'extras', indicating additional dependencies.
|
|
|
|
|
|
|
|
Requirements can be for a project with dependencies, something like
|
|
|
|
foo[extra]. The extras don't affect the project/version being installed
|
|
|
|
directly, but indicate that we need additional dependencies. We model that
|
|
|
|
by having an artificial ExtrasCandidate that wraps the "base" candidate.
|
|
|
|
|
|
|
|
The ExtrasCandidate differs from the base in the following ways:
|
|
|
|
|
|
|
|
1. It has a unique name, of the form foo[extra]. This causes the resolver
|
|
|
|
to treat it as a separate node in the dependency graph.
|
|
|
|
2. When we're getting the candidate's dependencies,
|
|
|
|
a) We specify that we want the extra dependencies as well.
|
2020-05-21 17:55:19 +02:00
|
|
|
b) We add a dependency on the base candidate.
|
|
|
|
See below for why this is needed.
|
2020-03-26 12:19:55 +01:00
|
|
|
3. We return None for the underlying InstallRequirement, as the base
|
|
|
|
candidate will provide it, and we don't want to end up with duplicates.
|
|
|
|
|
|
|
|
The dependency on the base candidate is needed so that the resolver can't
|
|
|
|
decide that it should recommend foo[extra1] version 1.0 and foo[extra2]
|
|
|
|
version 2.0. Having those candidates depend on foo=1.0 and foo=2.0
|
|
|
|
respectively forces the resolver to recognise that this is a conflict.
|
|
|
|
"""
|
2020-04-02 19:27:34 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
2020-04-04 12:12:38 +02:00
|
|
|
base, # type: BaseCandidate
|
2020-05-19 11:04:15 +02:00
|
|
|
extras, # type: FrozenSet[str]
|
2020-04-02 19:27:34 +02:00
|
|
|
):
|
|
|
|
# type: (...) -> None
|
2020-03-25 13:25:23 +01:00
|
|
|
self.base = base
|
|
|
|
self.extras = extras
|
|
|
|
|
2020-11-21 14:53:37 +01:00
|
|
|
def __str__(self):
|
|
|
|
# type: () -> str
|
|
|
|
name, rest = str(self.base).split(" ", 1)
|
|
|
|
return "{}[{}] {}".format(name, ",".join(self.extras), rest)
|
|
|
|
|
2020-04-07 14:53:25 +02:00
|
|
|
def __repr__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{class_name}(base={base!r}, extras={extras!r})".format(
|
|
|
|
class_name=self.__class__.__name__,
|
|
|
|
base=self.base,
|
|
|
|
extras=self.extras,
|
|
|
|
)
|
|
|
|
|
2020-05-19 11:04:15 +02:00
|
|
|
def __hash__(self):
|
|
|
|
# type: () -> int
|
|
|
|
return hash((self.base, self.extras))
|
|
|
|
|
2020-04-04 09:17:56 +02:00
|
|
|
def __eq__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
if isinstance(other, self.__class__):
|
|
|
|
return self.base == other.base and self.extras == other.extras
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Needed for Python 2, which does not implement this by default
|
|
|
|
def __ne__(self, other):
|
|
|
|
# type: (Any) -> bool
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
2020-03-25 13:25:23 +01:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
# type: () -> str
|
|
|
|
"""The normalised name of the project the candidate refers to"""
|
|
|
|
return format_name(self.base.name, self.extras)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def version(self):
|
|
|
|
# type: () -> _BaseVersion
|
|
|
|
return self.base.version
|
|
|
|
|
2020-06-05 13:56:43 +02:00
|
|
|
def format_for_error(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "{} [{}]".format(
|
|
|
|
self.base.format_for_error(),
|
|
|
|
", ".join(sorted(self.extras))
|
|
|
|
)
|
|
|
|
|
2020-05-14 12:33:30 +02:00
|
|
|
@property
|
|
|
|
def is_installed(self):
|
2020-06-23 15:39:12 +02:00
|
|
|
# type: () -> bool
|
2020-05-14 12:33:30 +02:00
|
|
|
return self.base.is_installed
|
|
|
|
|
2020-06-23 15:39:12 +02:00
|
|
|
@property
|
|
|
|
def is_editable(self):
|
|
|
|
# type: () -> bool
|
|
|
|
return self.base.is_editable
|
|
|
|
|
2020-05-28 05:18:47 +02:00
|
|
|
@property
|
|
|
|
def source_link(self):
|
|
|
|
# type: () -> Optional[Link]
|
|
|
|
return self.base.source_link
|
|
|
|
|
2020-08-02 23:28:10 +02:00
|
|
|
def iter_dependencies(self, with_requires):
|
2020-08-02 02:22:04 +02:00
|
|
|
# type: (bool) -> Iterable[Optional[Requirement]]
|
2020-03-27 15:40:05 +01:00
|
|
|
factory = self.base._factory
|
2020-03-26 12:57:34 +01:00
|
|
|
|
2020-08-02 02:22:04 +02:00
|
|
|
# Add a dependency on the exact base
|
|
|
|
# (See note 2b in the class docstring)
|
|
|
|
yield factory.make_requirement_from_candidate(self.base)
|
2020-08-02 23:28:10 +02:00
|
|
|
if not with_requires:
|
2020-08-02 02:22:04 +02:00
|
|
|
return
|
|
|
|
|
2020-03-26 12:57:34 +01:00
|
|
|
# The user may have specified extras that the candidate doesn't
|
|
|
|
# support. We ignore any unsupported extras here.
|
|
|
|
valid_extras = self.extras.intersection(self.base.dist.extras)
|
2020-03-26 15:53:24 +01:00
|
|
|
invalid_extras = self.extras.difference(self.base.dist.extras)
|
2020-05-15 13:22:30 +02:00
|
|
|
for extra in sorted(invalid_extras):
|
2020-03-26 15:53:24 +01:00
|
|
|
logger.warning(
|
2020-05-15 13:22:30 +02:00
|
|
|
"%s %s does not provide the extra '%s'",
|
|
|
|
self.base.name,
|
|
|
|
self.version,
|
|
|
|
extra
|
2020-03-26 15:53:24 +01:00
|
|
|
)
|
2020-03-26 12:57:34 +01:00
|
|
|
|
2020-05-21 09:39:16 +02:00
|
|
|
for r in self.base.dist.requires(valid_extras):
|
2020-06-02 05:59:03 +02:00
|
|
|
requirement = factory.make_requirement_from_spec(
|
2020-05-21 10:14:26 +02:00
|
|
|
str(r), self.base._ireq, valid_extras,
|
|
|
|
)
|
|
|
|
if requirement:
|
|
|
|
yield requirement
|
2020-05-21 09:39:16 +02:00
|
|
|
|
2020-03-25 13:25:23 +01:00
|
|
|
def get_install_requirement(self):
|
2020-03-26 12:19:10 +01:00
|
|
|
# type: () -> Optional[InstallRequirement]
|
|
|
|
# We don't return anything here, because we always
|
|
|
|
# depend on the base candidate, and we'll get the
|
|
|
|
# install requirement from that.
|
|
|
|
return None
|
2020-04-01 12:14:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RequiresPythonCandidate(Candidate):
|
2020-05-14 12:33:30 +02:00
|
|
|
is_installed = False
|
2020-05-28 05:18:47 +02:00
|
|
|
source_link = None
|
2020-05-14 12:33:30 +02:00
|
|
|
|
2020-04-01 12:14:36 +02:00
|
|
|
def __init__(self, py_version_info):
|
|
|
|
# type: (Optional[Tuple[int, ...]]) -> None
|
|
|
|
if py_version_info is not None:
|
|
|
|
version_info = normalize_version_info(py_version_info)
|
|
|
|
else:
|
|
|
|
version_info = sys.version_info[:3]
|
|
|
|
self._version = Version(".".join(str(c) for c in version_info))
|
|
|
|
|
2020-04-04 15:51:20 +02:00
|
|
|
# We don't need to implement __eq__() and __ne__() since there is always
|
|
|
|
# only one RequiresPythonCandidate in a resolution, i.e. the host Python.
|
|
|
|
# The built-in object.__eq__() and object.__ne__() do exactly what we want.
|
|
|
|
|
2020-11-21 14:53:37 +01:00
|
|
|
def __str__(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "Python {}".format(self._version)
|
|
|
|
|
2020-04-01 12:14:36 +02:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
# type: () -> str
|
2020-04-02 15:42:26 +02:00
|
|
|
# Avoid conflicting with the PyPI package "Python".
|
2020-05-16 06:59:19 +02:00
|
|
|
return "<Python from Requires-Python>"
|
2020-04-01 12:14:36 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def version(self):
|
|
|
|
# type: () -> _BaseVersion
|
|
|
|
return self._version
|
|
|
|
|
2020-06-05 13:56:43 +02:00
|
|
|
def format_for_error(self):
|
|
|
|
# type: () -> str
|
|
|
|
return "Python {}".format(self.version)
|
|
|
|
|
2020-08-02 23:28:10 +02:00
|
|
|
def iter_dependencies(self, with_requires):
|
2020-08-02 02:22:04 +02:00
|
|
|
# type: (bool) -> Iterable[Optional[Requirement]]
|
2020-05-21 09:39:16 +02:00
|
|
|
return ()
|
2020-04-01 12:14:36 +02:00
|
|
|
|
|
|
|
def get_install_requirement(self):
|
|
|
|
# type: () -> Optional[InstallRequirement]
|
|
|
|
return None
|