Skip to content

Commit 0d0ab5c

Browse files
authored
fix(pypi): show overridden index urls in pypi download error (#3130)
Closes #2985 Suppose invalid `experimental_index_url_overrides` in `pip.parse` is set like below. ```bzl pip.parse( experimental_index_url = "https://pypi.org/simple", experimental_index_url_overrides = {"mypy": "https://invalid.com"}, hub_name = "pypi", requirements_lock = "//:requirements_lock.txt", ) ``` It fails as follows, showing only "pypi.org" as pypi index url, not "invalid.com" for for `mypy` package. ``` Error in fail: Failed to download metadata for ["mypy"] for from urls: ["https://pypi.org/simple"]. If you would like to skip downloading metadata for these packages please add 'simpleapi_skip=["mypy"]' to your 'pip.parse' call. ``` To show overridden url for each package, show url of each package that has been failed to download metadata. The error message with this PR is like below. ``` Error in fail: Failed to download metadata of the following packages from urls: { "mypy": "https://invalid.com", } If you would like to skip downloading metadata for these packages please add 'simpleapi_skip=["mypy"]' to your 'pip.parse' call. ```
1 parent ab3e3f7 commit 0d0ab5c

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ END_UNRELEASED_TEMPLATE
9999
absolute imports (Python 2's behavior without `absolute_import`). Previous
100100
behavior can be restored using the directive
101101
`# gazelle:python_resolve_sibling_imports true`
102+
* (pypi) Show overridden index URL of packages when downloading metadata have failed.
103+
([#2985](https://github.com/bazel-contrib/rules_python/issues/2985)).
102104

103105
{#v0-0-0-added}
104106
### Added

python/private/pypi/simpleapi_download.bzl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,24 @@ def simpleapi_download(
128128

129129
failed_sources = [pkg for pkg in attr.sources if pkg not in found_on_index]
130130
if failed_sources:
131+
pkg_index_urls = {
132+
pkg: index_url_overrides.get(
133+
normalize_name(pkg),
134+
index_urls,
135+
)
136+
for pkg in failed_sources
137+
}
138+
131139
_fail(
132-
"\n".join([
133-
"Failed to download metadata for {} for from urls: {}.".format(
134-
failed_sources,
135-
index_urls,
136-
),
137-
"If you would like to skip downloading metadata for these packages please add 'simpleapi_skip={}' to your 'pip.parse' call.".format(
138-
render.list(failed_sources),
139-
),
140-
]),
140+
"""
141+
Failed to download metadata of the following packages from urls:
142+
{pkg_index_urls}
143+
144+
If you would like to skip downloading metadata for these packages please add 'simpleapi_skip={failed_sources}' to your 'pip.parse' call.
145+
""".format(
146+
pkg_index_urls = render.dict(pkg_index_urls),
147+
failed_sources = render.list(failed_sources),
148+
),
141149
)
142150
return None
143151

tests/pypi/simpleapi_download/simpleapi_download_tests.bzl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def _test_fail(env):
8787
output = "",
8888
success = False,
8989
)
90+
if "bar" in url:
91+
return struct(
92+
output = "",
93+
success = False,
94+
)
9095
else:
9196
return struct(
9297
output = "data from {}".format(url),
@@ -99,7 +104,9 @@ def _test_fail(env):
99104
report_progress = lambda _: None,
100105
),
101106
attr = struct(
102-
index_url_overrides = {},
107+
index_url_overrides = {
108+
"foo": "invalid",
109+
},
103110
index_url = "main",
104111
extra_index_urls = ["extra"],
105112
sources = ["foo", "bar", "baz"],
@@ -112,16 +119,25 @@ def _test_fail(env):
112119
)
113120

114121
env.expect.that_collection(fails).contains_exactly([
115-
"""\
116-
Failed to download metadata for ["foo"] for from urls: ["main", "extra"].
117-
If you would like to skip downloading metadata for these packages please add 'simpleapi_skip=["foo"]' to your 'pip.parse' call.\
122+
"""
123+
Failed to download metadata of the following packages from urls:
124+
{
125+
"foo": "invalid",
126+
"bar": ["main", "extra"],
127+
}
128+
129+
If you would like to skip downloading metadata for these packages please add 'simpleapi_skip=[
130+
"foo",
131+
"bar",
132+
]' to your 'pip.parse' call.
118133
""",
119134
])
120135
env.expect.that_collection(calls).contains_exactly([
121-
"extra/foo/",
136+
"invalid/foo/",
122137
"main/bar/",
123138
"main/baz/",
124-
"main/foo/",
139+
"invalid/foo/",
140+
"extra/bar/",
125141
])
126142

127143
_tests.append(_test_fail)

0 commit comments

Comments
 (0)