From fca6a405b726e8241a8f8630157d4f68f37afc28 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 20 May 2022 16:44:46 +0200 Subject: [PATCH 1/4] Remove duplication of the labextension --- .gitignore | 5 ++++- MANIFEST.in | 3 ++- jupyterlite_xeus_python/__init__.py | 14 ++++++++++---- jupyterlite_xeus_python/_version.py | 23 ++++++++++------------- package.json | 7 ++++--- setup.py | 4 ++-- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 5241ff5..35de38e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ node_modules/ *.egg-info/ .ipynb_checkpoints *.tsbuildinfo -jupyterlite_xeus_python/labextension # Created by https://www.gitignore.io/api/python # Edit at https://www.gitignore.io/?templates=python @@ -119,3 +118,7 @@ python_data.data xpython_wasm.js xpython_wasm.wasm xeus_python.worker.js + +# Labextension +share +jupyterlite_xeus_python/package.json diff --git a/MANIFEST.in b/MANIFEST.in index 5438ca8..8c26f0f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,13 +3,14 @@ include *.md include *.yml include pyproject.toml include package.json +include jupyterlite_xeus_python/package.json include install.json include ts*.json include yarn.lock include webpack.config.js recursive-include tests *.py -graft jupyterlite_xeus_python/labextension +graft share graft docs diff --git a/jupyterlite_xeus_python/__init__.py b/jupyterlite_xeus_python/__init__.py index 360f7cc..93d803f 100644 --- a/jupyterlite_xeus_python/__init__.py +++ b/jupyterlite_xeus_python/__init__.py @@ -1,3 +1,4 @@ +import sys import json from pathlib import Path @@ -5,9 +6,14 @@ HERE = Path(__file__).parent.resolve() -with (HERE / "labextension" / "package.json").open() as fid: - data = json.load(fid) - def _jupyter_labextension_paths(): - return [{"src": "labextension", "dest": data["name"]}] + prefix = sys.prefix + # For when in dev mode + if (HERE.parent / 'share' / 'jupyter' / 'labextensions' / '@jupyterlite' / 'xeus-python-kernel').parent.exists(): + prefix = HERE.parent + + return [{ + 'src': prefix / 'share' / 'jupyter' / 'labextensions' / '@jupyterlite' / 'xeus-python-kernel', + 'dest': '@jupyterlite/xeus-python-kernel', + }] diff --git a/jupyterlite_xeus_python/_version.py b/jupyterlite_xeus_python/_version.py index da102d4..0c15733 100644 --- a/jupyterlite_xeus_python/_version.py +++ b/jupyterlite_xeus_python/_version.py @@ -7,19 +7,16 @@ def _fetchVersion(): HERE = Path(__file__).parent.resolve() - for settings in HERE.rglob("package.json"): - try: - with settings.open() as f: - version = json.load(f)["version"] - return ( - version.replace("-alpha.", "a") - .replace("-beta.", "b") - .replace("-rc.", "rc") - ) - except FileNotFoundError: - pass - - raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}") + try: + with open(HERE / "package.json", "r") as f: + version = json.load(f)["version"] + return ( + version.replace("-alpha.", "a") + .replace("-beta.", "b") + .replace("-rc.", "rc") + ) + except FileNotFoundError: + pass __version__ = _fetchVersion() diff --git a/package.json b/package.json index 4f464e3..8fd1880 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,11 @@ "build:dockerimage_no_cache": "docker build -t mydockerimage --no-cache . ", "build:emscripten": "echo $(pwd) && docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) mydockerimage copy_output.sh", "copy-files": "copyfiles -u 1 src/xpython_wasm.wasm src/xpython_wasm.worker.js src/xpython_wasm.js src/python_data.js src/python_data.data lib", + "copy-packagejson": "copyfiles package.json jupyterlite_xeus_python/", "build:wasm": "jlpm run build:dockerimage && jlpm run build:emscripten", "build:wasm_no_cache": "jlpm run build:dockerimage_no_cache && jlpm run build:emscripten", - "build": "jlpm run build:lib && jlpm run copy-files && jlpm run build:labextension:dev", - "build:prod": "jlpm run clean && jlpm run build:wasm && jlpm run build:lib && jlpm run copy-files && jlpm run build:labextension", + "build": "jlpm run build:lib && jlpm run copy-files && jlpm run copy-packagejson && jlpm run build:labextension:dev", + "build:prod": "jlpm run clean && jlpm run build:wasm && jlpm run build:lib && jlpm run copy-files && jlpm run copy-packagejson && jlpm run build:labextension", "build:labextension": "jupyter labextension build .", "build:labextension:dev": "jupyter labextension build --development True .", "build:lib": "tsc", @@ -82,7 +83,7 @@ }, "jupyterlab": { "extension": true, - "outputDir": "jupyterlite_xeus_python/labextension", + "outputDir": "share/jupyter/labextensions/@jupyterlite/xeus-python-kernel", "webpackConfig": "./webpack.config.js", "sharedPackages": { "@jupyterlite/kernel": { diff --git a/setup.py b/setup.py index 95e87c0..b4ae39f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ # The name of the project name = "jupyterlite-xeus-python" -lab_path = (HERE / name.replace("-", "_") / "labextension") +lab_path = (HERE / "share" / "jupyter" / "labextensions" / "@jupyterlite" / "xeus-python-kernel") # Representative files that should exist after a successful build ensured_targets = [ @@ -20,7 +20,7 @@ str(lab_path / "static/style.js") ] -labext_name = "jupyterlite-xeus-python" +labext_name = "@jupyterlite/xeus-python-kernel" data_files_spec = [ ("share/jupyter/labextensions/%s" % labext_name, str(lab_path.relative_to(HERE)), "**"), From 63cbe58f2696a0ee7d5abe9f4b6524fc2b034bbb Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 20 May 2022 17:20:42 +0200 Subject: [PATCH 2/4] Update pyproject.toml --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9e0020e..c2bad4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,8 @@ requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1"] build-backend = "jupyter_packaging.build_api" [tool.jupyter-packaging.options] -skip-if-exists = ["jupyterlite_xeus_python/labextension/static/style.js"] -ensured-targets = ["jupyterlite_xeus_python/labextension/static/style.js", "jupyterlite_xeus_python/labextension/package.json"] +skip-if-exists = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/static/style.js"] +ensured-targets = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/static/style.js", "share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/package.json"] [tool.jupyter-packaging.builder] factory = "jupyter_packaging.npm_builder" @@ -14,4 +14,4 @@ build_cmd = "build:prod" npm = ["jlpm"] [tool.check-manifest] -ignore = ["jupyterlite_xeus_python/labextension/**", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"] +ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"] From 8bf952b6760921fa61f7c93a14305a18607c3715 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 20 May 2022 17:28:22 +0200 Subject: [PATCH 3/4] Add ignore on the package.json file --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c2bad4c..edd816e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,4 +14,4 @@ build_cmd = "build:prod" npm = ["jlpm"] [tool.check-manifest] -ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"] +ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "jupyterlite_xeus_python/package.json", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"] From 3ff3a9726f475beb4478e960eb636243fa7d7a8a Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 20 May 2022 18:06:09 +0200 Subject: [PATCH 4/4] Remove package.json from the site-packages We don't need this --- .gitignore | 1 - MANIFEST.in | 1 - package.json | 5 ++--- pyproject.toml | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 35de38e..fb278c7 100644 --- a/.gitignore +++ b/.gitignore @@ -121,4 +121,3 @@ xeus_python.worker.js # Labextension share -jupyterlite_xeus_python/package.json diff --git a/MANIFEST.in b/MANIFEST.in index 8c26f0f..da27019 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,6 @@ include *.md include *.yml include pyproject.toml include package.json -include jupyterlite_xeus_python/package.json include install.json include ts*.json include yarn.lock diff --git a/package.json b/package.json index 8fd1880..8b0d5fb 100644 --- a/package.json +++ b/package.json @@ -33,11 +33,10 @@ "build:dockerimage_no_cache": "docker build -t mydockerimage --no-cache . ", "build:emscripten": "echo $(pwd) && docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) mydockerimage copy_output.sh", "copy-files": "copyfiles -u 1 src/xpython_wasm.wasm src/xpython_wasm.worker.js src/xpython_wasm.js src/python_data.js src/python_data.data lib", - "copy-packagejson": "copyfiles package.json jupyterlite_xeus_python/", "build:wasm": "jlpm run build:dockerimage && jlpm run build:emscripten", "build:wasm_no_cache": "jlpm run build:dockerimage_no_cache && jlpm run build:emscripten", - "build": "jlpm run build:lib && jlpm run copy-files && jlpm run copy-packagejson && jlpm run build:labextension:dev", - "build:prod": "jlpm run clean && jlpm run build:wasm && jlpm run build:lib && jlpm run copy-files && jlpm run copy-packagejson && jlpm run build:labextension", + "build": "jlpm run build:lib && jlpm run copy-files && jlpm run build:labextension:dev", + "build:prod": "jlpm run clean && jlpm run build:wasm && jlpm run build:lib && jlpm run copy-files && jlpm run build:labextension", "build:labextension": "jupyter labextension build .", "build:labextension:dev": "jupyter labextension build --development True .", "build:lib": "tsc", diff --git a/pyproject.toml b/pyproject.toml index edd816e..c2bad4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,4 +14,4 @@ build_cmd = "build:prod" npm = ["jlpm"] [tool.check-manifest] -ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "jupyterlite_xeus_python/package.json", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"] +ignore = ["share/jupyter/labextensions/@jupyterlite/xeus-python-kernel/**", "yarn.lock", ".*", "package-lock.json", "Dockerfile", "src/xeus_python.worker.js", "src/xpython_wasm.js", "src/xpython_wasm.wasm", "src/python_data.data", "src/python_data.js", "*.sh"]