Skip to content

Commit

Permalink
Support use of em-forge wasm files in standalone JupyterLite deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Oct 29, 2024
1 parent c54a2e8 commit d1317ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dmypy.json
_output/
cockle_wasm_env/
cockle-config.json
.cockle_temp/
12 changes: 10 additions & 2 deletions jupyterlite_terminal/add_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def post_build(self, manager):
cockleTool = Path("node_modules") / "@jupyterlite" / "cockle" / "lib" / "tools" / "prepare_wasm.js"
cockleTool = Path("node_modules", "@jupyterlite", "cockle", "lib", "tools", "prepare_wasm.js")
if not cockleTool.is_file():
cockleTool = ".cockle_temp" / cockleTool
cmd = ["npm", "install", "--no-save", "--prefix", cockleTool.parts[0], "@jupyterlite/cockle"]
print("TerminalAddon:", " ".join(cmd))
subprocess.run(cmd, check=True)

assetDir = Path(self.manager.output_dir) / "extensions" / "@jupyterlite" / "terminal" / "static" / "wasm"

# Although cockle's prepare_wasm is perfectly capable of copying the wasm and associated
# files to the asset directory, here we just get the list of required files and let the
# add-on do the copying for consistency with other extensions.
tempFilename = 'cockle-files.txt'
subprocess.run(["node", str(cockleTool), "--list", tempFilename], check=True)
cmd = ["node", str(cockleTool), "--list", tempFilename]
print("TerminalAddon:", " ".join(cmd))
subprocess.run(cmd, check=True)

with open(tempFilename, 'r') as f:
for source in f:
Expand Down

0 comments on commit d1317ef

Please sign in to comment.