Skip to content

Commit c22fd31

Browse files
committed
move python to src to avoid import confusion
1 parent 52c17ce commit c22fd31

27 files changed

+121
-64
lines changed

.github/workflows/test.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ jobs:
6969
- name: Upload test config
7070
uses: actions/upload-artifact@v3
7171
with:
72-
name: pyproject-toml
73-
path: pyproject.toml
72+
name: test-assets
73+
path: |
74+
pyproject.toml
75+
examples
7476
if-no-files-found: error
7577

7678
test:
@@ -145,7 +147,7 @@ jobs:
145147
146148
- uses: actions/download-artifact@v3
147149
with:
148-
name: pyproject-toml
150+
name: test-assets
149151

150152
- name: Install test deps
151153
run: |-
@@ -157,6 +159,8 @@ jobs:
157159
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/pyodide-kernel.*OK"
158160
159161
- name: Run the tests
162+
env:
163+
LITE_PYODIDE_KERNEL_DEMO: ./examples
160164
run: pytest
161165

162166
- name: Upload reports

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_modules/
55
*.egg-info/
66
.ipynb_checkpoints
77
*.tsbuildinfo
8-
jupyterlite_pyodide_kernel/labextension
8+
src/jupyterlite_pyodide_kernel/labextension
99

1010
# Created by https://www.gitignore.io/api/python
1111
# Edit at https://www.gitignore.io/?templates=python
@@ -118,4 +118,4 @@ packages/pyodide-kernel/pypi/*.json
118118
_pypi.ts
119119
.jupyterlite.doit.db
120120
_output
121-
jupyterlite_pyodide_kernel/tests/fixtures/.pyodide*/
121+
src/jupyterlite_pyodide_kernel/tests/fixtures/.pyodide*/

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ node_modules/
22
**/node_modules
33
**/lib
44
**/package.json
5-
jupyterlite_pyodide_kernel/labextension/
5+
src/jupyterlite_pyodide_kernel/labextension/
66
**/.pyodide/
77
.pytest_cache/
88
docs/

.readthedocs.yml

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@ build:
77
nodejs: '18'
88
apt_packages:
99
- libarchive-dev
10-
1110
jobs:
1211
pre_build:
12+
- python -m pip install -r requirements-dev.txt
1313
- jlpm --frozen-lockfile
14-
- jlpm build
14+
- jlpm build:prod
1515
- jlpm dist
1616
# pre-build the lite site to isolate build errors
1717
- jlpm docs:lite
1818

19-
python:
20-
install:
21-
- method: pip
22-
path: .
23-
extra_requirements:
24-
- dev
25-
- docs
26-
2719
sphinx:
2820
builder: html
2921
configuration: docs/conf.py

examples/intro.ipynb

