Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions micropip/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://warehouse.pypa.io/api-reference/json/>`__ .

- 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 <https://packaging.python.org/en/latest/specifications/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
Expand Down Expand Up @@ -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 <https://warehouse.pypa.io/api-reference/json/>`__ .
`Simple repository API <https://packaging.python.org/en/latest/specifications/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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 12 additions & 24 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
24 changes: 8 additions & 16 deletions tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,51 +46,43 @@ 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
pkgs = micropip.list()
assert "regex" in pkgs
assert pkgs["regex"].source.lower() == "pyodide"
`);
"""
)
""")
Loading