Commit 0d179278 authored by Romain Casati's avatar Romain Casati
Browse files

Simplification of packages API + allowing to add dependencies to Pyodide packages.

parent 7fb9c34e
......@@ -31,7 +31,7 @@ _internal_modules_path = js.Basthon.basthonModulesRoot()
# Packages not implemented in Pyodide but in Basthon (internal)
# (dict pointing to Pypi or internal addresse).
_internal_pkgs = {
_internal_pkgs_dict = {
"turtle": {
"path": f"{_internal_modules_path}/turtle-0.0.1-py3-none-any.whl",
},
......@@ -62,8 +62,12 @@ _internal_pkgs = {
},
}
# checking that 'path' is in dict allows to add dependencies to pyodide packages
# (see _ivp/scipy)
_internal_pkgs = set(k for k, v in _internal_pkgs_dict.items() if 'path' in v)
# Union of internal and pyodide packages.
_all_pkgs = _pyodide_pkgs | set(_internal_pkgs.keys())
_all_pkgs = _pyodide_pkgs | _internal_pkgs
# Packages already loaded.
_loaded = set()
......@@ -90,7 +94,7 @@ def _load_internal(packages):
return js.Promise.resolve()
def micropip_wrapper(*args):
return micropip_install([_internal_pkgs[p]['path']
return micropip_install([_internal_pkgs_dict[p]['path']
for p in packages])
return _load_pyodide('micropip').then(micropip_wrapper)
......@@ -99,7 +103,7 @@ def _load_internal(packages):
def _internal_dependencies(packages):
""" Return the set of dependencies of a list of internal packages. """
def dependencies(package):
deps = set(_internal_pkgs.get(package, {}).get("deps", []))
deps = set(_internal_pkgs_dict.get(package, {}).get("deps", []))
return deps.union(*(dependencies(p) for p in deps))
packages = set(packages)
......@@ -119,7 +123,7 @@ def load_and_hack(packages):
packages = packages | _internal_dependencies(packages)
pyodide_packages = packages & _pyodide_pkgs
internal_packages = packages & set(_internal_pkgs.keys())
internal_packages = packages & _internal_pkgs
def callback(*args):
if packages:
......
......@@ -13,7 +13,7 @@ def test_all(selenium):
if g.startswith('test_') and g != 'test_all')
result = selenium.run_basthon("""
from basthon import packages
set(packages._internal_pkgs.keys())""")['result']
packages._internal_pkgs""")['result']
internal = eval(result['result']['text/plain'])
assert tested == internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment