Refactored `_get_index_url()` to get integration tests for the subprocess backend working.
Keyring support via the 'subprocess' provider can only retrieve a password, not a username-password combo. The username therefor MUST come from the URL.
If the URL obtained from the index does not contain a username then the username from a matching index is used. `_get_index_url()` does that matching.
The problem this refactoring solves is that the URL where a wheel or sdist can be downloaded from does not always start with the index url. Azure DevOps Artifacts Feeds are an example since it replaces the friendly name of the Feed with the GUID of the Feed. Causing `url.startswith(prefix)` to evaluate as `False`.
The new behaviour is to return the index which matches the netloc and has the longest common prefix of the `path` property of the value returned by `urllib.parse.urlsplit()`. The behaviour for resolving ties is unspecified.
This is designed as a script and a data file (in YAML format), and meant
to manage the RTD redirects with a version controlled file.
This makes it possible for pull requests to this repository to update
the redirects for this project's documentation (eg: for better error
urls) and for this evolution to be tracked as a part of version control
history.
pytest includes type annotations and is PEP-561 compliant. This helps
ensure correct pytest API usage.
This caught a misuse of pytest.mark.skipif which did not include a
boolean argument. The test is now marked "network" and no longer
skipped.
The tests are a large consumer of the pip API (both the internal API and
otherwise). By running mypy on tests, we help to:
1. Ensure the internal API is consistent with regards to typing
2. Ensure the tests are representative of real life scenarios as the API
are used correctly.
3. Helps to recognize unnecessary tests that simply pass junk data to
functions which can be caught by the type checker.
4. Make sure test support code in tests/lib/ is correct and consistent.
This is especially important when refactoring such code. For example, if
we were to replace tests/lib/path.py with pathlib.
As a first start, untyped defs are allowed. All existing typing issues
have been resolved. Overtime, we can chip away at untyped defs and
eventually remove the configuration option for stricter type checking of
tests.
The following changes were made to help make mypy pass:
Remove unused record_callback argument from make_wheel() in tests.
Unused since its introduction in
6d8a58f7e1.
Replace toml with tomli_w in tests/functional/test_pep517.py. Unlike the
toml package, tomli_w contains inline typing annotations.
Remove unnecessary make_no_network_finder(). Unnecessary since
bab1e4f8a1 where the _get_pages method was
removed.
This notably gets us on a version of mypy that uses modular typeshed:
https://mypy-lang.blogspot.com/2021/05/the-upcoming-switch-to-modular-typeshed.html
which allows us to have finer control over what version of stubs we pull
in from typeshed. Also contains other routine improvements to mypy.
Required a few minor typing changes.
Add flag --show-error-code so errors look like this
src/pip/_internal/network/auth.py:70: error: Incompatible types in assignment
(expression has type "None", variable has type Module) [assignment]
rather than
src/pip/_internal/network/auth.py:70: error: Incompatible types in assignment
(expression has type "None", variable has type Module)
In autocompletion.py, the should_list_installed boolean expression was
flipped to workaround upstream black bug:
https://github.com/psf/black/issues/1629
The bug makes black fail to stabilize formatting when the list isn't the
last piece of the expression.