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

MAINT Move install, list, uninstall implementation to PackageManager #163

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions micropip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
except ImportError:
pass

_package_manager_singleton = PackageManager()
from ._compat import compatibility_layer

_package_manager_singleton = PackageManager(compatibility_layer)

install = _package_manager_singleton.install
set_index_urls = _package_manager_singleton.set_index_urls
list = _package_manager_singleton.list_packages
set_constraints = _package_manager_singleton.set_constraints
list = _package_manager_singleton.list
freeze = _package_manager_singleton.freeze
add_mock_package = _package_manager_singleton.add_mock_package
list_mock_packages = _package_manager_singleton.list_mock_packages
Expand Down
6 changes: 3 additions & 3 deletions micropip/_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .compatibility_layer import CompatibilityLayer

compatibility_layer: type[CompatibilityLayer] | None = None
compatibility_layer: type[CompatibilityLayer]

IN_BROWSER = "_pyodide_core" in sys.modules

Expand All @@ -16,9 +16,9 @@
compatibility_layer = CompatibilityNotInPyodide


REPODATA_INFO = compatibility_layer.repodata_info()
REPODATA_INFO = compatibility_layer.repodata_info

REPODATA_PACKAGES = compatibility_layer.repodata_packages()
REPODATA_PACKAGES = compatibility_layer.repodata_packages

fetch_bytes = compatibility_layer.fetch_bytes

Expand Down
14 changes: 5 additions & 9 deletions micropip/_compat/_compat_in_pyodide.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

Check warning on line 2 in micropip/_compat/_compat_in_pyodide.py

View check run for this annotation

Codecov / codecov/patch

micropip/_compat/_compat_in_pyodide.py#L2

Added line #L2 was not covered by tests
from urllib.parse import urlparse

if TYPE_CHECKING:
Expand Down Expand Up @@ -37,14 +37,6 @@
self.message = message
super().__init__(message)

@staticmethod
def repodata_info() -> dict[str, str]:
return REPODATA_INFO

@staticmethod
def repodata_packages() -> dict[str, dict[str, Any]]:
return REPODATA_PACKAGES

@staticmethod
async def fetch_bytes(url: str, kwargs: dict[str, str]) -> bytes:
parsed_url = urlparse(url)
Expand Down Expand Up @@ -79,3 +71,7 @@
loadPackage = loadPackage

to_js = to_js

repodata_info = REPODATA_INFO

Check warning on line 75 in micropip/_compat/_compat_in_pyodide.py

View check run for this annotation

Codecov / codecov/patch

micropip/_compat/_compat_in_pyodide.py#L75

Added line #L75 was not covered by tests

repodata_packages = REPODATA_PACKAGES

Check warning on line 77 in micropip/_compat/_compat_in_pyodide.py

View check run for this annotation

Codecov / codecov/patch

micropip/_compat/_compat_in_pyodide.py#L77

Added line #L77 was not covered by tests
12 changes: 4 additions & 8 deletions micropip/_compat/_compat_not_in_pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ class loadedPackages(CompatibilityLayer.loadedPackages):
def to_py():
return {}

@staticmethod
def repodata_info() -> dict[str, str]:
return {}

@staticmethod
def repodata_packages() -> dict[str, dict[str, Any]]:
return {}

@staticmethod
def _fetch(url: str, kwargs: dict[str, Any]) -> addinfourl:
return urlopen(Request(url, **kwargs))
Expand Down Expand Up @@ -85,3 +77,7 @@ def to_js(
default_converter=None,
) -> Any:
return obj

repodata_info = {}

repodata_packages = {}
16 changes: 5 additions & 11 deletions micropip/_compat/compatibility_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ class loadedPackages(ABC):
def to_py():
pass

@staticmethod
@abstractmethod
def repodata_info() -> dict[str, str]:
pass
repodata_info: dict[str, str]

@staticmethod
@abstractmethod
def repodata_packages() -> dict[str, dict[str, Any]]:
pass
repodata_packages: dict[str, dict[str, Any]]

@staticmethod
@abstractmethod
Expand Down Expand Up @@ -73,9 +67,9 @@ def to_js(
/,
*,
depth: int = -1,
pyproxies: Any,
pyproxies: Any = None,
create_pyproxies: bool = True,
dict_converter: Any,
default_converter: Any,
dict_converter: Any = None,
default_converter: Any = None,
) -> Any:
pass
92 changes: 0 additions & 92 deletions micropip/install.py

This file was deleted.

43 changes: 0 additions & 43 deletions micropip/list.py

This file was deleted.

Loading