Skip to content

Commit

Permalink
Merge branch 'fix_dependencies' of https://github.com/joemarshall/mic…
Browse files Browse the repository at this point in the history
…ropip into fix_dependencies
  • Loading branch information
joemarshall committed Sep 6, 2023
2 parents 8484abe + 05b43dd commit fc566b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions micropip/_commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from typing import Any

from packaging.utils import canonicalize_name
from .._utils import fix_package_dependencies


from .._compat import REPODATA_INFO, REPODATA_PACKAGES
from .._utils import fix_package_dependencies


def freeze() -> str:
Expand Down
14 changes: 7 additions & 7 deletions micropip/_utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import functools
from importlib.metadata import Distribution
import json
from importlib.metadata import Distribution
from pathlib import Path
from sysconfig import get_platform

from packaging.requirements import Requirement
from packaging.tags import Tag
from packaging.tags import sys_tags as sys_tags_orig
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name, BuildTag, InvalidWheelFilename
from packaging.utils import BuildTag, InvalidWheelFilename, canonicalize_name
from packaging.utils import parse_wheel_filename as parse_wheel_filename_orig
from packaging.version import InvalidVersion, Version

from ._compat import REPODATA_INFO, REPODATA_PACKAGES
from ._compat import REPODATA_PACKAGES


def get_dist_info(dist: Distribution) -> Path:
Expand Down Expand Up @@ -212,7 +212,7 @@ def fix_package_dependencies(package_name, *, extras=None):
dist = Distribution.from_name(package_name)

package_requires = dist.requires
if package_requires == None:
if package_requires is None:
# no dependencies - we're good to go
return

Expand Down Expand Up @@ -241,7 +241,7 @@ def fix_package_dependencies(package_name, *, extras=None):
req_marker = req.marker
req_name = canonicalize_name(req.name)
needs_requirement = False
if req_marker != None:
if req_marker is not None:
for e in extras:
if req_marker.evaluate(None if e is None else {"extra": e}):
needs_requirement = True
Expand All @@ -252,7 +252,7 @@ def fix_package_dependencies(package_name, *, extras=None):
if needs_requirement:
fix_package_dependencies(req_name, extras=list(req_extras))

if not req_name in depends:
if req_name not in depends:
depends.append(req_name)

# write updated depends to PYODIDE_DEPENDS
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _mock_importlib_from_name(name: str) -> Distribution:
for dist in dists:
if dist.name == name:
return dist
raise PackageNotFoundError(name)
raise PackageNotFoundError(name)

def _mock_importlib_version(name: str) -> str:
dists = _mock_importlib_distributions()
Expand All @@ -138,7 +138,9 @@ def _mock_importlib_distributions():
monkeypatch.setattr(
importlib.metadata, "distributions", _mock_importlib_distributions
)
monkeypatch.setattr(importlib.metadata.Distribution, "from_name", _mock_importlib_from_name)
monkeypatch.setattr(
importlib.metadata.Distribution, "from_name", _mock_importlib_from_name
)


class Wildcard:
Expand Down
11 changes: 7 additions & 4 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ async def test_freeze(mock_fetch: mock_fetch_cls, mock_importlib: None) -> None:
assert dep1_metadata["imports"] == toplevel[1]
assert dep2_metadata["imports"] == toplevel[2]


@pytest.mark.asyncio
async def test_freeze_fix_depends(mock_fetch: mock_fetch_cls, mock_importlib: None) -> None:
async def test_freeze_fix_depends(
mock_fetch: mock_fetch_cls, mock_importlib: None
) -> None:
import micropip

dummy = "dummy"
Expand All @@ -44,9 +47,9 @@ async def test_freeze_fix_depends(mock_fetch: mock_fetch_cls, mock_importlib: No
mock_fetch.add_pkg_version(dep1, top_level=toplevel[1])
mock_fetch.add_pkg_version(dep2, top_level=toplevel[2])

await micropip.install(dummy,deps = False)
await micropip.install(dep1,deps = False)
await micropip.install(dep2,deps = False)
await micropip.install(dummy, deps=False)
await micropip.install(dep1, deps=False)
await micropip.install(dep2, deps=False)

import json

Expand Down

0 comments on commit fc566b8

Please sign in to comment.