1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
Commit graph

156 commits

Author SHA1 Message Date
Harutaka Kawamura 72e1ff35c7
Complete type annotations in pip/_internal/resolution (#10125) 2021-07-12 11:41:48 +08:00
briantracy 37a2b12a21
Special case warning for requirements.txt install (#9915)
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
2021-07-12 11:40:43 +08:00
Tzu-ping Chung d18ac6250e Exclude a known incompatible installed candidate
The resolver collects previously known incompatibilites and sends them
to the provider. But previously the provider does not correctly exclude
the currently-installed candidate if it is present in that
incompatibility list, causing the resolver to enter a loop trying that
same candidate. This patch correctly applies incompat_ids when producing
an AlreadyInstalledCandidate and exclude it if its id() is in the set.
2021-05-18 23:00:25 +08:00
Tzu-ping Chung cf4e3aa055 Remove stray id(candidate) call
Also moves the incompatibility candidate calculation to closer to their
usages.
2021-04-24 02:09:24 +08:00
Tzu-ping Chung 9cab9834fa Refactor Factory.find_candidates() for readability 2021-04-19 12:21:35 +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 4e56f1c52d Take responsibility to remove incompatibilities 2021-04-04 20:39:28 +08:00
Tzu-ping Chung 9ceabb568f Add note to explain the cast 2021-04-03 16:25:38 +08:00
Tzu-ping Chung 0d39ae9734 Pull in resolvelib's typing information 2021-04-03 16:25:38 +08:00
Andrey Bienkowski 622f104694 Use f-strings for formatting
suggested by pyupgrade --py36-plus
2021-03-30 15:48:27 +03:00
Tzu-ping Chung 56a8f3d8bd Typing fixes 2021-03-10 16:40:58 +08:00
Tzu-ping Chung 80e0163e03
Merge pull request #9552
From uranusjr/new-resolver-requires-python-error
2021-03-08 02:26:20 +08:00
Blazej Michalik d1d914597c
Refactor set(...){...}
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
2021-02-28 00:41:04 +01:00
Tzu-ping Chung d87abdfdfe Fix error reporting on Requires-Python conflicts 2021-02-28 07:31:39 +08:00
Blazej Michalik a2c57948b6 Bring back the "from versions:" message
In the new resolver the "(from versions ...)" message, shown on
failure to resolve a package, has been removed. This commit brings it
back.
2021-02-27 20:37:10 +01:00
Tzu-ping Chung 917ecadd77 Show constraint in error message 2021-02-23 02:08:19 +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 2e70ec0751 Create the candidate lazily to avoid download 2021-01-27 19:58:24 +08:00
Tzu-ping Chung 79cbe6b93f Avoid downloading candidates of a same version
Since 41a30089de, Candidate objects prepare their underlying
distribution eagerly on creation, so the error can be caught
deterministically to trigger backtracking.

This however has a negative side-effect. Since dist preparation involves
metadata validation, a remote distribution must be downloaded on
Candidate creation. This means that an sdist will be downloaded,
validated, and discarded (since its version is known to be incompatible)
during backtracking.

This commit moves version deduplication of candidates from indexes to
before the Candidate object is created, to avoid unneeded preparation.

Note that we still need another round of deduplication in FoundCandidates
to remove duplicated candidates when a distribution is already installed.
2021-01-06 17:19:59 +08:00
Jon Dufresne 133e146a88 Remove unused type VersionCandidate
Unused since 6a8956d7a8.
2020-12-28 19:18:20 -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
Pradyun Gedam 86afa89043
Merge pull request #9361 from jdufresne/f-strings
Use f-strings for simple string formatting
2020-12-26 10:24:18 +00: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 09b3d3a50b Remove object from class definitions
Unnecessary since dropping Python 2 support. In Python 3, all classes
are new style classes.
2020-12-25 15:48:11 -08:00
Pradyun Gedam 7165ab8cb9
Revert "Skip candidate not providing valid metadata" 2020-12-15 10:17:20 +00:00
Tzu-ping Chung d869e0cbfd Merge master 2020-12-12 18:49:14 +08:00
Tzu-ping Chung b2c04877fa Add comments explaining InstallationError handling 2020-12-12 18:47:37 +08:00
Tzu-ping Chung 120105d3e8 Cache AlreadyInstalledCandidate
Since the "Requirement already satisfied" message is printed during
candidate preparation, instantiating the candidate multiple times result
in excessive logging during intensive backtracking. By caching the
already-installed candidates, each package is only prepared, and thus
only logged once.
2020-12-12 02:39:54 +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 ffb3d1bc76 Correctly implement yanking logic
Do not return yanked versions from an index, unless the version
range can only be satisfied by yanked candidates.
2020-12-04 23:46:25 +08:00
Tzu-ping Chung d589795834 Allow constraining an explicit requirement 2020-11-21 22:14:24 +08:00
Tzu-ping Chung bf55229fc6 Use set to dedup package list in error message 2020-11-04 21:29:19 +08:00
Xavier Fernandez fad456a165 resolver: stabilize output for tests (& users)
Otherwise the test_install_distribution_union_with_versions test can end
up with either:

    Cannot install localextras[bar] 0.0.2 and localextras[baz] 0.0.1 because these package versions have conflicting dependencies.

or

    Cannot install localextras[baz] 0.0.2 and localextras[bar] 0.0.1 because these package versions have conflicting dependencies.
2020-10-31 00:07:34 +01:00
Tzu-ping Chung 8326148149 Implement "lazy sequence" to avoid Internet
find_matches() is modified to return a special type that implements
the sequence protocol (instead of a plain list). This special sequence
type tries to use the installed candidate as the first element if
possible, and only access indexes when the installed candidate is
considered unsatisfactory.
2020-10-13 16:06:00 +08:00
Noah Gorny 960dca9949 resolvelib: factory: Get installed distributions correctly 2020-10-10 02:23:08 +03:00
Pradyun Gedam 25ab172b55
Update linter: isort 2020-09-23 19:52:28 +05:30
Pradyun Gedam e61bb616ef
Merge pull request #8839 from uranusjr/new-resolver-hash-intersect 2020-09-17 10:58:44 +05:30
Nguyễn Gia Phong cca500f053 Remove unused definitions 2020-09-04 17:37:43 +07:00
Tzu-ping Chung dfaa111004 Pull in hashes from constraint files 2020-09-03 17:26:52 +08:00
Tzu-ping Chung 700eb7734f Hashes from lines should intersect, not union 2020-09-03 17:19:01 +08:00
Pradyun Gedam ee4371c386
Merge pull request #8685 from chrahunt/use-preparer-for-lazy-wheels 2020-08-04 18:46:56 +05:30
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
Pradyun Gedam c412613efe
Tweak ResolutionImpossible error line
This makes it more consistent with how error "summary" lines look.

eg:
     IndexError: list index out of range
      ModuleNotFoundError: No module named 'notamodule'
2020-08-02 07:55:49 +05:30
Pradyun Gedam b97c199cf7
Point to latest documentation
This allows us to update the content users would see as we get feedback.
2020-08-02 07:53:02 +05:30
Tzu-ping Chung 3ff9ee151d Account for comes_from string 2020-07-26 15:59:42 +08: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 f8b06a3906 Enable flake8-logging-format 2020-07-17 14:33:19 +07:00
Pradyun Gedam b419ca7317
Fix the link on new-resolver dependency conflicts 2020-07-17 06:03:01 +05:30
Tzu-ping Chung 01e0700e68 Skip installing if the version matches locally
This check only applies to explicit requirements since we avoid
downloading the dist from finder altogether when there is a matching
installation (although the check wouldn’t change the behaviour in that
case anyway).

We can do this when we build the `ExplicitRequirement` instead, like how
we did for `SpecifierRequirement`, but that would require us to resolve
the direct requirement’s version eagerly, which I don’t want to.

The implemented approach checks the version only after resolution, at
which point the distribution is already built anyway and the operation
is cheap.
2020-07-06 11:06:14 +08:00
Paul Moore d287033599
Merge pull request #8394 from pfmoore/nr_conflict_message
Improve the message for "Resolution Conflict" errors
2020-06-18 13:45:51 +01:00
Paul Moore 868ba81a74 Next iteration of message 2020-06-17 17:11:32 +01:00
Paul Moore 2795742b31 Add handling of inconsistent root requirements 2020-06-17 16:47:04 +01:00
Paul Moore 09d311594e Move error handling to factory.get_installation_error() 2020-06-17 16:44:53 +01:00
Tzu-ping Chung ebb90c6411 Reject incompatibile direct wheel link
This mirrors the behavior in the legacy resolver. In the future we may
want to backtrack in this situation instead, but I haven't found a clean
way to do this. We may need to introduce an "empty" requirement class.

The `PackageFinder.target_python` interface is also not the most clean.
Maybe we should expose the target Python object instead. Not sure yet.
2020-06-10 20:57:23 +08:00
Tzu-ping Chung e647b12540 Yield installed candidate at the correct position 2020-06-05 08:17:28 +08:00
Tzu-ping Chung 1719fc3dcc Merge spec->req constructors
Since both functions now return Optional[Requirement], we can just use
the same implementation.
2020-06-02 12:02:52 +08:00
Tzu-ping Chung d5204dd0ba Move markers check into the ireq->req constructor
This makes the check apply to ALL requirement constructions, no
exceptions.
2020-06-02 12:02:52 +08:00
Pradyun Gedam b5a5bcf13b
Rename parent to template 2020-05-28 18:50:09 +05:30
Tzu-ping Chung 9ee19a1190 Always use frozenset 2020-05-27 23:10:56 +08:00
Tzu-ping Chung b8404fde99 Always read extras from InstallRequirement.extras 2020-05-27 23:10:56 +08:00
Tzu-ping Chung 6c6b6a7765 Implement new Provider.find_matches() 2020-05-27 23:10:56 +08:00
Tzu-ping Chung 48c3d0c8ec Typo in docstring
Co-authored-by: Paul Moore <p.f.moore@gmail.com>
2020-05-27 20:19:38 +08:00
Tzu-ping Chung bc9b288b1e Implement wheel cache lookup in the new resolver 2020-05-27 20:19:37 +08:00
Tzu-ping Chung dab7b94ade Derive Requirement name from ireq is possible
This is useful when resolving the wheel cache.
2020-05-27 20:19:37 +08:00
Pradyun Gedam 901898c84f
Make mypy happy 2020-05-21 21:47:42 +05:30
Pradyun Gedam 775f9ff6ca
Add a helper for making ExplicitRequirement objects 2020-05-21 21:47:38 +05:30
Tzu-ping Chung de63eae0c3 Match logging 2020-05-21 18:09:35 +08:00
Tzu-ping Chung e6352bc468 Return package dependencies only if markers match 2020-05-21 16:14:26 +08:00
Tzu-ping Chung f39134699b Avoid the horrendous line break for type hints 2020-05-18 17:15:06 +08:00
Tzu-ping Chung ec86cb1970 Use OrderedDict to prefer links found *later* 2020-05-18 16:35:09 +08:00
Paul Moore e28b388c73
Merge pull request #7997 from uranusjr/resolver-use-user-site
New resolver: implement --user
2020-05-15 20:01:50 +01:00
Paul Moore 96b3377cd7 Type annotations 2020-05-15 10:57:07 +01:00
Paul Moore 9cf1bed78d Address review comments 2020-05-14 11:33:30 +01:00
Paul Moore ddbc8fd7c1 Split find_matches into generation and sorting 2020-05-13 17:52:09 +01:00
Tzu-ping Chung d8062791dd Implement use-user-site 2020-05-06 03:48:34 +08:00
Tzu-ping Chung 647dc6e128 Include prereleases in specifier check 2020-05-04 02:08:27 +08:00
Paul Moore 1599cc2a36 Merge branch 'master' into nr_upgrade_strategy 2020-05-03 11:01:27 +01:00
Paul Moore 1eb7011da4 Add an assertion that upgrade_strategy is valid 2020-04-28 10:39:53 +01:00
Tzu-ping Chung d8aede42d1 Correctly pass extras to explicit requirement
Local source directory is still not working due to some other reasons.
Need to investigate.
2020-04-27 14:23:15 +08:00
Paul Moore 7a54b2b3a8 Use is_direct rather than an explicit root parameter 2020-04-24 14:30:34 +01:00
Paul Moore 04bf571521 Ensure root requirement name is canonicalised 2020-04-24 14:30:34 +01:00
Paul Moore d605530b44 Implement upgrade strategies for the new resolver 2020-04-24 11:08:06 +01:00
Pradyun Gedam 97f639057e
Merge pull request #8014 from uranusjr/always-return-installed-candidate 2020-04-18 16:15:14 +05:30
Tzu-ping Chung 9c97b285b9 Rename variable for clarity 2020-04-16 13:44:13 +08:00
Tzu-ping Chung 84b99c20b8 Canonicalize installed distribution keys 2020-04-13 18:05:24 +08:00
Tzu-ping Chung d2028e9538 Implement RequiresPythonRequirement with context
This specialized class is able to carry more context information than
the previous implementation (which reuses ExplicitRequirement). Error
reports can thus provide better messages by introspecting.
2020-04-10 23:17:29 +08:00
Tzu-ping Chung cfac6aebdd Always return an install candidate last if matches
This rewrites how a SpecifierRequirement generates candidates, so it

* Always return an AlreadyInstalledCandidate (as long as the version
  satisfies the specifier), even if PackageFinder does not return a
  candidate for the same version.
* Always put the AlreadyInstalledCandidate last, so it's preferred over
  LinkCandidate, preventing version changes if possible.
2020-04-10 20:51:06 +08:00
Tzu-ping Chung be60eaaa4f Uninstall existing dist before reinstallation 2020-04-08 17:17:25 +08:00
Tzu-ping Chung 90ce7c9edd Refactor to prepare for upgrade procedures 2020-04-08 17:17:25 +08:00
Tzu-ping Chung b89e1c2fb4 Canonicalize InstallationCandidate name
Caught by test_single_download_from_requirements_file etc.
2020-04-07 19:05:26 +08:00
Tzu-ping Chung 05f7dbd0c8 Type hint hacks 2020-04-04 18:15:26 +08:00
Tzu-ping Chung 2430aba879 Implement editable candidate 2020-04-04 17:51:43 +08:00
Tzu-ping Chung 3b06cb6b53 Refactor ireq-related operations to base class 2020-04-03 21:33:16 +08:00
Paul Moore d53d3d6b24 Use the name/version from the InstallationCandidate 2020-04-03 11:23:35 +01:00
Tzu-ping Chung 7511737ee7 AlreadyInstalledCandidate 2020-04-03 01:27:34 +08:00
Tzu-ping Chung f061f3f691 Fetch install dist for a candidate if available
The candidate creation logic is further moved into the factory. The
factory would use pkg_resources.get_distribution() to find a matching
distribution for a givan InstallationCandidate. If found, the Candidate
would be created based on that found distribution, instead of the link.

--ignore-installed is implemented as to always use the link to create
candidates, even if an installed distribution is found.
2020-04-03 00:36:26 +08:00