Commit Graph

121 Commits

Author SHA1 Message Date
Paul Moore 4db45851b6 Explicitly test installs (and fix a bug found by those tests!) 2022-04-23 13:14:22 +01:00
Paul Moore af28440792 Store config settings on the install requirement 2022-04-21 18:30:48 +01:00
Pradyun Gedam 2e8e5ad3df
Don't duplicate output when raising out of distribution preparation 2022-01-25 01:38:23 +00:00
Tzu-ping Chung c54d40474a CHange ireq.satisfied_by to abstract distribution 2021-11-18 17:58:10 +08:00
Stéphane Bidoul e5be3f796e
Add PEP 660 support (build_editable) 2021-09-28 23:04:51 +02:00
Tzu-ping Chung 135faabfd6
Remove direct pkg_resource usages from resolver and preparer 2021-08-23 02:07:33 +08:00
Harutaka Kawamura 72e1ff35c7
Complete type annotations in `pip/_internal/resolution` (#10125) 2021-07-12 11:41:48 +08:00
Tzu-ping Chung c8638adc5a Check Requires-Python before other dependencies
This makes the resolver fail quicker when there's a interpreter
version conflict, and avoid additional (useless) downloads.
2021-06-02 01:54:44 +08:00
Tzu-ping Chung 0305e0d596 Implement extra-ed requirement merging
When a requirement is requested multiple times, some via a direct URL
("req @ URL") and some not but with extras ("req[extra] VERSION"), the
resolver previous could not correctly find "req[extra]" if "req" is
available in an index.

This additional logic makes the resolver, when encountering a
requirement with identifier "req[extra]", to also look for explicit
candidates listed under "req", and add them as found matches for
"req[extra]".
2021-04-19 08:37:35 +08:00
Stéphane Bidoul 8fc65ea53f
Merge pull request #9673 from mwchase/url-constraints-final-2
Support URL constraints in the new resolver
2021-04-18 12:31:45 +02:00
Max W Chase 4c69ab2a2c Support URL constraints in the new resolver
Fixes #8253
2021-04-17 07:59:57 -04:00
Tzu-ping Chung 56a8f3d8bd Typing fixes 2021-03-10 16:40:58 +08:00
Stefano Rivera ba4b7f110d Don't cache _version 2021-03-03 09:27:36 -08:00
Stefano Rivera 8f2e3d6978 Parse pkg_resources Dist versions with packaging.version
Due to a mix of bundled and unbundled dependencies, pkg_resources
Version class may not be the same as packaging's Version class.

See: https://github.com/pypa/setuptools/issues/2052
2021-03-02 12:19:10 -08:00
Jon Dufresne 8a6f6ac19b Blacken src/pip/_internal/resolution directory 2021-02-20 06:51:44 -08:00
Jon Dufresne 0945809afc Remove typing.TYPE_CHECKING guards
The typing module has been available since Python 3.5. Guarding the
import has been unnecessary since dropping Python 2.

Some guards remain to either:

- Avoid circular imports
- Importing objects that are also guarded by typing.TYPE_CHECKING
- Avoid mypy_extensions dependency
2021-02-19 18:34:21 -08:00
Jon Dufresne a6392bd62e Replace pip._internal.utils.typing with stdlib typing
The stdlib module has been available since Python 3.5 and the
TYPE_CHECKING constant has been available since 3.5.2.

By using stdlib, this removes the need for pip to maintain its own
Python 2 typing compatibility shim.
2021-02-18 19:09:13 -08:00
Tzu-ping Chung 6c0e484703 Include both sources in inconsistency error 2021-01-18 19:00:52 +08:00
Jon Dufresne a49f1732e9 Remove unnecessary __ne__ definitions
Unnecessary since dropping Python 2 support. In Python 3, `__ne__`
defaults to the opposite of of `__eq__`.

https://docs.python.org/3/reference/datamodel.html#object.__ne__

> For `__ne__()`, by default it delegates to `__eq__()` and inverts the
> result unless it is `NotImplemented`.
2020-12-30 08:23:04 -08:00
Tzu-ping Chung 41a30089de Re-apply invalid metadata skip
Skip candidate not providing valid metadata

This reverts commit 7165ab8cb9.
2020-12-27 04:16:24 +08:00
Jon Dufresne cdcf74fb8e Use f-strings for simple string formatting
Use pyupgrade to convert simple string formatting to use f-string
syntax. pyupgrade is intentionally timid and will not create an f-string
if it would make the expression longer or if the substitution parameters
are anything but simple names or dotted names.
2020-12-25 16:21:20 -08:00
Jon Dufresne c148bcc1aa Use short Python3 super() syntax 2020-12-24 15:11:51 -08:00
Pradyun Gedam 7165ab8cb9
Revert "Skip candidate not providing valid metadata" 2020-12-15 10:17:20 +00:00
Tzu-ping Chung b2c04877fa Add comments explaining InstallationError handling 2020-12-12 18:47:37 +08:00
Tzu-ping Chung d45541c8f3 Skip candidate not providing valid metadata
This is done by catching InstallationError from the underlying
distribution preparation logic. There are three cases to catch:

1. Candidates from indexes. These are simply ignored since we can
   potentially satisfy the requirement with other candidates.
2. Candidates from URLs with a dist name (PEP 508 or #egg=). A new
   UnsatisfiableRequirement class is introduced to represent this; it is
   like an ExplicitRequirement without an underlying candidate. As the
   name suggests, an instance of this can never be satisfied, and will
   cause eventual backtracking.
3. Candidates from URLs without a dist name. This is only possible for
   top-level user requirements, and no recourse is possible for them. So
   we error out eagerly.

The InstallationError raised during distribution preparation is cached
in the factory, like successfully prepared candidates, since we don't
want to repeatedly try to build a candidate if we already know it'd
fail. Plus pip's preparation logic also does not allow packages to be
built multiple times anyway.
2020-12-12 02:23:32 +08:00
Tzu-ping Chung e2fb3e12ab Use the project name to look up constraints
User-specified constraints only contain the project name without extras,
but a constraint a project A would also apply to A's extra variants.
This introduces a new project_name property on Requirement and Candidate
classes for this lookup.
2020-12-08 16:32:24 +08:00
Tzu-ping Chung 9efafb186f Implement __str__ for debuggability 2020-11-21 22:14:24 +08:00
Tzu-ping Chung d08b4d99e2 Use packaging.version to check version equality 2020-11-03 16:04:35 +08:00
Tzu-ping Chung 8b2b92485c Include Requires-Python dep even with --no-deps 2020-08-26 09:49:25 +08:00
Pradyun Gedam ee4371c386
Merge pull request #8685 from chrahunt/use-preparer-for-lazy-wheels 2020-08-04 18:46:56 +05:30
Pradyun Gedam 4fa31d509f
Merge pull request #8678 from uranusjr/new-resolver-no-deps-extras-install-self 2020-08-04 06:48:11 +05:30
Chris Hunt 6c4d4f3b78 Move _fetch_metadata to RequirementPreparer
The fact that all of this functionality can be put in terms of the
`RequirementPreparer` indicates that, at least at this point, this is
the cleanest place to put this functionality.
2020-08-02 19:36:29 -04:00
Chris Hunt 4e1bff741d Promote Wheel-related assertions to LinkCandidate constructor
These are things we know will be true because of the existing wheel
processing. In the future we may delegate the extraction of these to the
LinkCandidate itself so it doesn't have to be an assertion.
2020-08-02 19:36:28 -04:00
Chris Hunt 9e463916d0 Extract name and version from Wheel link
We happen to know that this is the same treatment that gave us `_name`
and `_version` for Wheels in the first place (in `LinkEvaluator`). It's not
ideal, however the metadata consistency check that occurs in `Candidate`
after creation of a `Distribution` guards us against any deviation in
the name and version during our processing.

Reduces dependence on Candidate.
2020-08-02 19:36:14 -04:00
Chris Hunt defbf82a8f Use link from InstallRequirement
Since when we generate the InstallRequirement we set the link, these
must be the same.

Reduces dependence on Candidate.
2020-08-02 18:40:11 -04:00
Chris Hunt f4603078cf Pass InstallRequirement to _fetch_metadata
Reduces dependence on Candidate.
2020-08-02 18:40:11 -04:00
Chris Hunt f0d4df10eb Propagate lazy_wheel option through RequirementPreparer
Reduces dependence on Candidate (and Resolver (and Factory)).
2020-08-02 18:40:11 -04:00
Chris Hunt 45ab317610 Move call to _fetch_metadata next to call to RequirementPreparer
Since wheels can't be editable, we can move this into LinkCandidate,
closer to `RequirementPreparer.prepare_linked_requirement` into which we
want to integrate `_fetch_metadata`.
2020-08-02 18:40:11 -04:00
Chris Hunt ec5b6d7b80 Remove extra metadata consistency check
Instead of an early return, we fall through to the existing check at the
end of this function. This aligns our treatment of `_fetch_metadata` and
`_prepare_distribution`.
2020-08-02 18:40:11 -04:00
Chris Hunt a72d04f734 Move common processing out of _fetch_metadata
Returning a `Distribution` makes `_fetch_metadata` look more like
`_prepare_distribution`, in preparation for moving it there next.
2020-08-02 18:40:11 -04:00
Chris Hunt 8c3c0ade78 Move _fetch_metadata into _prepare
Since `_prepare` is called in two places, we preserve the
`if self._dist is not None` protection above the new call to
`_fetch_metadata`. The second `if` in `_prepare` handles the early
return required when processing a lazy wheel.
2020-08-02 18:40:09 -04:00
Chris Hunt 4d94ae4c40 Move non-lazy req fallback outside of `_fetch_metadata`
No change in behavior, we just want to unify "requirements processing"
and moving this function out is a prereq for moving `_fetch_metadata` in.
2020-08-02 18:39:57 -04:00
Chris Hunt 7a5e043776 Remove unnecessary check for _dist
Since `_prepare` now internally validates that `_dist` isn't set, we
don't need to.
2020-08-02 18:39:15 -04:00
Chris Hunt 7289625734 Remove redundant guard variable
Now that `_dist` is only set on success, we can use it to guard against
repeated execution instead of `_prepared`. As a result there are now only
two possible outcomes for calling `dist`:

1. `_dist` set and returned - lazy and non-lazy req
2. `_dist` not set and exception raised - bad lazy or bad non-lazy req
2020-08-02 18:38:13 -04:00
Chris Hunt d957cc94c8 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 18:37:50 -04:00
Tzu-ping Chung 32b5e43c79 Flip the flag with another name 2020-08-03 05:28:10 +08:00
Tzu-ping Chung 3ce63a62d7 Ask candidates for dependencies even on --no-deps
ExtrasCandidate need to provide one dependency on the non-extra-ed self.
2020-08-02 16:12:46 +08:00
Nguyễn Gia Phong b795c9a7d6 Abstract away AbstractDistribution in higher-level resolver code 2020-07-26 17:13:04 +07:00
Nguyễn Gia Phong 5d15291274 Use lazy wheel to obtain dep info for new resolver 2020-07-21 16:00:34 +07:00
Nguyễn Gia Phong 2152a51b8c Give metadata consistency check its own method 2020-07-21 16:00:01 +07:00