From 6af0f17419308f2defcf996886358594fe756e9b Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Wed, 22 Jan 2025 11:16:50 -0500 Subject: [PATCH] chore: Add `done.` signal when package installation is completed (#195) * fix: strip extras from package req micropip.install() doesn't install extras but apparently it *acts like it does*. * feat: Add indication that installation completed It was pointed out on Discord that the current message approach makes it look like the last installation has hung * fix: micropip.install() installs extras if the main package isn't installed --- src/hooks/usePyodide.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/hooks/usePyodide.tsx b/src/hooks/usePyodide.tsx index b37734d7..869a89be 100644 --- a/src/hooks/usePyodide.tsx +++ b/src/hooks/usePyodide.tsx @@ -412,15 +412,17 @@ async def _install_requirements_from_dir(dir: str) -> None: extras.update({e.strip() for e in match_extras.group(2).split(",")}) if pkg_name not in micropip.list(): - print(f"Installing {req} ...") + req = re.sub(r"#.+$", "", req).strip() + print(f"\\nInstalling {req}...", end=" ", flush=True) await micropip.install(req) + print("done.", flush=True) if len(extras) == 0: continue else: - # Because micropip.install() doesn't install extras, we have to - # find the package requirements of each extra and install them - # if they aren't already installed. + # Because micropip.install() doesn't install extras if the primary + # package was already installed, we have to find the package + # requirements of each extra and install them manually if needed. dist = importlib.metadata.distribution(pkg_name) provided_extras = set(dist.metadata.get_all("Provides-Extra") or []) @@ -446,8 +448,9 @@ async def _install_requirements_from_dir(dir: str) -> None: for extra_req in extra_reqs: extra_req_name = re.sub(r"([a-zA-Z0-9._,-]+)(.*)", r"\\1", extra_req).strip() if extra_req_name not in micropip.list(): - print(f"Installing {extra_req_name} for {pkg_name}[{extra}]") + print(f"\\nInstalling {extra_req_name} for {pkg_name}[{extra}]...", end=" ", flush = True) await micropip.install(extra_req_name) + print("done.", flush = True) async def _load_packages_from_dir(dir: str) -> None: