Skip to content

Commit cfb7483

Browse files
committed
Move errors to a separate file.
1 parent 86f40d6 commit cfb7483

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

micropip/errors.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
A module to define micropip custom Exceptions.
3+
"""
4+
5+
6+
class UnsupportedContentTypeError(Exception):
7+
"""raise when selecting a parser for current index
8+
9+
This is raise if the current content type is not recognized.
10+
"""
11+
12+
13+
class NoCompatibleWheelError(Exception):
14+
"""
15+
This is raised when a package is found but have no wheel compatible with
16+
current pyodide.
17+
"""
18+
19+
20+
class PackageNotFoundOnAnyIndexError(Exception):
21+
"""
22+
This is raised if current package was not found on any of the currently
23+
listed index.
24+
"""

micropip/package_index.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from ._compat import HttpStatusError, fetch_string_and_headers
1515
from ._utils import is_package_compatible, parse_version
16+
from .errors import PackageNotFoundOnAnyIndexError, UnsupportedContentTypeError
1617
from .externals.mousebender.simple import from_project_details_html
1718
from .wheelinfo import WheelInfo
1819

@@ -218,10 +219,6 @@ def _contain_placeholder(url: str, placeholder: str = "package_name") -> bool:
218219
return placeholder in fields
219220

220221

221-
class UnsupportedContentTypeError(Exception):
222-
pass
223-
224-
225222
def _select_parser(content_type: str, pkgname: str) -> Callable[[str], ProjectInfo]:
226223
"""
227224
Select the function to parse the response based on the content type.
@@ -243,10 +240,6 @@ def _select_parser(content_type: str, pkgname: str) -> Callable[[str], ProjectIn
243240
)
244241

245242

246-
class NoValidIndexForPackageError(Exception):
247-
pass
248-
249-
250243
async def query_package(
251244
name: str,
252245
fetch_kwargs: dict[str, Any] | None = None,
@@ -309,7 +302,7 @@ async def query_package(
309302
parser = _select_parser(content_type, name)
310303
return parser(metadata)
311304
else:
312-
raise NoValidIndexForPackageError(
305+
raise PackageNotFoundOnAnyIndexError(
313306
f"Can't fetch metadata for {name!r}. "
314307
"Please make sure you have entered a correct package name "
315308
"and correctly specified index_urls (if you changed them)."

micropip/transaction.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
from ._compat import REPODATA_PACKAGES
1414
from ._utils import best_compatible_tag_index, check_compatible
1515
from .constants import FAQ_URLS
16+
from .errors import NoCompatibleWheelError
1617
from .package import PackageMetadata
17-
from .package_index import NoValidIndexForPackageError, ProjectInfo
18+
from .package_index import PackageNotFoundOnAnyIndexError, ProjectInfo
1819
from .wheelinfo import WheelInfo
1920

2021
logger = logging.getLogger("micropip")
@@ -153,7 +154,7 @@ def eval_marker(e: dict[str, str]) -> bool:
153154
else:
154155
try:
155156
await self._add_requirement_from_package_index(req)
156-
except NoValidIndexForPackageError:
157+
except PackageNotFoundOnAnyIndexError:
157158
logger.warning(
158159
"Transaction: package %r was not found in any index, "
159160
"falling back to pyodide lock file",
@@ -178,7 +179,7 @@ def eval_marker(e: dict[str, str]) -> bool:
178179
)
179180

180181
raise
181-
except (NoCompatibleWheelError, NoValidIndexForPackageError):
182+
except (NoCompatibleWheelError, PackageNotFoundOnAnyIndexError):
182183
self.failed.append(req)
183184
if not self.keep_going:
184185
raise
@@ -263,10 +264,6 @@ async def add_wheel(
263264
self.wheels.append(wheel)
264265

265266

266-
class NoCompatibleWheelError(Exception):
267-
pass
268-
269-
270267
def find_wheel(metadata: ProjectInfo, req: Requirement) -> WheelInfo:
271268
"""Parse metadata to find the latest version of pure python wheel.
272269
Parameters

0 commit comments

Comments
 (0)