Jupyter Packaging Utilities
Jupyter Packaging provides utility functions and `setuptools` build command classes to simplify the packaging of Jupyter applications and extensions, particularly those with front-end (JavaScript/TypeScript) assets. It helps integrate pre-build steps into the Python packaging process. The current version is 0.12.3, and it typically sees releases for bug fixes, maintenance, and enhancements related to packaging standards and dependencies.
Warnings
- breaking When upgrading `setuptools` to version 61.0.0 or higher, projects using `jupyter-packaging` versions prior to 0.12.0 may encounter `ImportError` due to a change in the internal import path for `bdist_wheel`.
- deprecated Support for Python 3.6 was dropped with the release of `jupyter-packaging` 0.11.0.
- gotcha Building Jupyter extensions with front-end assets typically requires Node.js and a package manager (npm or yarn) to be installed and available in the system's PATH, as `jupyter-packaging` will execute these tools.
- gotcha `jupyter-packaging` is primarily intended as a *build-time* dependency, not a *runtime* dependency. It should be listed in `build-system.requires` in `pyproject.toml` rather than `install_requires` in `setup.py` or `dependencies` in `pyproject.toml` for most projects.
- gotcha `jupyter-packaging` does not support the deprecated `python setup.py bdist_wheel` or `python setup.py sdist` commands directly. The recommended approach for building distributions is to use the `build` package.
- gotcha Setuptools' `data_files` (often used for Jupyter configuration files) are not fully supported in editable (`pip install -e .`) mode.
Install
-
pip install jupyter-packaging
Imports
- wrap_installers
from jupyter_packaging import wrap_installers
- npm_builder
from jupyter_packaging import npm_builder
- bdist_wheel
from setuptools.command.bdist_wheel import bdist_wheel
Quickstart
from setuptools import setup
try:
from jupyter_packaging import wrap_installers, npm_builder
# Define the builder for npm commands
# Assumes a package.json in the root that defines 'build' and 'build:dev' scripts
builder = npm_builder(build_cmd='build', develop_cmd='build:dev')
# Wrap the 'install' and 'develop' commands with the npm builder
cmdclass = wrap_installers(pre_develop=builder, pre_dist=builder)
except ImportError:
# Fallback for when jupyter_packaging is not available (e.g., during sdist build)
cmdclass = {}
setup(
name='my_jupyter_extension',
version='0.1.0',
cmdclass=cmdclass,
# Other setup arguments like packages, include_package_data, etc.
packages=['my_jupyter_extension'],
include_package_data=True,
# Make sure to include MANIFEST.in for data files not in Python packages
# (e.g., JS/CSS assets, Jupyter config files)
)