diff --git a/micropip/package_manager.py b/micropip/package_manager.py index 602c7fe..cb29d03 100644 --- a/micropip/package_manager.py +++ b/micropip/package_manager.py @@ -120,18 +120,16 @@ async def install( index_urls: A list of URLs or a single URL to use as the package index when looking - up packages. If None, *https://pypi.org/pypi/{package_name}/json* is used. + up packages. If None, *https://pypi.org/simple* is used. - The index URL should support the \ - `JSON API `__ . - - - The index URL may contain the placeholder {package_name} which will be \ - replaced with the package name when looking up a package. If it does not \ - contain the placeholder, the package name will be appended to the URL. + `Simple repository API `__ . - If a list of URLs is provided, micropip will try each URL in order until \ it finds a package. If no package is found, an error will be raised. + - The index URL must support CORS when used in a web browser. + constraints: A list of requirements with versions/URLs which will be used only if @@ -462,7 +460,7 @@ def set_index_urls(self, urls: List[str] | str): # noqa: UP006 Set the index URLs to use when looking up packages. - The index URL should support the - `JSON API `__ . + `Simple repository API `__ . - The index URL may contain the placeholder {package_name} which will be replaced with the package name when looking up a package. If it does not @@ -471,6 +469,8 @@ def set_index_urls(self, urls: List[str] | str): # noqa: UP006 - If a list of URLs is provided, micropip will try each URL in order until it finds a package. If no package is found, an error will be raised. + - The index URL must support CORS when used in a web browser. + Parameters ---------- urls diff --git a/tests/conftest.py b/tests/conftest.py index d09338a..d3d199b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -94,12 +94,10 @@ def selenium_standalone_micropip(selenium_standalone, wheel_path): with httpserver: url = httpserver.url_for(f"/{wheel_file.name}") - selenium_standalone.run_js( - f""" + selenium_standalone.run_js(f""" await pyodide.loadPackage("{url}"); pyodide.runPython("import micropip"); - """ - ) + """) yield selenium_standalone diff --git a/tests/test_freeze.py b/tests/test_freeze.py index 3a18655..3ff1176 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -83,12 +83,10 @@ def test_freeze_lockfile_compat( wheel = wheel_catalog.get(name) url = wheel.url - lockfile_content = selenium.run_async( - f""" + lockfile_content = selenium.run_async(f""" await micropip.install("{url}") micropip.freeze() - """ - ) + """) lockfile_path = tmp_path / "lockfile.json" with open(lockfile_path, "w") as f: diff --git a/tests/test_install.py b/tests/test_install.py index 0eb07e4..e174875 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -29,74 +29,62 @@ def test_install_file_protocol_node(selenium_standalone_micropip, request): DIST_PATH = request.config.option.dist_dir pyparsing_wheel_name = list(DIST_PATH.glob("pyparsing*.whl"))[0].name - selenium.run_js( - f""" + selenium.run_js(f""" await pyodide.runPythonAsync(` import micropip await micropip.install('file:{pyparsing_wheel_name}') import pyparsing `); - """ - ) + """) def test_install_different_version(selenium_standalone_micropip): selenium = selenium_standalone_micropip - selenium.run_js( - """ + selenium.run_js(""" await pyodide.runPythonAsync(` import micropip await micropip.install( "https://files.pythonhosted.org/packages/89/06/2c2d3034b4d6bf22f2a4ae546d16925898658a33b4400cfb7e2c1e2871a3/pytz-2020.5-py2.py3-none-any.whl" ); `); - """ - ) - selenium.run_js( - """ + """) + selenium.run_js(""" await pyodide.runPythonAsync(` import pytz assert pytz.__version__ == "2020.5" `); - """ - ) + """) def test_install_different_version2(selenium_standalone_micropip): selenium = selenium_standalone_micropip - selenium.run_js( - """ + selenium.run_js(""" await pyodide.runPythonAsync(` import micropip await micropip.install( "pytz == 2020.5" ); `); - """ - ) - selenium.run_js( - """ + """) + selenium.run_js(""" await pyodide.runPythonAsync(` import pytz assert pytz.__version__ == "2020.5" `); - """ - ) + """) @pytest.mark.parametrize("jinja2", ["jinja2", "Jinja2"]) def test_install_mixed_case2(selenium_standalone_micropip, jinja2): selenium = selenium_standalone_micropip - selenium.run_js( - f""" + selenium.run_js(f""" await pyodide.loadPackage("micropip"); await pyodide.runPythonAsync(` import micropip await micropip.install("{jinja2}") import jinja2 `); - """ - ) + """) @pytest.mark.parametrize("set_constraints", [False, True]) diff --git a/tests/test_list.py b/tests/test_list.py index d229b9f..3464cf6 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -46,45 +46,38 @@ def test_list_load_package_from_url(selenium_standalone_micropip, wheel_catalog) url = snowball_wheel.url selenium = selenium_standalone_micropip - selenium.run_js( - f""" + selenium.run_js(f""" await pyodide.loadPackage({url!r}); await pyodide.runPythonAsync(` import micropip assert "snowballstemmer" in micropip.list() `); - """ - ) + """) def test_list_pyodide_package(selenium_standalone_micropip): selenium = selenium_standalone_micropip - selenium.run_js( - """ + selenium.run_js(""" await pyodide.runPythonAsync(` import micropip await micropip.install( "regex" ); `); - """ - ) - selenium.run_js( - """ + """) + selenium.run_js(""" await pyodide.runPythonAsync(` import micropip pkgs = micropip.list() assert "regex" in pkgs assert pkgs["regex"].source.lower() == "pyodide" `); - """ - ) + """) def test_list_loaded_from_js(selenium_standalone_micropip): selenium = selenium_standalone_micropip - selenium.run_js( - """ + selenium.run_js(""" await pyodide.loadPackage("regex"); await pyodide.runPythonAsync(` import micropip @@ -92,5 +85,4 @@ def test_list_loaded_from_js(selenium_standalone_micropip): assert "regex" in pkgs assert pkgs["regex"].source.lower() == "pyodide" `); - """ - ) + """)