From 885c72bc696ff0e711229e5997a613a7678cb41b Mon Sep 17 00:00:00 2001 From: martinRenou Date: Mon, 30 Nov 2020 16:53:35 +0100 Subject: [PATCH 1/2] JupyterLab 3 update Signed-off-by: martinRenou --- .gitignore | 1 + MANIFEST.in | 2 + install.json | 5 ++ jupytext/__init__.py | 4 ++ packages/labextension/package.json | 35 +++++++++---- pyproject.toml | 3 ++ requirements-dev.txt | 2 + setup.py | 81 +++++++++++++++++++----------- 8 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 install.json create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 17921bf29..ec5358b79 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ future gits* .ipynb_checkpoints docs/_build +jupytext/labextension # Will be created by postBuild demo/get_started.ipynb diff --git a/MANIFEST.in b/MANIFEST.in index 53a9ceead..08c279773 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,8 @@ include *.md include *.txt include *.rst +graft jupytext/labextension + graft tests global-exclude *__pycache__ global-exclude *.pyc diff --git a/install.json b/install.json new file mode 100644 index 000000000..a1ebe7949 --- /dev/null +++ b/install.json @@ -0,0 +1,5 @@ +{ + "packageManager": "python", + "packageName": "jupytext", + "uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupytext" +} diff --git a/jupytext/__init__.py b/jupytext/__init__.py index d1e75cb9a..82f6861c6 100644 --- a/jupytext/__init__.py +++ b/jupytext/__init__.py @@ -16,6 +16,10 @@ TextFileContentsManager = reraise(err) +def _jupyter_labextension_paths(): # pragma: no cover + return [{"src": "labextension", "dest": "jupyterlab-jupytext"}] + + def load_jupyter_server_extension(app): # pragma: no cover """Use Jupytext's contents manager""" if hasattr(app.contents_manager_class, "default_jupytext_formats"): diff --git a/packages/labextension/package.json b/packages/labextension/package.json index 631ccb77a..b64bd38a3 100644 --- a/packages/labextension/package.json +++ b/packages/labextension/package.json @@ -25,10 +25,20 @@ "url": "https://github.com/mwouts/jupytext.git" }, "scripts": { - "build": "tsc", - "clean": "rimraf lib", - "prepare": "npm run clean && npm run build", - "watch": "tsc -w" + "build": "jlpm run build:lib && jlpm run build:labextension:dev", + "build:labextension": "jupyter labextension build .", + "build:labextension:dev": "jupyter labextension build --development True .", + "build:lib": "tsc", + "build:prod": "jlpm run build:lib && jlpm run build:labextension", + "clean": "jlpm run clean:lib", + "clean:all": "jlpm run clean:lib && jlpm run clean:labextension", + "clean:labextension": "rimraf jupyterlab-jupytext/labextension", + "clean:lib": "rimraf lib tsconfig.tsbuildinfo", + "install:extension": "jupyter labextension develop --overwrite .", + "prepare": "jlpm run clean && jlpm run build:prod", + "watch": "run-p watch:src watch:labextension", + "watch:labextension": "jupyter labextension watch .", + "watch:src": "tsc -w" }, "jupyterlab": { "discovery": { @@ -43,16 +53,19 @@ } }, "extension": true, - "schemaDir": "schema" + "schemaDir": "schema", + "outputDir": "../../jupytext/labextension" }, "dependencies": { - "@jupyterlab/application": "^2.0", - "@jupyterlab/apputils": "^2.0", - "@jupyterlab/notebook": "^2.0", - "@jupyterlab/nbformat": "^2.0" + "@jupyterlab/application": "^3.0.0", + "@jupyterlab/apputils": "^3.0.0", + "@jupyterlab/nbformat": "^3.0.0", + "@jupyterlab/notebook": "^3.0.0" }, "devDependencies": { - "rimraf": "^3.0.0", - "typescript": "~3.7.3" + "@jupyterlab/builder": "^3.0.0", + "npm-run-all": "^4.1.5", + "rimraf": "^3.0.2", + "typescript": "~4.0.3" } } diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..87eef4f66 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0,==3.*", "setuptools>=40.8.0", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/requirements-dev.txt b/requirements-dev.txt index c9c96140a..b5bf1992a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,6 +8,8 @@ ipykernel sphinx-gallery<=0.7.0 setuptools toml +jupyterlab==3.0.0 +jupyter-packaging # Python 2 pathlib diff --git a/setup.py b/setup.py index 8a6f9caa4..89e718606 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,13 @@ import re from setuptools import setup, find_packages +from jupyter_packaging import ( + create_cmdclass, + install_npm, + ensure_targets, + combine_commands, +) + this_directory = path.abspath(path.dirname(__file__)) with open(path.join(this_directory, "README.md"), encoding="utf-8") as f: # replace Markdown links (docs/[NAME].md with (https://jupytext.readthedocs.io/en/latest/[NAME].html @@ -17,6 +24,51 @@ version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) version = version_match.group(1) +lab_path = path.join(this_directory, "jupytext", "labextension") +nb_path = path.join(this_directory, "jupytext", "nbextension") + +jupyter_config_path = path.join(this_directory, "jupyter-config") +notebook_config_path = path.join(jupyter_config_path, "jupyter_notebook_config.d") +jupyter_server_config_path = path.join(jupyter_config_path, "jupyter_server_config.d") +nbconfig_path = path.join(jupyter_config_path, "nbconfig", "notebook.d") + +data_files_spec = [ + # Install labextension + ("share/jupyter/labextensions/jupyterlab-jupytext", lab_path, "**"), + ("share/jupyter/labextensions/jupyterlab-jupytext", this_directory, "install.json"), + # Install nbextension + ("share/jupyter/nbextensions/jupytext", nb_path, "**"), + ("share/jupyter/nbextensions/jupytext", nbconfig_path, "jupytext.json"), + # Install config files + ( + "etc/jupyter/jupyter_server_config.d", + jupyter_server_config_path, + "jupytext.json", + ), + ("etc/jupyter/jupyter_notebook_config.d", notebook_config_path, "jupytext.json"), + ("etc/jupyter/nbconfig/notebook.d", nbconfig_path, "jupytext.json"), +] + +# Representative files that should exist after a successful build +jstargets = [ + path.join(lab_path, "package.json"), +] + +cmdclass = create_cmdclass( + "jsdeps", + package_data_spec={"jupytext": ["nbextension/**"]}, + data_files_spec=data_files_spec, +) + +cmdclass["jsdeps"] = combine_commands( + install_npm( + path.join(this_directory, "packages", "labextension"), + build_cmd="build:prod", + npm=["jlpm"], + ), + ensure_targets(jstargets), +) + setup( name="jupytext", version=version, @@ -28,34 +80,7 @@ long_description_content_type="text/markdown", url="https://github.com/mwouts/jupytext", packages=find_packages(exclude=["tests"]), - package_data={"jupytext": ["nbextension/*.*"]}, - data_files=[ - ( - "etc/jupyter/nbconfig/notebook.d", - ["jupyter-config/nbconfig/notebook.d/jupytext.json"], - ), - ( - "etc/jupyter/jupyter_notebook_config.d", - ["jupyter-config/jupyter_notebook_config.d/jupytext.json"], - ), - ( - "etc/jupyter/jupyter_server_config.d", - ["jupyter-config/jupyter_server_config.d/jupytext.json"], - ), - ( - "share/jupyter/nbextensions/jupytext", - [ - "jupytext/nbextension/index.js", - "jupytext/nbextension/README.md", - "jupytext/nbextension/jupytext_menu.png", - "jupytext/nbextension/jupytext.yml", - ], - ), - ( - "share/jupyter/lab/extensions", - ["packages/labextension/jupyterlab-jupytext-1.2.3.tgz"], - ), - ], + cmdclass=cmdclass, entry_points={"console_scripts": ["jupytext = jupytext.cli:jupytext"]}, tests_require=["pytest"], install_requires=["nbformat>=4.0.0", "pyyaml", "toml", "markdown-it-py~=0.6.0"], From 798dc2fd14d2e395b18623a1119dd5b70e22e346 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 5 Jan 2021 20:27:19 +0100 Subject: [PATCH 2/2] Update build dependencies when building the wheel Signed-off-by: martinRenou --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 21516e00f..7845fcfc9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -213,7 +213,7 @@ jobs: python-version: 3.7 - name: Build package run: | - pip install wheel + pip install wheel jupyter-packaging jupyterlab=3 python setup.py sdist bdist_wheel - name: Publish uses: pypa/gh-action-pypi-publish@v1.1.0