From bf024c98e0806e4cfdb5b2eb755f17619dcf726b Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Mon, 27 Sep 2021 03:24:23 +0900 Subject: [PATCH] Raise error when trying to install a non-pure python wheel (#1859) --- docs/project/changelog.md | 5 +++++ packages/micropip/src/micropip/micropip.py | 9 ++++++++- packages/micropip/test_micropip.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/project/changelog.md b/docs/project/changelog.md index d4ec3500d..a3d12a6f3 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -48,6 +48,11 @@ substitutions: - {{ Enhancement }} Better support for ccache when building Pyodide {pr}`1805` +### micropip + +- {{Fix}} micropip now raises error when installing non-pure python wheel directly from url. + {pr}`1859` + ### packages - {{ Enhancement }} Unit tests are now unvendored from Python packages and diff --git a/packages/micropip/src/micropip/micropip.py b/packages/micropip/src/micropip/micropip.py index 361d5e952..f66ad7e97 100644 --- a/packages/micropip/src/micropip/micropip.py +++ b/packages/micropip/src/micropip/micropip.py @@ -92,6 +92,10 @@ async def _get_pypi_json(pkgname): return json.load(fd) +def _is_pure_python_wheel(filename: str): + return filename.endswith("py3-none-any.whl") + + def _parse_wheel_url(url: str) -> Tuple[str, Dict[str, Any], str]: """Parse wheels URL and extract available metadata @@ -205,6 +209,9 @@ class _PackageManager: # custom download location name, wheel, version = _parse_wheel_url(requirement) name = name.lower() + if not _is_pure_python_wheel(wheel["filename"]): + raise ValueError(f"'{wheel['filename']}' is not a pure Python 3 wheel") + await self.add_wheel(name, wheel, version, (), ctx, transaction) return else: @@ -264,7 +271,7 @@ class _PackageManager: for ver in candidate_versions: release = releases[str(ver)] for fileinfo in release: - if fileinfo["filename"].endswith("py3-none-any.whl"): + if _is_pure_python_wheel(fileinfo["filename"]): return fileinfo, ver raise ValueError(f"Couldn't find a pure Python 3 wheel for '{req}'") diff --git a/packages/micropip/test_micropip.py b/packages/micropip/test_micropip.py index 61c508191..10d60d53b 100644 --- a/packages/micropip/test_micropip.py +++ b/packages/micropip/test_micropip.py @@ -166,6 +166,19 @@ def test_last_version_from_pypi(): assert str(ver) == "0.15.5" +def test_install_non_pure_python_wheel(): + pytest.importorskip("packaging") + from micropip import micropip + + msg = "not a pure Python 3 wheel" + with pytest.raises(ValueError, match=msg): + url = "http://scikit_learn-0.22.2.post1-cp35-cp35m-macosx_10_9_intel.whl" + transaction = {"wheels": [], "locked": {}} + asyncio.get_event_loop().run_until_complete( + micropip.PACKAGE_MANAGER.add_requirement(url, {}, transaction) + ) + + def test_install_different_version(selenium_standalone_micropip): selenium = selenium_standalone_micropip selenium.run_js(