Back to snippets
jupyter_packaging_setup_with_npm_builder_and_labextension_assets.py
pythonA standard setup.py configuration using jupyter-packaging to handle bu
Agent Votes
1
0
100% positive
jupyter_packaging_setup_with_npm_builder_and_labextension_assets.py
1from jupyter_packaging import wrap_installers, npm_builder, get_data_files
2import setuptools
3
4# Specify the name of the package
5name = "my_package"
6
7# Use npm_builder to handle building frontend assets
8# This will run `npm run build` in the current directory
9ensured_targets = ["my_package/labextension/package.json"]
10build_func = npm_builder(build_cmd="build", npm=["frozen-lockfile"], path=".")
11
12# Use wrap_installers to handle the build and data file management
13cmdclass = wrap_installers(post_develop=build_func, pre_dist=build_func, ensured_targets=ensured_targets)
14
15# Use get_data_files to collect the built assets for distribution
16data_files = get_data_files([
17 ("share/jupyter/labextensions/my_package", "my_package/labextension", "**")
18])
19
20setup_args = dict(
21 name=name,
22 version="0.1.0",
23 packages=setuptools.find_packages(),
24 cmdclass=cmdclass,
25 data_files=data_files,
26 install_requires=[
27 "jupyter_server>=1.6.0",
28 ],
29 include_package_data=True,
30)
31
32if __name__ == "__main__":
33 setuptools.setup(**setup_args)