Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clobber pyodide packages with pip packages in freeze #172

Merged
merged 12 commits into from
Jan 13, 2025
8 changes: 3 additions & 5 deletions micropip/freeze.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import importlib.metadata
import itertools
import json
from collections.abc import Iterator
from copy import deepcopy
Expand All @@ -19,12 +18,11 @@ def freeze_lockfile(
def freeze_data(
lockfile_packages: dict[str, dict[str, Any]], lockfile_info: dict[str, str]
) -> dict[str, Any]:
pyodide_packages = deepcopy(lockfile_packages)
pip_packages = load_pip_packages()
package_items = itertools.chain(pyodide_packages.items(), pip_packages)
packages = deepcopy(lockfile_packages)
packages.update(load_pip_packages())

# Sort
packages = dict(sorted(package_items))
packages = dict(sorted(packages.items()))
return {
"info": lockfile_info,
"packages": packages,
Expand Down
30 changes: 20 additions & 10 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ async def test_freeze_fix_depends(
assert dep2_metadata["imports"] == toplevel[2]


def test_freeze_lockfile_compat(selenium_standalone_micropip, wheel_catalog, tmp_path):
@pytest.mark.parametrize(
("name", "depends"),
[
["pytest", {"attrs", "iniconfig", "packaging", "pluggy"}],
["snowballstemmer", set()],
],
)
def test_freeze_lockfile_compat(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name, depends, selenium_standalone_micropip, wheel_catalog, tmp_path
):
from pyodide_lock import PyodideLockSpec

selenium = selenium_standalone_micropip
snowball_wheel = wheel_catalog.get("snowballstemmer")
url = snowball_wheel.url
wheel = wheel_catalog.get(name)
url = wheel.url

lockfile_content = selenium.run_async(
f"""
Expand All @@ -85,10 +94,11 @@ def test_freeze_lockfile_compat(selenium_standalone_micropip, wheel_catalog, tmp
f.write(lockfile_content)

lockfile = PyodideLockSpec.from_json(lockfile_path)
assert lockfile.packages["snowballstemmer"].file_name == url
assert lockfile.packages["snowballstemmer"].name == "snowballstemmer"
assert lockfile.packages["snowballstemmer"].depends == []
assert lockfile.packages["snowballstemmer"].imports == ["snowballstemmer"]
assert lockfile.packages["snowballstemmer"].install_dir == "site"
assert not lockfile.packages["snowballstemmer"].unvendored_tests
assert lockfile.packages["snowballstemmer"].version == snowball_wheel.version
package = lockfile.packages[name]
assert package.file_name == url
assert package.name == name
assert set(package.depends) == depends
assert name in package.imports
assert package.install_dir == "site"
assert not package.unvendored_tests
assert package.version == wheel.version
Loading