|
| 1 | +from typing import ( # noqa: UP035 List import is necessary due to the `list` method |
| 2 | + Any, |
| 3 | + List, |
| 4 | +) |
| 5 | + |
| 6 | +from micropip import package_index |
| 7 | + |
| 8 | + |
| 9 | +class PackageManager: |
| 10 | + """ |
| 11 | + PackageManager provides an extensible interface for customizing micropip's behavior. |
| 12 | +
|
| 13 | + Each Manager instance holds its own local state that is |
| 14 | + independent of other instances. |
| 15 | +
|
| 16 | + TODO: Implement all of the following global commands to utilize local state. |
| 17 | + """ |
| 18 | + |
| 19 | + def __init__(self) -> None: |
| 20 | + self.index_urls = package_index.DEFAULT_INDEX_URLS |
| 21 | + |
| 22 | + # TODO: initialize the compatibility layer |
| 23 | + self.repodata_packages: dict[str, dict[str, Any]] = {} |
| 24 | + self.repodata_info: dict[str, str] = {} |
| 25 | + |
| 26 | + pass |
| 27 | + |
| 28 | + def install(self): |
| 29 | + raise NotImplementedError() |
| 30 | + |
| 31 | + def list(self): |
| 32 | + raise NotImplementedError() |
| 33 | + |
| 34 | + def freeze(self): |
| 35 | + raise NotImplementedError() |
| 36 | + |
| 37 | + def add_mock_package(self): |
| 38 | + raise NotImplementedError() |
| 39 | + |
| 40 | + def list_mock_packages(self): |
| 41 | + raise NotImplementedError() |
| 42 | + |
| 43 | + def remove_mock_package(self): |
| 44 | + raise NotImplementedError() |
| 45 | + |
| 46 | + def uninstall(self): |
| 47 | + raise NotImplementedError() |
| 48 | + |
| 49 | + def set_index_urls(self, urls: List[str] | str): # noqa: UP006 |
| 50 | + """ |
| 51 | + Set the index URLs to use when looking up packages. |
| 52 | +
|
| 53 | + - The index URL should support the |
| 54 | + `JSON API <https://warehouse.pypa.io/api-reference/json/>`__ . |
| 55 | +
|
| 56 | + - The index URL may contain the placeholder {package_name} which will be |
| 57 | + replaced with the package name when looking up a package. If it does not |
| 58 | + contain the placeholder, the package name will be appended to the URL. |
| 59 | +
|
| 60 | + - If a list of URLs is provided, micropip will try each URL in order until |
| 61 | + it finds a package. If no package is found, an error will be raised. |
| 62 | +
|
| 63 | + Parameters |
| 64 | + ---------- |
| 65 | + urls |
| 66 | + A list of URLs or a single URL to use as the package index. |
| 67 | + """ |
| 68 | + |
| 69 | + if isinstance(urls, str): |
| 70 | + urls = [urls] |
| 71 | + |
| 72 | + self.index_urls = urls[:] |
0 commit comments