Skip to content

Commit 4044983

Browse files
authored
More debug logging (#142)
So many errors are swallowed because everything that triggers a ValueError is just ignored. This adds a bunch of debug logs to at least be able to debug.
1 parent 1398ea2 commit 4044983

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

micropip/install.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ async def install(
154154
pkg.name for pkg in transaction.wheels
155155
]
156156

157+
logger.debug(
158+
"Installing packages %r and wheels %r ",
159+
transaction.pyodide_packages,
160+
transaction.wheels,
161+
)
157162
if package_names:
158163
logger.info("Installing collected packages: %s", ", ".join(package_names))
159164

micropip/package_index.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import string
34
import sys
45
from collections import defaultdict
@@ -20,6 +21,8 @@
2021

2122
_formatter = string.Formatter()
2223

24+
logger = logging.getLogger("micropip")
25+
2326

2427
@dataclass
2528
class ProjectInfo:
@@ -224,7 +227,11 @@ def _select_parser(content_type: str, pkgname: str) -> Callable[[str], ProjectIn
224227
return ProjectInfo.from_simple_json_api
225228
case "application/json":
226229
return ProjectInfo.from_json_api
227-
case "application/vnd.pypi.simple.v1+html" | "text/html":
230+
case (
231+
"application/vnd.pypi.simple.v1+html"
232+
| "text/html"
233+
| "text/html; charset=utf-8"
234+
):
228235
return partial(ProjectInfo.from_simple_html_api, pkgname=pkgname)
229236
case _:
230237
raise ValueError(f"Unsupported content type: {content_type}")
@@ -264,21 +271,28 @@ async def query_package(
264271
)
265272

266273
if index_urls is None:
274+
logger.debug("index_urls is None, falling back to default, %s", INDEX_URLS)
267275
index_urls = INDEX_URLS
268276
elif isinstance(index_urls, str):
269277
index_urls = [index_urls]
270278

271279
for url in index_urls:
280+
logger.debug("Looping through index urls: %r", url)
272281
if _contain_placeholder(url):
273282
url = url.format(package_name=name)
283+
logger.debug("Formatting url with package name : %r", url)
274284
else:
275285
url = f"{url}/{name}/"
276-
286+
logger.debug("Url has no placeholder, appending package name : %r", url)
277287
try:
278288
metadata, headers = await fetch_string_and_headers(url, _fetch_kwargs)
279289
except HttpStatusError as e:
280290
if e.status_code == 404:
291+
logger.debug("NotFound (404) for %r, trying next index.", url)
281292
continue
293+
logger.debug(
294+
"Error fetching %r (%s), trying next index.", url, e.status_code
295+
)
282296
raise
283297

284298
content_type = headers.get("content-type", "").lower()

micropip/transaction.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,26 @@ def eval_marker(e: dict[str, str]) -> bool:
146146
try:
147147
if self.search_pyodide_lock_first:
148148
if self._add_requirement_from_pyodide_lock(req):
149+
logger.debug("Transaction: package found in lock file: %r", req)
149150
return
150151

151152
await self._add_requirement_from_package_index(req)
152153
else:
153154
try:
154155
await self._add_requirement_from_package_index(req)
155156
except ValueError:
157+
logger.debug(
158+
"Transaction: package %r not found in index, will search lock file",
159+
req,
160+
)
161+
156162
# If the requirement is not found in package index,
157163
# we still have a chance to find it from pyodide lockfile.
158164
if not self._add_requirement_from_pyodide_lock(req):
165+
logger.debug(
166+
"Transaction: package %r not found in lock file", req
167+
)
168+
159169
raise
160170
except ValueError:
161171
self.failed.append(req)
@@ -187,8 +197,12 @@ async def _add_requirement_from_package_index(self, req: Requirement):
187197
req.name, self.fetch_kwargs, index_urls=self.index_urls
188198
)
189199

200+
logger.debug("Transaction: got metadata %r for requirement %r", metadata, req)
201+
190202
wheel = find_wheel(metadata, req)
191203

204+
logger.debug("Transaction: Selected wheel: %r", wheel)
205+
192206
# Maybe while we were downloading pypi_json some other branch
193207
# installed the wheel?
194208
satisfied, ver = self.check_version_satisfied(req)

0 commit comments

Comments
 (0)