Jupyter Packaging Utilities

0.12.3 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `jupyter-packaging` into a `setup.py` file to handle front-end build steps for a Jupyter extension. It uses `npm_builder` to define pre-build commands for both development (`develop`) and distribution (`dist`) modes, ensuring that JavaScript/TypeScript assets are compiled before the Python package is installed or built. The `try/except ImportError` block allows the `setup.py` to be run even if `jupyter-packaging` is not installed, which can be useful during initial `sdist` creation or local testing.

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)
)

view raw JSON →