|
10 | 10 |
|
11 | 11 | from empack.file_packager import pack_python_core
|
12 | 12 |
|
13 |
| -from jupyterlite.constants import SHARE_LABEXTENSIONS, UTF8 |
| 13 | +from jupyterlite.constants import ( |
| 14 | + SHARE_LABEXTENSIONS, |
| 15 | + LAB_EXTENSIONS, |
| 16 | + JUPYTERLITE_JSON, |
| 17 | + UTF8, |
| 18 | + FEDERATED_EXTENSIONS, |
| 19 | +) |
14 | 20 | from jupyterlite.addons.federated_extensions import (
|
15 | 21 | FederatedExtensionAddon,
|
16 | 22 | ENV_EXTENSIONS,
|
@@ -159,7 +165,16 @@ def post_build(self, manager):
|
159 | 165 | ],
|
160 | 166 | )
|
161 | 167 |
|
162 |
| - return super(XeusPythonEnv, self).post_build(manager) |
| 168 | + jupyterlite_json = manager.output_dir / JUPYTERLITE_JSON |
| 169 | + lab_extensions_root = manager.output_dir / LAB_EXTENSIONS |
| 170 | + lab_extensions = self.env_extensions(lab_extensions_root) |
| 171 | + |
| 172 | + yield dict( |
| 173 | + name="patch:xeus", |
| 174 | + doc=f"ensure {JUPYTERLITE_JSON} includes the federated_extensions", |
| 175 | + file_dep=[*lab_extensions, jupyterlite_json], |
| 176 | + actions=[(self.patch_jupyterlite_json, [jupyterlite_json])], |
| 177 | + ) |
163 | 178 |
|
164 | 179 | def create_env(self):
|
165 | 180 | """Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
|
@@ -255,6 +270,21 @@ def safe_copy_extension(self, pkg_json):
|
255 | 270 | actions=[(self.copy_one, [pkg_path, dest])],
|
256 | 271 | )
|
257 | 272 |
|
| 273 | + def dedupe_federated_extensions(self, config): |
| 274 | + if FEDERATED_EXTENSIONS not in config: |
| 275 | + return |
| 276 | + |
| 277 | + named = {} |
| 278 | + |
| 279 | + # Making sure to dedupe extensions by keeping the most recent ones |
| 280 | + for ext in config[FEDERATED_EXTENSIONS]: |
| 281 | + if os.path.exists(self.output_extensions / ext["name"] / ext["load"]): |
| 282 | + named[ext["name"]] = ext |
| 283 | + |
| 284 | + config[FEDERATED_EXTENSIONS] = sorted(named.values(), key=lambda x: x["name"]) |
| 285 | + |
| 286 | + print("--- CONFIG AFTER DEDUPE", config) |
| 287 | + |
258 | 288 | def __del__(self):
|
259 | 289 | # Cleanup
|
260 | 290 | shutil.rmtree(self.root_prefix, ignore_errors=True)
|
|
0 commit comments