Skip to content

Commit

Permalink
Merge pull request jupyter-xeus#62 from martinRenou/update_empack_1
Browse files Browse the repository at this point in the history
Update to empack 1 with support for loading custom empack config
  • Loading branch information
martinRenou authored Aug 5, 2022
2 parents 23524d2 + eae3405 commit ad41eec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions lite/docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Then those packages are usable directly:
.. replite::
:kernel: xeus-python
:height: 600px
:prompt: Try it!

%matplotlib inline

Expand Down
28 changes: 25 additions & 3 deletions lite/jupyterlite_xeus_python/env_build_addon.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""a JupyterLite addon for creating the env for xeus-python"""
import json
import os
from pathlib import Path
import requests
import shutil
from subprocess import check_call, run, DEVNULL
from tempfile import TemporaryDirectory
import json
import shutil
from pathlib import Path
from urllib.parse import urlparse

import yaml

from traitlets import List, Unicode

from empack.file_packager import pack_environment
from empack.file_patterns import PkgFileFilter, pkg_file_filter_from_yaml

from jupyterlite.constants import (
SHARE_LABEXTENSIONS,
Expand Down Expand Up @@ -74,6 +79,12 @@ class XeusPythonEnv(FederatedExtensionAddon):
config=True, description="The xeus-python version to use"
)

empack_config = Unicode(
"https://raw.githubusercontent.com/emscripten-forge/recipes/main/empack_config.yaml",
config=True,
description="The path or URL to the empack config file",
)

packages = PackagesList([]).tag(
config=True,
description="A comma-separated list of packages to install in the xeus-python env",
Expand Down Expand Up @@ -123,11 +134,22 @@ def post_build(self, manager):
# Create emscripten env with the given packages
self.create_env()

# Download env filter config
empack_config_is_url = urlparse(self.empack_config).scheme in ("http", "https")
if empack_config_is_url:
empack_config_content = requests.get(self.empack_config).content
pkg_file_filter = PkgFileFilter.parse_obj(
yaml.safe_load(empack_config_content)
)
else:
pkg_file_filter = pkg_file_filter_from_yaml(self.empack_config)

# Pack the environment
pack_environment(
env_prefix=self.prefix_path,
outname=Path(self.cwd.name) / "python_data",
export_name="globalThis.Module",
pkg_file_filter=pkg_file_filter,
download_emsdk="latest",
)

Expand Down
2 changes: 1 addition & 1 deletion lite/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"traitlets",
"jupyterlite",
"requests",
"empack>=0.8.2,<0.9",
"empack>=1.0.0,<2",
],
zip_safe=False,
include_package_data=True,
Expand Down

0 comments on commit ad41eec

Please sign in to comment.