Skip to content

Commit

Permalink
Move functions into manager class
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 committed Dec 4, 2024
1 parent 91773c4 commit 5dbe22b
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: "3.11"
python: "3.12"

exclude: (^micropip/externals|^tests/vendored|^tests/test_data)
repos:
Expand Down
6 changes: 4 additions & 2 deletions micropip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
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
list = _package_manager_singleton.list_packages
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
from urllib.parse import urlparse

if TYPE_CHECKING:
Expand Down Expand Up @@ -37,14 +37,6 @@ def __init__(self, status_code: int, message: str):
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 @@ async def fetch_string_and_headers(
loadPackage = loadPackage

to_js = to_js

repodata_info = REPODATA_INFO

repodata_packages = REPODATA_PACKAGES
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 @@ -30,14 +30,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 @@ -84,3 +76,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
101 changes: 0 additions & 101 deletions micropip/install.py

This file was deleted.

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

This file was deleted.

Loading

0 comments on commit 5dbe22b

Please sign in to comment.