Package: jupyter-packaging
Jupyter PackagingTools to help build and install Jupyter Python packages that require a pre-build step that may include JavaScript build steps.Installpip install jupyter-packagingUsageThere are three ways to usejupyter-packagingin another package.
In general, you should not depend onjupyter_packagingas a runtime dependency, only as a build dependency.As a Build RequirementUse apyproject.tomlfile as outlined inpep-518.
An example:[build-system]requires=["jupyter_packaging>=0.10,<2"]build-backend="setuptools.build_meta"Below is an examplesetup.pyusing the above config.
It assumes the rest of your metadata is insetup.cfg.
We wrap the import in a try/catch to allow the file to be run withoutjupyter_packagingso thatpython setup.pycan be run directly when not building.fromsetuptoolsimportsetuptry:fromjupyter_packagingimportwrap_installers,npm_builderbuilder=npm_builder()cmdclass=wrap_installers(pre_develop=builder,pre_dist=builder)exceptImportError:cmdclass={}setup(cmdclass=cmdclass))As a Build BackendUse thejupyter_packagingbuild backend.
The pre-build command is specified as metadata inpyproject.toml:[build-system]requires=["jupyter_packaging>=0.10,<2"]build-backend="jupyter_packaging.build_api"[tool.jupyter-packaging.builder]factory="jupyter_packaging.npm_builder"[tool.jupyter-packaging.build-args]build_cmd="build:src"The correspondingsetup.pywould be greatly simplified:fromsetuptoolsimportsetupsetup()Thetool.jupyter-packaging.buildersection expects afuncvalue that points to an importable
module and a function with dot separators.  If not given, no pre-build function will run.The optionaltool.jupyter-packaging.build-argssections accepts a dict of keyword arguments to
give to the pre-build command.The build backend does not handle thedevelopcommand (pip install -e .).
If desired, you can wrap just that command:importsetuptoolstry:fromjupyter_packagingimportwrap_installers,npm_builderbuilder=npm_builder(build_cmd="build:dev")cmdclass=wrap_installers(pre_develop=builder)exceptImportError:cmdclass={}setup(cmdclass=cmdclass))The optionaltool.jupyter-packaging.optionssection accepts the following options:skip-if-exists: A list of local files whose presence causes the prebuild to skipensured-targets: A list of local file paths that should exist when the dist commands are runAs a Vendored FileVendorsetupbase.pylocally alongsidesetup.pyand import the module directly.importsetuptoolsfromsetupbaseimportwrap_installers,npm_builderfunc=npm_builder()cmdclass=wrap_installers(post_develop=func,pre_dist=func)setup(cmdclass=cmdclass)Usage NotesThis package does not work with the deprecatedpython setup.py bdist_wheelorpython setup.py sdistcommands, PyPA recommends using thebuildpackage (pip install build && python -m build .).We recommend usinginclude_package_data=TrueandMANIFEST.into control the assets included in thepackage.Tools likecheck-manifestormanifixcan be used to ensure the desired assets are included.Simple uses ofdata_filescan be handled insetup.cfgor insetup.py.  If recursive directories are needed useget_data_files()from this package.Unfortunatelydata_filesare not supported indevelopmode (a limitation ofsetuptools).  You can work around it by doing a full install (pip install .) before the develop install (pip install -e .), or by adding a script to push the data files tosys.base_prefix.Development Installgitclonehttps://github.com/jupyter/jupyter-packaging.gitcdjupyter-packaging
pipinstall-e.[test]pre-commitinstallYou can test changes locally by creating apyproject.tomlwith the following, replacing the local path to the git checkout:[build-system]requires=["jupyter_packaging@file://<path-to-git-checkout>"]build-backend="setuptools.build_meta"Note: you need to runpip cache remove jupyter_packagingany time changes are made to preventpipfrom using a cached version of the source.