Skip to content

Commit

Permalink
Move uninstall command to singleton manager (#152)
Browse files Browse the repository at this point in the history
* Move uninstall to singleton manager

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* list->List

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ryanking13 and pre-commit-ci[bot] authored Nov 3, 2024
1 parent d4847f6 commit 2fe3650
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 215 deletions.
5 changes: 1 addition & 4 deletions micropip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ._commands.uninstall import uninstall
from .package_manager import PackageManager

try:
Expand All @@ -15,9 +14,7 @@
add_mock_package = _package_manager_singleton.add_mock_package
list_mock_packages = _package_manager_singleton.list_mock_packages
remove_mock_package = _package_manager_singleton.remove_mock_package

# TODO: port uninstall
# uninstall = _package_manager_singleton.uninstall
uninstall = _package_manager_singleton.uninstall

__all__ = [
"install",
Expand Down
Empty file removed micropip/_commands/__init__.py
Empty file.
70 changes: 0 additions & 70 deletions micropip/_mock_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,69 +113,6 @@ def add_mock_package(
modules: dict[str, str | None] | None = None,
persistent: bool = False,
) -> None:
"""
Add a mock version of a package to the package dictionary.
This means that if it is a dependency, it is skipped on install.
By default a single empty module is installed with the same
name as the package. You can alternatively give one or more modules to make a
set of named modules.
The modules parameter is usually a dictionary mapping module name to module text.
.. code-block:: python
{
"mylovely_module":'''
def module_method(an_argument):
print("This becomes a module level argument")
module_value = "this value becomes a module level variable"
print("This is run on import of module")
'''
}
If you are adding the module in non-persistent mode, you can also pass functions
which are used to initialize the module on loading (as in `importlib.abc.loader.exec_module` ).
This allows you to do things like use `unittest.mock.MagicMock` classes for modules.
.. code-block:: python
def init_fn(module):
module.dict["WOO"]="hello"
print("Initing the module now!")
...
{
"mylovely_module": init_fn
}
Parameters
----------
name :
Package name to add
version :
Version of the package. This should be a semantic version string,
e.g. 1.2.3
modules :
Dictionary of module_name:string pairs.
The string contains the source of the mock module or is blank for
an empty module.
persistent :
If this is True, modules will be written to the file system, so they
persist between runs of python (assuming the file system persists).
If it is False, modules will be stored inside micropip in memory only.
"""

if modules is None:
# make a single mock module with this name
modules = {name: ""}
Expand Down Expand Up @@ -238,9 +175,6 @@ def init_fn(module):


def list_mock_packages() -> list[str]:
"""
List all mock packages currently installed.
"""
mock_packages = [
dist.name
for dist in importlib.metadata.distributions()
Expand All @@ -251,10 +185,6 @@ def list_mock_packages() -> list[str]:


def remove_mock_package(name: str) -> None:
"""
Remove a mock package.
"""

d = importlib.metadata.distribution(name)
installer = d.read_text("INSTALLER")

Expand Down
11 changes: 0 additions & 11 deletions micropip/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@
def freeze_lockfile(
lockfile_packages: dict[str, dict[str, Any]], lockfile_info: dict[str, str]
) -> str:
"""Produce a json string which can be used as the contents of the
``repodata.json`` lock file.
If you later load Pyodide with this lock file, you can use
:js:func:`pyodide.loadPackage` to load packages that were loaded with :py:mod:`micropip`
this time. Loading packages with :js:func:`~pyodide.loadPackage` is much faster
and you will always get consistent versions of all your dependencies.
You can use your custom lock file by passing an appropriate url to the
``lockFileURL`` of :js:func:`~globalThis.loadPyodide`.
"""
return json.dumps(freeze_data(lockfile_packages, lockfile_info))


Expand Down
87 changes: 0 additions & 87 deletions micropip/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,93 +22,6 @@ async def install(
*,
verbose: bool | int | None = None,
) -> None:
"""Install the given package and all of its dependencies.
If a package is not found in the Pyodide repository it will be loaded from
PyPI. Micropip can only load pure Python wheels or wasm32/emscripten wheels
built by Pyodide.
When used in web browsers, downloads from PyPI will be cached. When run in
Node.js, packages are currently not cached, and will be re-downloaded each
time ``micropip.install`` is run.
Parameters
----------
requirements :
A requirement or list of requirements to install. Each requirement is a
string, which should be either a package name or a wheel URI:
- If the requirement does not end in ``.whl``, it will be interpreted as
a package name. A package with this name must either be present
in the Pyodide lock file or on PyPI.
- If the requirement ends in ``.whl``, it is a wheel URI. The part of
the requirement after the last ``/`` must be a valid wheel name in
compliance with the `PEP 427 naming convention
<https://www.python.org/dev/peps/pep-0427/#file-format>`_.
- If a wheel URI starts with ``emfs:``, it will be interpreted as a path
in the Emscripten file system (Pyodide's file system). E.g.,
``emfs:../relative/path/wheel.whl`` or ``emfs:/absolute/path/wheel.whl``.
In this case, only .whl files are supported.
- If a wheel URI requirement starts with ``http:`` or ``https:`` it will
be interpreted as a URL.
- In node, you can access the native file system using a URI that starts
with ``file:``. In the browser this will not work.
keep_going :
This parameter decides the behavior of the micropip when it encounters a
Python package without a pure Python wheel while doing dependency
resolution:
- If ``False``, an error will be raised on first package with a missing
wheel.
- If ``True``, the micropip will keep going after the first error, and
report a list of errors at the end.
deps :
If ``True``, install dependencies specified in METADATA file for each
package. Otherwise do not install dependencies.
credentials :
This parameter specifies the value of ``credentials`` when calling the
`fetch() <https://developer.mozilla.org/en-US/docs/Web/API/fetch>`__
function which is used to download the package.
When not specified, ``fetch()`` is called without ``credentials``.
pre :
If ``True``, include pre-release and development versions. By default,
micropip only finds stable versions.
index_urls :
A list of URLs or a single URL to use as the package index when looking
up packages. If None, *https://pypi.org/pypi/{package_name}/json* is used.
- The index URL should support the
`JSON API <https://warehouse.pypa.io/api-reference/json/>`__ .
- The index URL may contain the placeholder {package_name} which will be
replaced with the package name when looking up a package. If it does not
contain the placeholder, the package name will be appended to the URL.
- If a list of URLs is provided, micropip will try each URL in order until
it finds a package. If no package is found, an error will be raised.
verbose :
Print more information about the process. By default, micropip does not
change logger level. Setting ``verbose=True`` will print similar
information as pip.
"""
with setup_logging().ctx_level(verbose) as logger:

ctx = default_environment()
Expand Down
18 changes: 0 additions & 18 deletions micropip/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@
def list_installed_packages(
lockfile_packages: dict[str, dict[str, Any]]
) -> PackageDict:
"""Get the dictionary of installed packages.
Returns
-------
``PackageDict``
A dictionary of installed packages.
>>> import micropip
>>> await micropip.install('regex') # doctest: +SKIP
>>> package_list = micropip.list()
>>> print(package_list) # doctest: +SKIP
Name | Version | Source
----------------- | -------- | -------
regex | 2021.7.6 | pyodide
>>> "regex" in package_list # doctest: +SKIP
True
"""

# Add packages that are loaded through pyodide.loadPackage
packages = PackageDict()
for dist in importlib.metadata.distributions():
Expand Down
Loading

0 comments on commit 2fe3650

Please sign in to comment.