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

Commit 7b33a62

Browse files
New emscripten + Fix CI (#108)
* changes for new emscripten * cleanup * cleanup * cleanup * cleanup * Put back what has been removed * Put back filter * Update empack in build env * CI split build * Empack 2.0.6 * Bump empack * Bump empack * Use mamba * Stupid conda * Syntax error * Missing eslint ignore entries * More updates * Verbose build * Try * Empack 2.0.8 * Install empack from conda again --------- Co-authored-by: DerThorsten <derthorstenbeier@gmail.com>
1 parent 0cad1ad commit 7b33a62

File tree

12 files changed

+63
-60
lines changed

12 files changed

+63
-60
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ dist
33
coverage
44
**/*.d.ts
55
tests
6+
src/worker.ts
7+
src/web_worker_kernel.ts

.github/workflows/build.yml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,25 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v2
19-
- name: Install node
20-
uses: actions/setup-node@v1
21-
with:
22-
node-version: '14.x'
23-
- name: Install Python
24-
uses: actions/setup-python@v2
25-
with:
26-
python-version: '3.8'
27-
architecture: 'x64'
2819

29-
- name: Setup pip cache
30-
uses: actions/cache@v2
31-
with:
32-
path: ~/.cache/pip
33-
key: pip-3.8-${{ hashFiles('package.json') }}
34-
restore-keys: |
35-
pip-3.8-
36-
pip-
37-
38-
- name: Get yarn cache directory path
39-
id: yarn-cache-dir-path
40-
run: echo "::set-output name=dir::$(yarn cache dir)"
41-
- name: Setup yarn cache
42-
uses: actions/cache@v2
43-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
20+
- name: Install Conda environment with Micromamba
21+
uses: mamba-org/provision-with-micromamba@main
4422
with:
45-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
46-
key: yarn-${{ hashFiles('**/yarn.lock') }}
47-
restore-keys: |
48-
yarn-
49-
50-
- name: Install dependencies
51-
run: python -m pip install -U jupyterlab~=3.1 check-manifest typer empack
23+
environment-name: xeus-python-kernel
24+
environment-file: environment.yml
5225

53-
- name: Build the extension
26+
- name: Dev install
5427
run: |
5528
set -eux
5629
jlpm
5730
jlpm run build
5831
jlpm run eslint:check
59-
python -m pip install .
32+
python -m pip install -v .
6033
6134
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/xeus-python-kernel.*OK"
6235
63-
# TODO: add JupyterLite browser check
64-
# python -m jupyterlab.browser_check
65-
36+
- name: Build the extension
37+
run: |
6638
pip install build
6739
python -m build --sdist
6840
cp dist/*.tar.gz jupyterlite-xeus-python.tar.gz
@@ -120,7 +92,9 @@ jobs:
12092
activate-environment: xeus-python-kernel
12193
environment-file: environment.yml
12294
python-version: '3.10'
123-
mamba-version: '*'
95+
96+
- name: Install mamba
97+
run: conda install -c conda-forge mamba
12498

12599
- name: Make sure the Mamba Python API is available
126100
run: |
@@ -152,7 +126,9 @@ jobs:
152126
activate-environment: xeus-python-kernel
153127
environment-file: environment.yml
154128
python-version: '3.10'
155-
mamba-version: '*'
129+
130+
- name: Install mamba
131+
run: conda install -c conda-forge mamba
156132

157133
- name: Install
158134
run: pip install jupyterlite-xeus-python.tar.gz

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ _output
114114
*.doit.db
115115

116116
python_data.js
117-
python_data.data
117+
*.data
118+
src/*.js
118119
xpython_wasm.js
119120
xpython_wasm.wasm
120121
xpython_wasm.hash

docs/build-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- pydata-sphinx-theme
1212
- yarn
1313
- jupyterlab
14-
- empack>=2.0.3
14+
- empack >=2.0.8,<3
1515
- pip:
1616
- jupyterlite==0.1.0b17
1717
- jupyterlite-sphinx

environment.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ channels:
44
dependencies:
55
- python
66
- pip
7+
- jupyterlab
78
- traitlets
89
- requests
910
- typer
1011
- pytest
1112
- emsdk >=3.1.11
12-
- empack >=2.0.2
13+
- empack >=2.0.8,<3
1314
- pip:
14-
- jupyterlite
15+
- jupyterlite

jupyterlite_xeus_python/build.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import yaml
1111

12-
from empack.file_packager import pack_environment
12+
from empack.file_packager import split_pack_environment
1313
from empack.file_patterns import PkgFileFilter, pkg_file_filter_from_yaml
1414

1515
import typer
@@ -206,10 +206,12 @@ def build_and_pack_emscripten_env(
206206
)
207207

208208
# Pack the environment
209-
pack_environment(
209+
split_pack_environment(
210210
env_prefix=prefix_path,
211-
outname=Path(output_path) / "python_data",
211+
outname="python_data",
212+
pack_outdir=output_path,
212213
export_name="globalThis.Module",
214+
with_export_default_statement=False,
213215
**pack_kwargs,
214216
)
215217

@@ -230,9 +232,14 @@ def build_and_pack_emscripten_env(
230232

231233
worker = worker.replace("XEUS_KERNEL_FILE", "'xpython_wasm.js'")
232234
worker = worker.replace("LANGUAGE_DATA_FILE", "'python_data.js'")
233-
235+
worker = worker.replace("importScripts(DATA_FILE);", """
236+
importScripts(DATA_FILE);
237+
await globalThis.Module.importPackages();
238+
await globalThis.Module.init();
239+
""" )
234240
with open(Path(output_path) / "worker.ts", "w") as fobj:
235241
fobj.write(worker)
242+
236243
except Exception as e:
237244
raise e
238245
finally:

jupyterlite_xeus_python/env_build_addon.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,27 @@ def post_build(self, manager):
9393
# We should really find a nicer way.
9494
# (make jupyterlite-xeus-python extension somewhat configurable?)
9595
dest = self.output_extensions / "@jupyterlite" / "xeus-python-kernel" / "static"
96+
97+
# copy *.data/*.js for all side packages
98+
for item in Path(self.cwd.name) .iterdir():
99+
if item.suffix == ".data":
100+
101+
file = item.name
102+
yield dict(
103+
name=f"xeus:copy:{file}",
104+
actions=[(self.copy_one, [item, dest / file])],
105+
)
106+
107+
js_item = Path(self.cwd.name) / (str(item.stem) + '.js')
108+
js_file = js_item.name
109+
yield dict(
110+
name=f"xeus:copy:{js_file}",
111+
actions=[(self.copy_one, [js_item, dest / js_file])],
112+
)
113+
96114

97115
for file in [
98116
"python_data.js",
99-
"python_data.data",
100117
"xpython_wasm.js",
101118
"xpython_wasm.wasm",
102119
]:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"url": "https://github.com/jupyterlite/xeus-python-kernel.git"
2727
},
2828
"scripts": {
29-
"copy-files": "copyfiles -u 1 src/xpython_wasm.wasm src/xpython_wasm.js src/python_data.js src/python_data.data lib",
29+
"copy-files": "copyfiles -u 1 src/xpython_wasm.wasm src/xpython_wasm.js src/python_data.js src/*.data src/*.js lib",
3030
"build:worker": "webpack --config worker.webpack.config.js --mode=development",
3131
"build": "jlpm run build:xeus-python && jlpm run build:lib && jlpm run build:worker && jlpm run copy-files && jlpm run build:labextension:dev",
3232
"build:xeus-python": "python jupyterlite_xeus_python/build.py --output-path src --build-worker",

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1", "empack"]
2+
requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1", "empack>=2.0.8,<3"]
33
build-backend = "jupyter_packaging.build_api"
44

55
[tool.jupyter-packaging.options]
@@ -14,4 +14,4 @@ build_cmd = "build:prod"
1414
npm = ["jlpm"]
1515

1616
[tool.check-manifest]
17-
ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "yarn.lock", ".*", "package-lock.json", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "src/worker.ts", "src/web_worker_kernel.ts", "*.sh"]
17+
ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "yarn.lock", ".*", "package-lock.json", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/*.data", "src/*.js", "src/worker.ts", "src/web_worker_kernel.ts", "*.sh"]

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
ensured_targets = [
2121
str(lab_path / "package.json"),
2222
str(lab_path / "static" / "python_data.js"),
23-
str(lab_path / "static" / "python_data.data"),
2423
str(lab_path / "static" / "xpython_wasm.js"),
2524
str(lab_path / "static" / "xpython_wasm.wasm"),
2625
str(lab_path / "static" / "style.js"),
@@ -62,7 +61,7 @@
6261
"traitlets",
6362
"jupyterlite",
6463
"requests",
65-
"empack>=2.0.2,<3",
64+
"empack>=2.0.8,<3",
6665
"typer",
6766
],
6867
zip_safe=False,

tests/test_xeus_python_env.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ def test_python_env():
2828

2929
# Check empack output
3030
assert os.path.isfile(Path(addon.cwd.name) / "python_data.js")
31-
assert os.path.isfile(Path(addon.cwd.name) / "python_data.data")
3231

3332
os.remove(Path(addon.cwd.name) / "python_data.js")
34-
os.remove(Path(addon.cwd.name) / "python_data.data")
3533

3634

3735
def test_python_env_from_file_1():
@@ -53,7 +51,5 @@ def test_python_env_from_file_1():
5351

5452
# Check empack output
5553
assert os.path.isfile(Path(addon.cwd.name) / "python_data.js")
56-
assert os.path.isfile(Path(addon.cwd.name) / "python_data.data")
5754

5855
os.remove(Path(addon.cwd.name) / "python_data.js")
59-
os.remove(Path(addon.cwd.name) / "python_data.data")

webpack.config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ module.exports = {
1313
to: '.'
1414
},
1515
{
16-
from: 'src/python_data.data',
16+
from: 'src/python_data.js',
1717
to: '.'
1818
},
1919
{
20-
from: 'src/python_data.js',
21-
to: '.'
22-
}
20+
from: 'src/*.data',
21+
to: './[name].data'
22+
},
23+
{
24+
from: 'src/*.js',
25+
to: './[name].js'
26+
},
2327
]
2428
})
2529
]

0 commit comments

Comments
 (0)