Skip to content

Commit

Permalink
Initial Jupyter extension updates
Browse files Browse the repository at this point in the history
- Updates build system to hatchling and deprecates setup.py
- Bumps jupyter package compats in python and javascript
  • Loading branch information
halleysfifthinc committed Nov 26, 2024
1 parent ed377cf commit cdc664b
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 150 deletions.
2 changes: 1 addition & 1 deletion webio_jupyter_extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Requirements

* JupyterLab >= 3.0
* JupyterLab >= 4.0

## Install

Expand Down
39 changes: 20 additions & 19 deletions webio_jupyter_extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"main": "dist/labextension.js",
"repository": {
"type": "git",
"url": "https://github.com/github_username/webio-jupyterlab-provider.git"
"url": "https://github.com/JuliaGizmos/WebIO.jl.git",
"directory": "webio_jupyter_extension"
},
"scripts": {
"build": "yarn build:lib && yarn build:nbextension && yarn build:labextension:dev",
Expand All @@ -36,29 +37,29 @@
"publish-pypi": "yarn build && python3 -m build && python3 -m twine upload dist/*.whl dist/*.gz "
},
"dependencies": {
"@jupyterlab/application": "^3",
"@jupyterlab/docregistry": "^3",
"@jupyterlab/notebook": "^3",
"@jupyterlab/rendermime": "^3",
"@jupyterlab/services": "^6",
"@lumino/disposable": "^1",
"@lumino/widgets": "^1",
"@jupyterlab/application": "^4.0.6",
"@jupyterlab/docregistry": "^4.0.6",
"@jupyterlab/notebook": "^4.0.6",
"@jupyterlab/rendermime": "^4.0.6",
"@jupyterlab/services": "^7.0.6",
"@lumino/disposable": "^2.0.0",
"@lumino/widgets": "^2.0.1",
"@webio/webio": "portal:../packages/webio",
"debug": "^4.3.2"
},
"devDependencies": {
"@jupyterlab/builder": "^3.1.0",
"@jupyterlab/builder": "^4.0.0",
"@types/debug": "^4.1.7",
"@types/react": "^17.0.20",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"@types/react": "^18.0.26",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"rimraf": "^3.0.2",
"typescript": "~4.1.3",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"typescript": "~5.0.2",
"webpack": "^5.52.0",
"webpack-cli": "^4.8.0"
},
Expand All @@ -69,7 +70,7 @@
"jupyter-releaser": {
"hooks": {
"before-build-npm": [
"python -m pip install jupyterlab~=3.1",
"python -m pip install jupyterlab~=4.0",
"yarn"
]
}
Expand Down
98 changes: 88 additions & 10 deletions webio_jupyter_extension/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,95 @@
[build-system]
requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1"]
build-backend = "jupyter_packaging.build_api"
requires = [
"hatchling>=1.5.0",
"jupyterlab>=4.0.0,<5",
"hatch-nodejs-version>=0.3.2"
]
build-backend = "hatchling.build"

[tool.jupyter-packaging.options]
skip-if-exists = ["webio_jupyter_extension/labextension/static/style.js"]
ensured-targets = ["webio_jupyter_extension/labextension/static/style.js", "webio_jupyter_extension/labextension/package.json"]
[project]
name = "webio-jupyter-extension"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.8"
classifiers = [
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
"Framework :: Jupyter :: JupyterLab :: 4",
"Framework :: Jupyter :: JupyterLab :: Extensions",
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"jupyter_server>=2.0.1,<3"
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

[tool.jupyter-packaging.builder]
factory = "jupyter_packaging.npm_builder"
[tool.hatch.version]
source = "nodejs"

[tool.jupyter-packaging.build-args]
[tool.hatch.metadata.hooks.nodejs]
fields = ["description", "authors", "urls"]

[tool.hatch.build.targets.wheel.shared-data]
"install.json" = "share/jupyter/labextensions/webio-jupyterlab-provider/install.json"
"webio_jupyter_extension/labextension" = "share/jupyter/labextensions/webio-jupyterlab-provider"
"webio_jupyter_extension/nbextension" = "share/jupyter/nbextensions/webio-jupyter-nbextension"
"jupyter-config/notebook-config" = "etc/jupyter/nbconfig/notebook.d"
"jupyter-config/server-config" = "etc/jupyter/jupyter_server_config.d"
"jupyter-config/nb-config" = "etc/jupyter/jupyter_notebook_config.d"

[tool.hatch.build.targets.sdist]
exclude = [".github", "binder"]
artifacts = [
"webio_jupyter_extension/labextension",
"webio_jupyter_extension/nbextension"
]

[tool.hatch.build.hooks.version]
path = "webio_jupyter_extension/_version.py"

[tool.hatch.build.hooks.jupyter-builder]
dependencies = [
"hatch-jupyter-builder>=0.8.1",
]
build-function = "hatch_jupyter_builder.npm_builder"
ensured-targets = [
"webio_jupyter_extension/labextension/static/style.js",
"webio_jupyter_extension/labextension/package.json",
]
skip-if-exists = [
"webio_jupyter_extension/labextension/static/style.js",
]

[tool.hatch.build.hooks.jupyter-builder.editable-build-kwargs]
build_dir = "webio_jupyter_extension/labextension"
source_dir = "webio-jupyter-labextension"
build_cmd = "install:extension"
npm = [
"jlpm",
]

[tool.hatch.build.hooks.jupyter-builder.build-kwargs]
build_cmd = "build:prod"
npm = ["jlpm"]

[tool.check-manifest]
ignore = ["webio_jupyter_extension/labextension/**", "yarn.lock", ".*", "package-lock.json"]
[tool.jupyter-releaser.options]
version_cmd = "hatch version"

[tool.jupyter-releaser.hooks]
before-build-npm = [
"python -m pip install 'jupyterlab>=4.0.0,<5'",
"jlpm",
"jlpm build:prod"
]
before-build-python = ["jlpm clean:all"]

[tool.check-wheel-contents]
ignore = ["W002"]
98 changes: 3 additions & 95 deletions webio_jupyter_extension/setup.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,3 @@
"""
webio_jupyter_extension setup
"""
import json
import sys
from pathlib import Path

import setuptools

HERE = Path(__file__).parent.resolve()

# The name of the project
name = "webio_jupyter_extension"

lab_path = (HERE / name.replace("-", "_") / "labextension")
nbextension_path = (HERE / name.replace("-", "_") / "nbextension")

# Representative files that should exist after a successful build
ensured_targets = [
str(lab_path / "package.json"),
str(lab_path / "static/style.js")
]

# Get the package info from package.json
pkg_json = json.loads((HERE / "package.json").read_bytes())
labext_name = pkg_json["name"]

data_files_spec = [
# labextension files
(f"share/jupyter/labextensions/{labext_name}", str("."), "install.json"),
(f"share/jupyter/labextensions/{labext_name}", str(lab_path.relative_to(HERE)), "**"),

# nbextension files
('share/jupyter/nbextensions/webio-jupyter-nbextension', str(nbextension_path.relative_to(HERE)), '**'),
('etc/jupyter/nbconfig/notebook.d' , "jupyter-config/notebook-config", 'webio-jupyter-nbextension.json'),

# serverextension files
("etc/jupyter/jupyter_server_config.d", "jupyter-config/server-config", f"{name}.json"),
# For backward compatibility with notebook server
("etc/jupyter/jupyter_notebook_config.d", "jupyter-config/nb-config", f"{name}.json"),
]

long_description = (HERE / "README.md").read_text()


setup_args = dict(
name=name,
version=pkg_json["version"],
description=pkg_json["description"],
license=pkg_json["license"],
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
install_requires=[],
zip_safe=False,
include_package_data=True,
python_requires=">=3.6",
platforms="Linux, Mac OS X, Windows",
keywords=["Jupyter", "JupyterLab", "JupyterLab3"],
classifiers=[
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
"Framework :: Jupyter :: JupyterLab :: 3",
"Framework :: Jupyter :: JupyterLab :: Extensions",
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
],
)

try:
from jupyter_packaging import (
wrap_installers,
npm_builder,
get_data_files
)
post_develop = npm_builder(
build_cmd="install:extension", source_dir="src", build_dir=lab_path
)
setup_args["cmdclass"] = wrap_installers(post_develop=post_develop, ensured_targets=ensured_targets)
setup_args["data_files"] = get_data_files(data_files_spec)
except ImportError as e:
import logging
logging.basicConfig(format="%(levelname)s: %(message)s")
logging.warning("Build tool `jupyter-packaging` is missing. Install it with pip or conda.")
if not ("--name" in sys.argv or "--version" in sys.argv):
raise e

if __name__ == "__main__":
setuptools.setup(**setup_args)
# setup.py shim for use with versions of JupyterLab that require
# it for extensions.
__import__("setuptools").setup()
8 changes: 1 addition & 7 deletions webio_jupyter_extension/webio_jupyter_extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@

from ._version import __version__

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"]
"dest": "webio-jupyterlab-provider"
}]


Expand Down
22 changes: 4 additions & 18 deletions webio_jupyter_extension/webio_jupyter_extension/_version.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import json
from pathlib import Path

__all__ = ["__version__"]

def _fetchVersion():
HERE = Path(__file__).parent.resolve()

for settings in HERE.rglob("package.json"):
try:
with settings.open() as f:
return json.load(f)["version"]
except FileNotFoundError:
pass

raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}")

__version__ = _fetchVersion()
# This file is auto-generated by Hatchling. As such, do not:
# - modify
# - track in version control e.g. be sure to add to .gitignore
__version__ = VERSION = '0.2.0'

0 comments on commit cdc664b

Please sign in to comment.