+29-13
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@
8181
"source": [
8282
"## What _can't_ it do?\n",
8383
"\n",
84-
"While a very broad subset of the CPython standard library, and much of the open source, scientific Python ecosystem are available, there are some limitation."
84+
"While a very broad subset of the CPython standard library, and much of the open source, scientific Python ecosystem are available, there are some limitation.\n",
85+
"\n",
86+
"The best way to find out is to **try it out**! However, some known implementation-level limitations are listed below."
8587
]
8688
},
8789
{
@@ -91,14 +93,28 @@
9193
"source": [
9294
"### Differences from CPython\n",
9395
"\n",
94-
"A number of aspects of the underlying Python implementation that don't work the same way as their upstream counterparts, if at all.\n",
96+
"A number of aspects of the underlying Python implementation that don't work the same way as their upstream counterparts, if at all. Uses of these features will need to be updated, or put behind some check.\n",
9597
"\n",
9698
"- no threads\n",
9799
"- no subprocesses\n",
98-
"- no custom event loops\n",
99-
"- some blocking features are made asynchronous, such as `await input` \n",
100+
"- no custom event asynchronous loops\n",
101+
"- package `data_files` are not installed\n",
102+
"- some blocking features are made asynchronous\n",
103+
" - `input` must be `await`ed\n",
104+
" - the `urllib` family of HTTP features don't work\n",
105+
" - though [pyodide-http](https://github.com/koenvo/pyodide-http) can be explicitly installed, imported and used"
106+
]
107+
},
108+
{
109+
"cell_type": "markdown",
110+
"id": "961bb18f-954b-4624-bf85-774d451addec",
111+
"metadata": {},
112+
"source": [
113+
"### Differences from `IPython` and `ipykernel`\n",
114+
"\n",
115+
"`jupyterlite-pyodide-kernel` ships a _shim_ of `ipykernel`, and changes a number of features in `ipython`\n",
100116
"\n",
101-
"Libraries and notebooks that use these features will need to be updated."
117+
"- many [magics](https://ipython.readthedocs.io/en/stable/interactive/magics.html) don't work"
102118
]
103119
},
104120
{
@@ -107,7 +123,7 @@
107123
"metadata": {},
108124
"source": [
109125
"### Differences from Pyodide\n",
110-
"Inside a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), there are a number of features that don't work (yet).\n",
126+
"Because `jupyterlite-pyodide-kernel` runs inside a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), a number of features don't work (yet).\n",
111127
"\n",
112128
"- no access to the browser's DOM\n",
113129
" - in particular, the Pyodide [matplotlib](https://github.com/pyodide/matplotlib-pyodide) backend will not work"
@@ -122,15 +138,15 @@
122138
"\n",
123139
"This site follows the pattern for an [offline site](https://jupyterlite.readthedocs.io/en/0.1.0-beta/howto/configure/advanced/offline.html) based on a minimal, but fully self-contained, distribution of Pyodide. \n",
124140
"\n",
125-
"> ℹ️ For a more full-featured site with full Pyodide distributions, hosted from a CDN, see: \n",
126-
">\n",
127-
"> - the JupyterLite [documentation](https://jupyterlite.readthedocs.io) on [ReadTheDocs](https://jupyterlite.readthedocs.io/en/0.1.0-beta/reference/demo.html)\n",
128-
"> - the JupyterLite [demo](https://jupyterlite.github.io/demo) on [GitHub Pages](https://jupyterlite.readthedocs.io/en/0.1.0-beta/quickstart/deploy.html)\n",
129-
"\n",
130141
"This means:\n",
131142
"- no additional resources are loaded from any other sites on the internet\n",
132143
" - serving from a content delivery network (CDN) is often faster, but _could_ disappear or change in the future \n",
133-
"- only the Python 3.10 standard library is available by default"
144+
"- only the Python 3.10 standard library is available by default\n",
145+
"\n",
146+
"> ℹ️ For a more full-featured site with full Pyodide distributions, hosted from a CDN, see: \n",
147+
">\n",
148+
"> - the JupyterLite [documentation](https://jupyterlite.readthedocs.io) on [ReadTheDocs](https://jupyterlite.readthedocs.io/en/0.1.0-beta/reference/demo.html)\n",
149+
"> - the JupyterLite [demo](https://jupyterlite.github.io/demo) on [GitHub Pages](https://jupyterlite.readthedocs.io/en/0.1.0-beta/quickstart/deploy.html)"
134150
]
135151
},
136152
{
@@ -184,7 +200,7 @@
184200
"source": [
185201
"## How do I use more client extension packages?\n",
186202
"\n",
187-
"Some python packages, like widgets, will require client extensions, and need to be available when the site loads for a site visitor.\n",
203+
"Some python packages, like all Jupyter widgets, will require client extensions, and need to be available when the site loads for a site visitor.\n",
188204
"\n",
189205
"Any number of JupyterLab [extensions]() can be [added at **build time**](https://jupyterlite.readthedocs.io/en/latest/howto/configure/simple_extensions.html), but not all will be compatible:\n",
190206
"\n",

examples/jupyter_lite_config.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"LiteBuildConfig": {
33
"contents": ["."],
44
"output_dir": "../build/docs-app",
5-
"ignore_sys_prefix": ["federated_extensions"],
65
"federated_extensions": [
7-
"https://files.pythonhosted.org/packages/df/82/4576cbc07ebace8c7734fe08b2c2f9123b7ebecd29e932a3b839b6bee2cb/jupyterlab_widgets-3.0.5-py3-none-any.whl",
8-
"../jupyterlite_pyodide_kernel/labextension"
6+
"https://files.pythonhosted.org/packages/df/82/4576cbc07ebace8c7734fe08b2c2f9123b7ebecd29e932a3b839b6bee2cb/jupyterlab_widgets-3.0.5-py3-none-any.whl"
97
],
108
"cache_dir": "../build/.lite-cache"
119
},

nx.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
"build": {
2020
"dependsOn": ["build:py", "^build"],
2121
"outputs": [
22-
"{projectRoot}/lib",
23-
"{projectRoot}/jupyterlite_pyodide_kernel/labextension/package.json",
24-
"{projectRoot}/jupyterlite_pyodide_kernel/labextension/static/pypi/all.json"
22+
"{projectRoot}/src/jupyterlite_pyodide_kernel/labextension/package.json",
23+
"{projectRoot}/src/jupyterlite_pyodide_kernel/labextension/static/pypi/all.json"
2524
]
2625
},
2726
"build:prod": {
2827
"dependsOn": ["build:py", "^build:prod"],
2928
"outputs": [
30-
"{projectRoot}/lib",
31-
"{projectRoot}/jupyterlite_pyodide_kernel/labextension/package.json",
32-
"{projectRoot}/jupyterlite_pyodide_kernel/labextension/static/pypi/all.json"
29+
"{projectRoot}/src/jupyterlite_pyodide_kernel/labextension/package.json",
30+
"{projectRoot}/src/jupyterlite_pyodide_kernel/labextension/static/pypi/all.json"
3331
]
3432
}
3533
}

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
"dist:npm": "lerna run --stream dist",
2323
"dist:pypi": "pyproject-build .",
2424
"dist": "jlpm dist:pypi && jlpm dist:npm",
25-
"docs:lite": "cd examples && jupyter lite build",
25+
"docs:lite": "jlpm docs:lite:build && jlpm docs:lite:archive && jlpm docs:lite:check",
26+
"docs:lite:build": "cd examples && jupyter lite build",
27+
"docs:lite:archive": "cd examples && jupyter lite archive",
2628
"docs:lite:check": "cd examples && jupyter lite check",
2729
"docs:sphinx": "sphinx-build -W -b html docs build/docs",
28-
"docs": "jlpm docs:lite && jlpm docs:sphinx && jlpm docs:lite:check",
30+
"docs": "jlpm docs:lite && jlpm docs:sphinx",
2931
"eslint:check": "eslint . --cache --ext .ts,.tsx",
3032
"eslint": "jlpm eslint:check --fix",
3133
"lint": "jlpm lint:js && jlpm lint:py",
@@ -35,8 +37,8 @@
3537
"lint:py": "jlpm lint:py:black && jlpm lint:py:ruff --fix-only",
3638
"lint:py:pip": "python -m pip check",
3739
"lint:py:check": "jlpm lint:py:pip && jlpm lint:py:black --check && jlpm lint:py:ruff",
38-
"lint:py:black": "black scripts jupyterlite_pyodide_kernel packages/pyodide-kernel/py",
39-
"lint:py:ruff": "ruff scripts jupyterlite_pyodide_kernel packages/pyodide-kernel/py",
40+
"lint:py:black": "black scripts src packages/pyodide-kernel/py",
41+
"lint:py:ruff": "ruff scripts src packages/pyodide-kernel/py",
4042
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml,.yaml}\"",
4143
"prettier:check": "jlpm prettier:base --check",
4244
"prettier": "jlpm prettier:base --write --list-different",

