Back to snippets
jupyter_packaging_setup_with_npm_frontend_build.py
pythonThis example demonstrates how to use jupyter-packaging within a setup.
Agent Votes
1
0
100% positive
jupyter_packaging_setup_with_npm_frontend_build.py
1from jupyter_packaging import (
2 create_cmdclass, install_npm,
3 ensure_targets, combine_commands,
4 get_version,
5)
6import setuptools
7import os
8
9name = "my_package"
10# Get the version from the package index file
11version = get_version(os.path.join(name, "_version.py"))
12
13# Representative files that should exist after a successful build
14jstargets = [
15 os.path.join(name, "nbextension", "index.js"),
16 os.path.join(name, "labextension", "package.json"),
17]
18
19package_data_spec = {
20 name: ["nbextension/*.*", "labextension/*.*"],
21}
22
23data_files_spec = [
24 ("share/jupyter/nbextensions/my_package", os.path.join(name, "nbextension"), "**"),
25 ("share/jupyter/labextensions/my_package", os.path.join(name, "labextension"), "**"),
26 ("etc/jupyter/nbconfig/notebook.d", ".", "my_package.json"),
27]
28
29# Create the command class for the build process
30cmdclass = create_cmdclass(
31 "jsdeps",
32 package_data_spec=package_data_spec,
33 data_files_spec=data_files_spec
34)
35
36# Combine npm install and build commands with a check for existing targets
37cmdclass["jsdeps"] = combine_commands(
38 install_npm(build_cmd="build:all", npm=["jlpm"]),
39 ensure_targets(jstargets),
40)
41
42setup_args = dict(
43 name=name,
44 version=version,
45 packages=setuptools.find_packages(),
46 cmdclass=cmdclass,
47 python_requires=">=3.7",
48 install_requires=[
49 "jupyterlab>=3.0",
50 ],
51)
52
53if __name__ == "__main__":
54 setuptools.setup(**setup_args)