Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Update to empack 1 with support for loading custom empack config #62

Merged
merged 1 commit into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration.rst
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 jupyterlite_xeus_python/env_build_addon.py
@@ -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 setup.py
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