Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarshall committed Oct 13, 2023
1 parent ba8ac4c commit 20f0f79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
11 changes: 7 additions & 4 deletions pyodide_lock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ def add_wheels_to_spec(
base_path: Path | None = None,
base_url: str = "",
ignore_missing_dependencies: bool = False,
) -> None:
"""Add a list of wheel files to this pyodide-lock.json
) -> PyodideLockSpec:
"""Add a list of wheel files to this pyodide-lock.json and return a
new PyodideLockSpec
Parameters:
wheel_files : list[Path]
Expand All @@ -177,8 +178,9 @@ def add_wheels_to_spec(
not 100% reliable, because it ignores any extras and does not do any
sub-dependency or version resolution.
"""
new_spec = lock_spec.copy(deep=True)
if not wheel_files:
return
return new_spec
wheel_files = [f.resolve() for f in wheel_files]
if base_path is None:
base_path = wheel_files[0].parent
Expand All @@ -193,7 +195,8 @@ def add_wheels_to_spec(

_fix_new_package_deps(lock_spec, new_packages, ignore_missing_dependencies)
_set_package_paths(new_packages, base_path, base_url)
lock_spec.packages |= new_packages
new_spec.packages |= new_packages
return new_spec


def _fix_new_package_deps(
Expand Down
29 changes: 16 additions & 13 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@


def test_add_one(test_wheel_list, example_lock_spec):
add_wheels_to_spec(example_lock_spec, test_wheel_list[0:1])
# py_one only should get added
assert example_lock_spec.packages["py-one"].imports == ["one"]
new_lock_spec = add_wheels_to_spec(example_lock_spec, test_wheel_list[0:1])
# py_one only should get added to the new spec
assert new_lock_spec.packages["py-one"].imports == ["one"]
assert "py-one" not in example_lock_spec.packages


def test_add_simple_deps(test_wheel_list, example_lock_spec):
add_wheels_to_spec(example_lock_spec, test_wheel_list[0:3])
example_lock_spec = add_wheels_to_spec(example_lock_spec, test_wheel_list[0:3])
# py_one, needs_one and needs_one_opt should get added
assert "py-one" in example_lock_spec.packages
assert "needs-one" in example_lock_spec.packages
Expand All @@ -37,7 +38,7 @@ def test_add_simple_deps(test_wheel_list, example_lock_spec):


def test_add_deps_with_extras(test_wheel_list, example_lock_spec):
add_wheels_to_spec(example_lock_spec, test_wheel_list[0:4])
example_lock_spec = add_wheels_to_spec(example_lock_spec, test_wheel_list[0:4])
# py_one, needs_one, needs_one_opt and test_extra_dependencies should get added
# because of the extra dependency in test_extra_dependencies,
# needs_one_opt should now depend on one
Expand All @@ -48,11 +49,11 @@ def test_add_deps_with_extras(test_wheel_list, example_lock_spec):
def test_missing_dep(test_wheel_list, example_lock_spec):
# this has a package with a missing dependency so should fail
with pytest.raises(RuntimeError):
add_wheels_to_spec(example_lock_spec, test_wheel_list[0:5])
example_lock_spec = add_wheels_to_spec(example_lock_spec, test_wheel_list[0:5])


def test_url_rewriting(test_wheel_list, example_lock_spec):
add_wheels_to_spec(
example_lock_spec = add_wheels_to_spec(
example_lock_spec, test_wheel_list[0:3], base_url="http://www.nowhere.org/"
)
# py_one, needs_one and needs_one_opt should get added
Expand All @@ -67,7 +68,7 @@ def test_url_rewriting(test_wheel_list, example_lock_spec):
def test_base_relative_path(test_wheel_list, example_lock_spec):
# this should make all the file names relative to the
# parent path of the wheels (which is "dist")
add_wheels_to_spec(
example_lock_spec = add_wheels_to_spec(
example_lock_spec,
test_wheel_list[0:3],
base_url="http://www.nowhere.org/",
Expand All @@ -84,14 +85,14 @@ def test_base_relative_path(test_wheel_list, example_lock_spec):

# all requirements markers should not be needed, so dependencies should be empty
def test_markers_not_needed(test_wheel_list, example_lock_spec):
add_wheels_to_spec(example_lock_spec, test_wheel_list[5:6])
example_lock_spec = add_wheels_to_spec(example_lock_spec, test_wheel_list[5:6])
assert example_lock_spec.packages["markers-not-needed-test"].depends == []


# all requirements markers should be needed,
# so returned dependencies should be the same length as marker_examples_needed
def test_markers_needed(test_wheel_list, example_lock_spec, marker_examples_needed):
add_wheels_to_spec(
example_lock_spec = add_wheels_to_spec(
example_lock_spec, test_wheel_list[6:7], ignore_missing_dependencies=True
)
assert len(example_lock_spec.packages["markers-needed-test"].depends) == len(
Expand All @@ -102,7 +103,9 @@ def test_markers_needed(test_wheel_list, example_lock_spec, marker_examples_need
@pytest.mark.skipif(WHEEL is None, reason="wheel test requires a built wheel")
def test_self_wheel(example_lock_spec):
assert WHEEL is not None
add_wheels_to_spec(example_lock_spec, [WHEEL], ignore_missing_dependencies=True)
example_lock_spec = add_wheels_to_spec(
example_lock_spec, [WHEEL], ignore_missing_dependencies=True
)

expected = PackageSpec(
name="pyodide-lock",
Expand All @@ -126,7 +129,7 @@ def test_not_wheel(tmp_path, example_lock_spec):
whlzip.writestr("README.md", data="Not a wheel")

with pytest.raises(RuntimeError, match="metadata"):
add_wheels_to_spec(example_lock_spec, [wheel])
example_lock_spec = add_wheels_to_spec(example_lock_spec, [wheel])


@pytest.mark.parametrize(
Expand All @@ -141,7 +144,7 @@ def test_bad_names(tmp_path, bad_name, example_lock_spec):
with zipfile.ZipFile(wheel, "w") as whlzip:
whlzip.writestr("README.md", data="Not a wheel")
with pytest.raises(RuntimeError, match="Wheel filename"):
add_wheels_to_spec(example_lock_spec, [wheel])
example_lock_spec = add_wheels_to_spec(example_lock_spec, [wheel])


def test_wheel_compatibility_checking(example_lock_spec):
Expand Down

0 comments on commit 20f0f79

Please sign in to comment.