| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
|
||
| # detect whether the wheel metadata is from PyPI or from custom location | ||
| # wheel metadata from PyPI has SHA256 checksum digest. | ||
| wheel_source = "pypi" if wheel["digests"] is not None else wheel["url"] |
There was a problem hiding this comment.
This (checking digest) is a hacky way to detect whether the wheel is from PyPI or from a custom URL.
Another way can be adding a key that explicitly indicates the wheel is from a custom URL.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @ryanking13 , I was hoping you would be interested in doing this :)
PackageMetadata / PackageList could use some tests, or at least a few doctests.
Sorry, something went wrong.
…installation succeed
|
Applied suggestions:
|
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks! A few more minor comments below.
A more major point, is that if we want micropip to be the main API for users #1470, micropip.list should also list packages loaded via loadPackage. In particular, for a new page load in console it would currently show that no packages are installed, as far as I understand, while the following were loaded,
>>> micropip.micropip.loadedPackages.to_py()
{'distutils': 'default channel', 'micropip': 'default channel', 'pyparsing': 'default channel', 'packaging': 'default channel'}So I think we can fix this by merging both sources with something like,
def _list():
from importlib.metadata import version as get_version
packages = copy.deepcopy(self.installed_packages)
for name, pkg_source in micropip.micropip.loadedPackages.to_py().items():
if name in packages:
continue
version = get_version(name)
source = 'pyodide'
if pkg_source != 'default channel':
# Pyodide package loaded from a custom URL
source = pkg_source
packages[name] = PackageMetadata(name=name, version=version, source=source)
return packagesThough we might want to add a check in test_import here that getting the version with importlib doesn't fail.
WDYT?
Sorry, something went wrong.
| WHEEL_BASE = Path(getsitepackages()[0]) | ||
| else: | ||
| WHEEL_BASE = Path(".") / "wheels" | ||
| WHEEL_BASE = Path(tempfile.mkdtemp()) |
There was a problem hiding this comment.
Not sure about this. We don't necessarily want to create a new temp folder each time micropip is imported in a new process (outside of Pyodide), particularly given that this is only going to be used in tests. Or else we might need to clean it up afterward.
Maybe let's revert for now and open an issue about it?
Sorry, something went wrong.
There was a problem hiding this comment.
For now, testing micropip (== micropip is imported in a new process (outside of Pyodide)) generates wheels folder in the working directory.
How about renaming it to .wheels and adding it to .gitignore?
Sorry, something went wrong.
|
Also, let's add a mention to https://pyodide.org/en/stable/usage/api/js-api.html#pyodide.loadedPackages docs that this only concerns packages installed with loadPackage and that for a more general solution it is recommended to use {func}`micropip.list`
|
Sorry, something went wrong.
Totally agreed, I'll apply that, thanks! |
Sorry, something went wrong.
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Actually, pyodide.loadedPackages is updated when micropip.install is called. So there are some duplications... pyodide/packages/micropip/src/micropip/_micropip.py Lines 137 to 142 in 337847a |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks LGTM.
Sorry, something went wrong.
|
Thanks! I'll look into the pyodide.loadedPackages later. Maybe we could make it private after #1470. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Closes: #1967
Adds a new API micropip.list() which returns a list of installed packages.
Detail
>>> import micropip >>> await micropip.install("black") >>> await micropip.install("https://files.pythonhosted.org/packages/89/06/2c2d3034b4d6bf22f2a4ae546d16925898658a33b4400cfb7e2c1e2871a3/pytz-2020.5-py2.py3-none-any.whl") >>> pkgs = micropip.list() >>> print(pkgs) | Name | Version | Source | | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | regex | 2021.7.6 | pyodide | | click | 8.0.3 | pypi | | typing-extensions | 4.0.1 | pypi | | platformdirs | 2.4.0 | pypi | | pathspec | 0.9.0 | pypi | | tomli | 1.2.2 | pypi | | mypy-extensions | 0.4.3 | pypi | | black | 21.11b1 | pypi | | pytz | 2020.5 | https://files.pythonhosted.org/packages/89/06/2c2d3034b4d6bf22f2a4ae546d16925898658a33b4400cfb7e2c1e2871a3/pytz-2020.5-py2.py3-none-any.whl | >>> "regex" in pkgs True >>> "pytz" in pkgs True >>> "numpy" in pkgs FalseChecklists