From 253efa171328c91b67f21c13fa2e75385dc8410e Mon Sep 17 00:00:00 2001 From: telamonian Date: Thu, 3 Jun 2021 14:38:54 -0400 Subject: [PATCH] fixed layout of `labextension` in dist; `jupyter labextension develop` now works --- .gitignore | 2 +- MANIFEST.in | 3 ++- Makefile | 2 +- js/package.json | 3 +-- jupyterfs/__init__.py | 13 +++++++++++++ jupyterfs/extension.py | 16 ++++++++-------- package.json | 1 + setup.py | 5 ++--- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 8b3e797d..1764d0e2 100644 --- a/.gitignore +++ b/.gitignore @@ -197,10 +197,10 @@ ENV/ .DS_Store +*/labextension .autoversion .jupyter docs/api docs/index.md -js/labextension python_junit.xml diff --git a/MANIFEST.in b/MANIFEST.in index 7326f689..abb1cb82 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -12,11 +12,12 @@ include jupyterfs/browser-test.js include pyproject.toml include setup.cfg +graft labextension + # javascript pkg files include js/package.json include js/ts*.json -graft js/labextension graft js/src graft js/style prune js/build diff --git a/Makefile b/Makefile index 8a1f0f0b..001853e7 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ clean: ## clean the repository rm -rf binder/.[!.]* binder/*.ipynb ## build state cd js; ${YARN} clean:slate - rm -rf *.egg-info *junit.xml .*-log.txt .jupyter/ .local/ .pytest_cache/ build/ coverage* dist/ MANIFEST node_modules/ pip-wheel-metadata + rm -rf *.egg-info *junit.xml .*-log.txt .jupyter/ .local/ .pytest_cache/ build/ coverage* dist/ MANIFEST node_modules/ pip-wheel-metadata jupyterfs/labextension # make -C ./docs clean ## package lock files # rm -rf package-lock.json yarn-lock.json js/package-lock.json js/yarn-lock.json diff --git a/js/package.json b/js/package.json index dfa67e58..ef13810c 100644 --- a/js/package.json +++ b/js/package.json @@ -23,7 +23,6 @@ "clean:slate": "jlpm clean && jlpm clean:labextension && rimraf node_modules", "deduplicate": "jlpm yarn-deduplicate -s fewer ../yarn.lock || jlpm yarn-deduplicate -s fewer", "fix": "jlpm lint --fix", - "install:extension": "jupyter labextension develop --overwrite .", "integrity": "jlpm install && jlpm deduplicate && jlpm install", "lint": "eslint -c .eslintrc.js --ext .js,.ts,.tsx src/ tests/", "postpack": "shx rm README.md", @@ -107,7 +106,7 @@ } }, "extension": true, - "outputDir": "labextension", + "outputDir": "../jupyterfs/labextension", "schemaDir": "schema" } } diff --git a/jupyterfs/__init__.py b/jupyterfs/__init__.py index 792cdfbc..38de070b 100644 --- a/jupyterfs/__init__.py +++ b/jupyterfs/__init__.py @@ -6,3 +6,16 @@ # the Apache License 2.0. The full license can be found in the LICENSE file. # from ._version import __version__ # noqa: F401 + +import json +from pathlib import Path + +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"], + }] diff --git a/jupyterfs/extension.py b/jupyterfs/extension.py index 3a7fec91..361ae20c 100644 --- a/jupyterfs/extension.py +++ b/jupyterfs/extension.py @@ -24,24 +24,24 @@ def _jupyter_server_extension_paths(): - return [{'module': 'jupyterfs.extension'}] + return [{"module": "jupyterfs.extension"}] -def load_jupyter_server_extension(nb_server_app): +def load_jupyter_server_extension(serverapp): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ - web_app = nb_server_app.web_app - base_url = web_app.settings['base_url'] - host_pattern = '.*$' + web_app = serverapp.web_app + base_url = web_app.settings["base_url"] + host_pattern = ".*$" - if not isinstance(nb_server_app.contents_manager, MetaManager): + if not isinstance(serverapp.contents_manager, MetaManager): warnings.warn(_mm_config_warning_msg) return - resources_url = 'jupyterfs/resources' - print('Installing jupyter-fs resources handler on path %s' % url_path_join(base_url, resources_url)) + resources_url = "jupyterfs/resources" + print("Installing jupyter-fs resources handler on path %s" % url_path_join(base_url, resources_url)) web_app.add_handlers(host_pattern, [(url_path_join(base_url, resources_url), MetaManagerHandler)]) diff --git a/package.json b/package.json index 785359ad..6119f8fa 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "license": "BSD-3-Clause", "workspaces": ["js"], "scripts": { + "develop": "jupyter labextension develop --overwrite .", "test:browser": "yarn --cwd ./js test:browser" } } diff --git a/setup.py b/setup.py index 73dee2df..7a5ab275 100644 --- a/setup.py +++ b/setup.py @@ -24,13 +24,12 @@ # relative paths to python pkg dir and labextension pkg dir js_pkg, py_pkg = Path('js'), Path('jupyterfs') # relative path to labextension dist that gets built at the root of the python package -labext_dist = js_pkg/'labextension' +labext_dist = py_pkg/'labextension' # Representative files that should exist after a successful build jstargets = [labext_dist/"package.json"] version = get_version(str(py_pkg / '_version.py')) -# POSIX_PREFIX/APP_SUFFIX determines the install location of the labextension dist +# POSIX_PREFIX/(APP_SUFFIX, CONFIG_SUFFIX) determines the install location of the (labextension dist, extension config) APP_SUFFIX = Path('share/jupyter/labextensions/') -# POSIX_PREFIX/CONFIG_SUFFIX determines the install location of the extension config CONFIG_SUFFIX = Path('etc/jupyter/') with open('README.md', encoding='utf-8') as f: