-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
BUG: fetch_string_and_headers compat: raise in and out of pyodide #129
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from packaging.utils import InvalidWheelFilename | ||
from packaging.version import InvalidVersion, Version | ||
|
||
from ._compat import fetch_string_and_headers | ||
from ._compat import HttpStatusError, fetch_string_and_headers | ||
from ._utils import is_package_compatible, parse_version | ||
from .externals.mousebender.simple import from_project_details_html | ||
from .wheelinfo import WheelInfo | ||
|
@@ -276,11 +276,33 @@ async def query_package( | |
|
||
try: | ||
metadata, headers = await fetch_string_and_headers(url, _fetch_kwargs) | ||
except HttpStatusError as e: | ||
if e.status_code == 404: | ||
continue | ||
raise | ||
except OSError: | ||
continue | ||
# temporary pyodide compatibility. | ||
# pypi now set proper CORS on 404 (https://github.com/pypi/warehouse/pull/16339), | ||
# but stable pyodide (<0.27) does not yet have proper HttpStatusError exception | ||
# so when: on pyodide and 0.26.x we ignore OSError. Once we drop support for 0.26 | ||
# all this OSError except clause should just be gone. | ||
try: | ||
import pyodide | ||
from packaging.version import parse | ||
|
||
if parse(pyodide.__version__) > parse("0.27"): | ||
# reraise on more recent pyodide. | ||
raise | ||
continue | ||
except ImportError: | ||
# not in pyodide. | ||
raise | ||
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. Here too. |
||
|
||
content_type = headers.get("content-type", "").lower() | ||
parser = _select_parser(content_type, name) | ||
try: | ||
parser = _select_parser(content_type, name) | ||
except ValueError as e: | ||
raise ValueError(f"Error trying to decode url: {url}") from e | ||
return parser(metadata) | ||
else: | ||
raise ValueError( | ||
|
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
test that function in compati behave the same | ||
|
||
""" | ||
|
||
import pytest | ||
from pytest_pyodide import run_in_pyodide | ||
|
||
|
||
@pytest.mark.driver_timeout(10) | ||
def test_404(selenium_standalone_micropip, httpserver, request): | ||
selenium_standalone_micropip.set_script_timeout(11) | ||
|
||
@run_in_pyodide(packages=["micropip", "packaging"]) | ||
async def _inner_test_404_raise(selenium, url): | ||
import pyodide | ||
import pytest | ||
from packaging.version import parse | ||
|
||
from micropip._compat import HttpStatusError, fetch_string_and_headers | ||
|
||
if parse(pyodide.__version__) > parse("0.27"): | ||
ExpectedErrorClass = HttpStatusError | ||
else: | ||
ExpectedErrorClass = OSError | ||
|
||
with pytest.raises(ExpectedErrorClass): | ||
await fetch_string_and_headers(url, {}) | ||
|
||
httpserver.expect_request("/404").respond_with_data( | ||
"Not found", | ||
status=404, | ||
content_type="text/plain", | ||
headers={"Access-Control-Allow-Origin": "*"}, | ||
) | ||
url_404 = httpserver.url_for("/404") | ||
_inner_test_404_raise(selenium_standalone_micropip, url_404) |
This file contains 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
Oops, something went wrong.
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.
I removed Pyodide versions < 0.27 from CI. I am fine with removing these conditions and drop backward compatibility for versions < 0.27 @hoodmane WDYT?