-
-
Notifications
You must be signed in to change notification settings - Fork 676
fix(pypi): propagate fails if overrides are passed only one index is used #3666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aignas
wants to merge
1
commit into
bazel-contrib:main
Choose a base branch
from
aignas:aignas.chore.allow_fail_false_for_single_index
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,14 @@ _tests = [] | |
| def _test_simple(env): | ||
| calls = [] | ||
|
|
||
| def read_simpleapi(ctx, url, versions, attr, cache, get_auth, block): | ||
| def read_simpleapi(ctx, url, versions, attr, cache, get_auth, block, allow_fail): | ||
| _ = ctx # buildifier: disable=unused-variable | ||
| _ = attr | ||
| _ = cache | ||
| _ = get_auth | ||
| _ = versions | ||
| env.expect.that_bool(block).equals(False) | ||
| env.expect.that_bool(allow_fail).equals(True) | ||
| calls.append(url) | ||
| if "foo" in url and "main" in url: | ||
| return struct( | ||
|
|
@@ -96,13 +97,14 @@ def _test_fail(env): | |
| calls = [] | ||
| fails = [] | ||
|
|
||
| def read_simpleapi(ctx, url, versions, attr, cache, get_auth, block): | ||
| def read_simpleapi(ctx, url, versions, attr, cache, get_auth, block, allow_fail): | ||
| _ = ctx # buildifier: disable=unused-variable | ||
| _ = attr | ||
| _ = cache | ||
| _ = get_auth | ||
| _ = versions | ||
| env.expect.that_bool(block).equals(False) | ||
| env.expect.that_bool(allow_fail).equals(True) | ||
| calls.append(url) | ||
| if "foo" in url: | ||
| return struct( | ||
|
|
@@ -130,9 +132,7 @@ def _test_fail(env): | |
| report_progress = lambda _: None, | ||
| ), | ||
| attr = struct( | ||
| index_url_overrides = { | ||
| "foo": "invalid", | ||
| }, | ||
| index_url_overrides = {}, | ||
| index_url = "main", | ||
| extra_index_urls = ["extra"], | ||
| sources = {"bar": None, "baz": None, "foo": None}, | ||
|
|
@@ -149,7 +149,7 @@ def _test_fail(env): | |
| Failed to download metadata of the following packages from urls: | ||
| { | ||
| "bar": ["main", "extra"], | ||
| "foo": "invalid", | ||
| "foo": ["main", "extra"], | ||
| } | ||
|
|
||
| If you would like to skip downloading metadata for these packages please add 'simpleapi_skip=[ | ||
|
|
@@ -159,15 +159,86 @@ If you would like to skip downloading metadata for these packages please add 'si | |
| """, | ||
| ]) | ||
| env.expect.that_collection(calls).contains_exactly([ | ||
| "invalid/foo/", | ||
| "main/foo/", | ||
| "main/bar/", | ||
| "main/baz/", | ||
| "invalid/foo/", | ||
| "extra/foo/", | ||
| "extra/bar/", | ||
| ]) | ||
|
|
||
| _tests.append(_test_fail) | ||
|
|
||
| def _test_allow_fail_single_index(env): | ||
| calls = [] | ||
| fails = [] | ||
|
|
||
| def read_simpleapi(ctx, *, url, versions, attr, cache, get_auth, block, allow_fail): | ||
| _ = ctx # buildifier: disable=unused-variable | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: assign them all to underscore in a single line. Just saves a bit of vertical space |
||
| _ = attr | ||
| _ = cache | ||
| _ = get_auth | ||
| _ = versions | ||
| env.expect.that_bool(block).equals(False) | ||
| env.expect.that_bool(allow_fail).equals(False) | ||
| calls.append(url) | ||
| return struct( | ||
| output = struct( | ||
| sdists = {"deadbeef": url.strip("/").split("/")[-1]}, | ||
| whls = {"deadb33f": url.strip("/").split("/")[-1]}, | ||
| sha256s_by_version = {"fizz": url.strip("/").split("/")[-1]}, | ||
| ), | ||
| success = True, | ||
| ) | ||
|
|
||
| contents = simpleapi_download( | ||
| ctx = struct( | ||
| getenv = {}.get, | ||
| report_progress = lambda _: None, | ||
| ), | ||
| attr = struct( | ||
| index_url_overrides = { | ||
| "foo": "extra", | ||
| }, | ||
| index_url = "main", | ||
| extra_index_urls = [], | ||
| sources = {"bar": None, "baz": None, "foo": None}, | ||
| envsubst = [], | ||
| ), | ||
| cache = pypi_cache(), | ||
| parallel_download = True, | ||
| read_simpleapi = read_simpleapi, | ||
| _fail = fails.append, | ||
| ) | ||
|
|
||
| env.expect.that_collection(fails).contains_exactly([]) | ||
| env.expect.that_collection(calls).contains_exactly([ | ||
| "main/bar/", | ||
| "main/baz/", | ||
| "extra/foo/", | ||
| ]) | ||
| env.expect.that_dict(contents).contains_exactly({ | ||
| "bar": struct( | ||
| index_url = "main/bar/", | ||
| sdists = {"deadbeef": "bar"}, | ||
| sha256s_by_version = {"fizz": "bar"}, | ||
| whls = {"deadb33f": "bar"}, | ||
| ), | ||
| "baz": struct( | ||
| index_url = "main/baz/", | ||
| sdists = {"deadbeef": "baz"}, | ||
| sha256s_by_version = {"fizz": "baz"}, | ||
| whls = {"deadb33f": "baz"}, | ||
| ), | ||
| "foo": struct( | ||
| index_url = "extra/foo/", | ||
| sdists = {"deadbeef": "foo"}, | ||
| sha256s_by_version = {"fizz": "foo"}, | ||
| whls = {"deadb33f": "foo"}, | ||
| ), | ||
| }) | ||
|
|
||
| _tests.append(_test_allow_fail_single_index) | ||
|
|
||
| def _test_download_url(env): | ||
| downloads = {} | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for setting
allow_failhas an unintended side effect when bothindex_url_overridesandextra_index_urlsare used. Whenindex_url_overridesis set,allow_failis globally set toFalse. This prevents the intended fallback mechanism for packages that are not in the override map but might exist in one of theextra_index_urls.For example, consider this scenario:
index_url = "A"extra_index_urls = ["B"]index_url_overrides = {"pkg1": "C"}requirements.txtcontainspkg1andpkg2.pkg2exists in index "B" but not "A".With the current change, the download for
pkg2from index "A" will fail, and becauseallow_failisFalse, the entire process will stop. It will not attempt to downloadpkg2from index "B". This seems to break the expected fallback behavior.The
allow_faillogic should probably be more granular, determined on a per-package basis. It should beFalseonly when a download is expected to be definitive (e.g., only one index URL to try for a package, or for a package with a specific override).The existing tests do not seem to cover this specific combination of multiple indexes and an override map, which is why this issue might have been missed.