|
1 | 1 | """a JupyterLite addon for creating the env for xeus-python""" |
| 2 | +import json |
2 | 3 | import os |
| 4 | +from pathlib import Path |
| 5 | +import requests |
| 6 | +import shutil |
3 | 7 | from subprocess import check_call, run, DEVNULL |
4 | 8 | from tempfile import TemporaryDirectory |
5 | | -import json |
6 | | -import shutil |
7 | | -from pathlib import Path |
| 9 | +from urllib.parse import urlparse |
| 10 | + |
| 11 | +import yaml |
8 | 12 |
|
9 | 13 | from traitlets import List, Unicode |
10 | 14 |
|
11 | 15 | from empack.file_packager import pack_environment |
| 16 | +from empack.file_patterns import PkgFileFilter, pkg_file_filter_from_yaml |
12 | 17 |
|
13 | 18 | from jupyterlite.constants import ( |
14 | 19 | SHARE_LABEXTENSIONS, |
@@ -74,6 +79,12 @@ class XeusPythonEnv(FederatedExtensionAddon): |
74 | 79 | config=True, description="The xeus-python version to use" |
75 | 80 | ) |
76 | 81 |
|
| 82 | + empack_config = Unicode( |
| 83 | + "https://raw.githubusercontent.com/emscripten-forge/recipes/main/empack_config.yaml", |
| 84 | + config=True, |
| 85 | + description="The path or URL to the empack config file", |
| 86 | + ) |
| 87 | + |
77 | 88 | packages = PackagesList([]).tag( |
78 | 89 | config=True, |
79 | 90 | description="A comma-separated list of packages to install in the xeus-python env", |
@@ -123,11 +134,22 @@ def post_build(self, manager): |
123 | 134 | # Create emscripten env with the given packages |
124 | 135 | self.create_env() |
125 | 136 |
|
| 137 | + # Download env filter config |
| 138 | + empack_config_is_url = urlparse(self.empack_config).scheme in ("http", "https") |
| 139 | + if empack_config_is_url: |
| 140 | + empack_config_content = requests.get(self.empack_config).content |
| 141 | + pkg_file_filter = PkgFileFilter.parse_obj( |
| 142 | + yaml.safe_load(empack_config_content) |
| 143 | + ) |
| 144 | + else: |
| 145 | + pkg_file_filter = pkg_file_filter_from_yaml(self.empack_config) |
| 146 | + |
126 | 147 | # Pack the environment |
127 | 148 | pack_environment( |
128 | 149 | env_prefix=self.prefix_path, |
129 | 150 | outname=Path(self.cwd.name) / "python_data", |
130 | 151 | export_name="globalThis.Module", |
| 152 | + pkg_file_filter=pkg_file_filter, |
131 | 153 | download_emsdk="latest", |
132 | 154 | ) |
133 | 155 |
|
|
0 commit comments