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

Commit 58fc8fd

Browse files
authored
Merge pull request #46 from martinRenou/dedupe
Add a deduplication phase that make sure the latest copied labextension is used
2 parents 8d9bc60 + e8ef3d1 commit 58fc8fd

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

jupyterlite_xeus_python/env_build_addon.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
from empack.file_packager import pack_python_core
1212

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+
)
1420
from jupyterlite.addons.federated_extensions import (
1521
FederatedExtensionAddon,
1622
ENV_EXTENSIONS,
@@ -159,7 +165,16 @@ def post_build(self, manager):
159165
],
160166
)
161167

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+
)
163178

164179
def create_env(self):
165180
"""Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
@@ -255,6 +270,21 @@ def safe_copy_extension(self, pkg_json):
255270
actions=[(self.copy_one, [pkg_path, dest])],
256271
)
257272

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+
258288
def __del__(self):
259289
# Cleanup
260290
shutil.rmtree(self.root_prefix, ignore_errors=True)

0 commit comments

Comments
 (0)