packages/pyodide-kernel-extension/package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
"schema/*.json"
3232
],
3333
"scripts": {
34-
"build": "jlpm build:lib && jlpm build:labextension:dev",
35-
"build:prod": "jlpm build:lib && jlpm build:labextension",
34+
"build": "jlpm build:lib && jlpm build:labextension:dev && jlpm dev",
35+
"build:prod": "jlpm build:lib && jlpm build:labextension && jlpm dev",
3636
"build:labextension": "jupyter labextension build .",
3737
"build:labextension:dev": "jupyter labextension build --development True .",
3838
"build:lib": "tsc -b",
39+
"dev": "cd ../../ && jupyter labextension develop --overwrite .",
3940
"dist": "cd ../../dist && npm pack ../packages/pyodide-kernel-extension",
4041
"clean": "jlpm clean:lib",
4142
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
42-
"clean:labextension": "rimraf ../../jupyterlite_pyodide_kernel/labextension",
43+
"clean:labextension": "rimraf ../../src/jupyterlite_pyodide_kernel/labextension",
4344
"clean:all": "jlpm clean:lib && jlpm clean:labextension",
4445
"docs": "typedoc src",
4546
"watch": "run-p watch:src watch:labextension",
@@ -63,13 +64,17 @@
6364
},
6465
"jupyterlab": {
6566
"extension": true,
66-
"outputDir": "../../jupyterlite_pyodide_kernel/labextension",
67+
"outputDir": "../../src/jupyterlite_pyodide_kernel/labextension",
6768
"webpackConfig": "webpack.config.js",
6869
"sharedPackages": {
6970
"@jupyterlite/kernel": {
7071
"bundled": false,
7172
"singleton": true
7273
},
74+
"@jupyterlite/pyodide-kernel": {
75+
"bundled": true,
76+
"singleton": true
77+
},
7378
"@jupyterlite/server": {
7479
"bundled": false,
7580
"singleton": true

pyproject.toml

+29-17
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ lint = [
6767
]
6868

6969
test = [
70-
"pytest-console-scripts",
7170
"pytest-cov",
71+
"pytest-console-scripts",
7272
"pytest-html",
7373
"pytest-xdist",
7474
"pytest",
@@ -87,20 +87,17 @@ docs = [
8787
"libarchive-c"
8888
]
8989

90-
[tool.hatch.metadata]
91-
allow-direct-references = true
92-
9390
[tool.hatch.version]
94-
path = "jupyterlite_pyodide_kernel/_version.py"
91+
path = "src/jupyterlite_pyodide_kernel/_version.py"
9592

9693
[tool.hatch.build.targets.sdist]
97-
artifacts = ["jupyterlite_pyodide_kernel/labextension"]
94+
artifacts = ["src/jupyterlite_pyodide_kernel/labextension"]
9895
exclude = [
9996
".github",
100-
"/jupyterlite_pyodide_kernel/tests/fixtures/.pyodide"
97+
"/src/jupyterlite_pyodide_kernel/tests/fixtures/.pyodide"
10198
]
10299
include = [
103-
"/jupyterlite_pyodide_kernel",
100+
"/src/jupyterlite_pyodide_kernel",
104101
"/package.json",
105102
"/install.json",
106103
"/ts*.json",
@@ -109,11 +106,14 @@ include = [
109106

110107
[tool.hatch.build.targets.wheel]
111108
include = [
112-
"/jupyterlite_pyodide_kernel",
109+
"/src/jupyterlite_pyodide_kernel",
113110
]
114111

112+
[tool.hatch.build.targets.wheel.sources]
113+
"src" = ""
114+
115115
[tool.hatch.build.targets.wheel.shared-data]
116-
"jupyterlite_pyodide_kernel/labextension" = "share/jupyter/labextensions/@jupyterlite/pyodide-kernel-extension"
116+
"src/jupyterlite_pyodide_kernel/labextension" = "share/jupyter/labextensions/@jupyterlite/pyodide-kernel-extension"
117117
"install.json" = "share/jupyter/labextensions/@jupyterlite/pyodide-kernel-extension/install.json"
118118

119119
[tool.pytest.ini_options]
@@ -126,19 +126,31 @@ addopts = [
126126
"--script-launch-mode=subprocess",
127127
# parallel
128128
"-n=auto",
129-
# cov
129+
# coverage scope
130130
"--cov=jupyterlite_pyodide_kernel",
131-
"--cov-report=term-missing:skip-covered",
132-
"--cov-report=html:build/reports/htmlcov",
131+
# coverage options
133132
"--cov-branch",
134-
"--cov-fail-under=83",
135-
"--no-cov-on-fail",
133+
"--cov-context=test",
134+
# coverage reporting
135+
"--cov-report=html:build/reports/htmlcov",
136+
"--cov-report=term-missing:skip-covered",
137+
# coverage threshold (local will be slightly be higher)
138+
"--cov-fail-under=92",
136139
# html
137140
"--html=build/reports/pytest.html",
138141
"--self-contained-html",
139142
]
140-
testpaths = [
141-
"tests/",
143+
144+
[tool.coverage.run]
145+
data_file = "build/reports/.coverage"
146+
147+
[tool.coverage.html]
148+
show_contexts = true
149+
150+
[tool.coverage.paths]
151+
jupyterlite_pyodide_kernel = [
152+
"src/jupyterlite_pyodide_kernel",
153+
"*/src/jupyterlite_pyodide_kernel"
142154
]
143155

144156
[tool.jupyter-releaser.options]
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Use the demo site for a more extensive test."""
2+
import pytest
3+
import shutil
4+
import os
5+
from pathlib import Path
6+
7+
from .conftest import HERE
8+
9+
IN_TREE_EXAMPLES = HERE / "../../../examples"
10+
EXAMPLES = Path(os.environ.get("LITE_PYODIDE_KERNEL_DEMO", IN_TREE_EXAMPLES))
11+
12+
if not EXAMPLES.exists(): # pragma: no cover
13+
pytest.skip(
14+
"not in a source checkout, skipping example test", allow_module_level=True
15+
)
16+
17+
18+
def test_examples(script_runner, tmp_path):
19+
"""verity the demo site builds (if it available)"""
20+
examples = tmp_path / EXAMPLES.name
21+
shutil.copytree(EXAMPLES, examples)
22+
23+
build = script_runner.run("jupyter", "lite", "build", cwd=str(examples))
24+
assert build.success
25+
26+
build = script_runner.run("jupyter", "lite", "archive", cwd=str(examples))
27+
assert build.success
28+
29+
build = script_runner.run("jupyter", "lite", "check", cwd=str(examples))
30+
assert build.success

jupyterlite_pyodide_kernel/tests/test_repo.py src/jupyterlite_pyodide_kernel/tests/test_repo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from jupyterlite_pyodide_kernel.constants import PYODIDE_VERSION
88
from .conftest import HERE
99

10-
PACKAGES = HERE / "../../packages"
10+
PACKAGES = HERE / "../../../packages"
1111
KERNEL_PKG = PACKAGES / "pyodide-kernel"
1212
KERNEL_PKG_JSON = KERNEL_PKG / "package.json"
1313

0 commit comments

Comments
 (0)