diff --git a/micropip/_compat/__init__.py b/micropip/_compat/__init__.py index 737add1..a9e0738 100644 --- a/micropip/_compat/__init__.py +++ b/micropip/_compat/__init__.py @@ -34,9 +34,6 @@ to_js = compatibility_layer.to_js -HttpStatusError = compatibility_layer.HttpStatusError - - __all__ = [ "LOCKFILE_INFO", "LOCKFILE_PACKAGES", @@ -47,5 +44,4 @@ "loadPackage", "get_dynlibs", "to_js", - "HttpStatusError", ] diff --git a/micropip/_compat/_compat_in_pyodide.py b/micropip/_compat/_compat_in_pyodide.py index 198afea..323ec2d 100644 --- a/micropip/_compat/_compat_in_pyodide.py +++ b/micropip/_compat/_compat_in_pyodide.py @@ -7,7 +7,7 @@ from pyodide._package_loader import get_dynlibs from pyodide.ffi import IN_BROWSER, to_js -from pyodide.http import HttpStatusError, pyfetch +from pyodide.http import pyfetch from .compatibility_layer import CompatibilityLayer @@ -28,14 +28,6 @@ class CompatibilityInPyodide(CompatibilityLayer): - class HttpStatusError(Exception): - status_code: int - message: str - - def __init__(self, status_code: int, message: str): - self.status_code = status_code - self.message = message - super().__init__(message) @staticmethod async def fetch_bytes(url: str, kwargs: dict[str, str]) -> bytes: @@ -51,11 +43,9 @@ async def fetch_bytes(url: str, kwargs: dict[str, str]) -> bytes: async def fetch_string_and_headers( url: str, kwargs: dict[str, str] ) -> tuple[str, dict[str, str]]: - try: - response = await pyfetch(url, **kwargs) - response.raise_for_status() - except HttpStatusError as e: - raise CompatibilityInPyodide.HttpStatusError(e.status, str(e)) from e + + response = await pyfetch(url, **kwargs) + response.raise_for_status() content = await response.string() headers: dict[str, str] = response.headers diff --git a/micropip/_compat/_compat_not_in_pyodide.py b/micropip/_compat/_compat_not_in_pyodide.py index 978c724..c7c9dd7 100644 --- a/micropip/_compat/_compat_not_in_pyodide.py +++ b/micropip/_compat/_compat_not_in_pyodide.py @@ -1,7 +1,6 @@ import re from pathlib import Path from typing import IO, TYPE_CHECKING, Any -from urllib.error import HTTPError from urllib.request import Request, urlopen from urllib.response import addinfourl @@ -17,15 +16,6 @@ class CompatibilityNotInPyodide(CompatibilityLayer): # TODO: use packaging APIs here instead? _canonicalize_regex = re.compile(r"[-_.]+") - class HttpStatusError(Exception): - status_code: int - message: str - - def __init__(self, status_code: int, message: str): - self.status_code = status_code - self.message = message - super().__init__(message) - class loadedPackages(CompatibilityLayer.loadedPackages): @staticmethod def to_py(): @@ -43,11 +33,7 @@ async def fetch_bytes(url: str, kwargs: dict[str, Any]) -> bytes: async def fetch_string_and_headers( url: str, kwargs: dict[str, Any] ) -> tuple[str, dict[str, str]]: - try: - response = CompatibilityNotInPyodide._fetch(url, kwargs=kwargs) - except HTTPError as e: - raise CompatibilityNotInPyodide.HttpStatusError(e.code, str(e)) from e - + response = CompatibilityNotInPyodide._fetch(url, kwargs=kwargs) headers = {k.lower(): v for k, v in response.headers.items()} return response.read().decode(), headers diff --git a/micropip/_compat/compatibility_layer.py b/micropip/_compat/compatibility_layer.py index dc96352..13e7705 100644 --- a/micropip/_compat/compatibility_layer.py +++ b/micropip/_compat/compatibility_layer.py @@ -13,14 +13,6 @@ class CompatibilityLayer(ABC): All of the following methods / properties must be implemented for use both inside and outside of pyodide. """ - class HttpStatusError(ABC, Exception): - status_code: int - message: str - - @abstractmethod - def __init__(self, status_code: int, message: str): - pass - class loadedPackages(ABC): @staticmethod @abstractmethod diff --git a/micropip/package_index.py b/micropip/package_index.py index 8128f06..3fa998e 100644 --- a/micropip/package_index.py +++ b/micropip/package_index.py @@ -9,7 +9,7 @@ from typing import Any from urllib.parse import urljoin, urlparse, urlunparse -from ._compat import HttpStatusError, fetch_string_and_headers +from ._compat import fetch_string_and_headers from ._utils import is_package_compatible, parse_version from ._vendored.mousebender.simple import from_project_details_html from ._vendored.packaging.src.packaging.utils import InvalidWheelFilename @@ -313,14 +313,14 @@ async def query_package( logger.debug("Url has no placeholder, appending package name : %r", url) try: metadata, headers = await fetch_string_and_headers(url, _fetch_kwargs) - except HttpStatusError as e: - if e.status_code == 404: - logger.debug("NotFound (404) for %r, trying next index.", url) - continue + except Exception as e: logger.debug( - "Error fetching %r (%s), trying next index.", url, e.status_code + "Error fetching metadata for the package %r from (%r): %r, trying next index.", + name, + url, + e, ) - raise + continue content_type = headers.get("content-type", "").lower() try: diff --git a/tests/test_compat.py b/tests/test_compat.py deleted file mode 100644 index 6a886de..0000000 --- a/tests/test_compat.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -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 pytest - - from micropip._compat import HttpStatusError, fetch_string_and_headers - - with pytest.raises(HttpStatusError): - 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)