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

Commit

Permalink
Merge pull request #46 from martinRenou/dedupe
Browse files Browse the repository at this point in the history
Add a deduplication phase that make sure the latest copied labextension is used
  • Loading branch information
martinRenou authored Jun 28, 2022
2 parents 8d9bc60 + e8ef3d1 commit 58fc8fd
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions jupyterlite_xeus_python/env_build_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

from empack.file_packager import pack_python_core

from jupyterlite.constants import SHARE_LABEXTENSIONS, UTF8
from jupyterlite.constants import (
SHARE_LABEXTENSIONS,
LAB_EXTENSIONS,
JUPYTERLITE_JSON,
UTF8,
FEDERATED_EXTENSIONS,
)
from jupyterlite.addons.federated_extensions import (
FederatedExtensionAddon,
ENV_EXTENSIONS,
Expand Down Expand Up @@ -159,7 +165,16 @@ def post_build(self, manager):
],
)

return super(XeusPythonEnv, self).post_build(manager)
jupyterlite_json = manager.output_dir / JUPYTERLITE_JSON
lab_extensions_root = manager.output_dir / LAB_EXTENSIONS
lab_extensions = self.env_extensions(lab_extensions_root)

yield dict(
name="patch:xeus",
doc=f"ensure {JUPYTERLITE_JSON} includes the federated_extensions",
file_dep=[*lab_extensions, jupyterlite_json],
actions=[(self.patch_jupyterlite_json, [jupyterlite_json])],
)

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

def dedupe_federated_extensions(self, config):
if FEDERATED_EXTENSIONS not in config:
return

named = {}

# Making sure to dedupe extensions by keeping the most recent ones
for ext in config[FEDERATED_EXTENSIONS]:
if os.path.exists(self.output_extensions / ext["name"] / ext["load"]):
named[ext["name"]] = ext

config[FEDERATED_EXTENSIONS] = sorted(named.values(), key=lambda x: x["name"])

print("--- CONFIG AFTER DEDUPE", config)

def __del__(self):
# Cleanup
shutil.rmtree(self.root_prefix, ignore_errors=True)
Expand Down

0 comments on commit 58fc8fd

Please sign in to comment.