setup.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. import json
  4. import os
  5. import os.path as osp
  6. import sys
  7. # Copyright (c) Jupyter Development Team.
  8. # Distributed under the terms of the Modified BSD License.
  9. from os.path import join as pjoin
  10. from setuptools import setup
  11. NAME = "jupyterlab"
  12. HERE = osp.dirname(osp.abspath(__file__))
  13. ensured_targets = [
  14. "static/package.json",
  15. "schemas/@jupyterlab/shortcuts-extension/shortcuts.json",
  16. "themes/@jupyterlab/theme-light-extension/index.css",
  17. ]
  18. ensured_targets = [osp.join(HERE, NAME, t) for t in ensured_targets]
  19. data_files_spec = [
  20. ("share/jupyter/lab/static", f"{NAME}/static", "**"),
  21. ("share/jupyter/lab/schemas", f"{NAME}/schemas", "**"),
  22. ("share/jupyter/lab/themes", f"{NAME}/themes", "**"),
  23. (
  24. "etc/jupyter/jupyter_server_config.d",
  25. "jupyter-config/jupyter_server_config.d",
  26. f"{NAME}.json",
  27. ),
  28. (
  29. "etc/jupyter/jupyter_notebook_config.d",
  30. "jupyter-config/jupyter_notebook_config.d",
  31. f"{NAME}.json",
  32. ),
  33. ]
  34. def post_dist():
  35. from jupyter_packaging import get_version
  36. from packaging.version import Version
  37. target = pjoin(HERE, NAME, "static", "package.json")
  38. with open(target) as fid:
  39. version = json.load(fid)["jupyterlab"]["version"]
  40. if Version(version) != Version(get_version(f"{NAME}/_version.py")):
  41. raise ValueError("Version mismatch, please run `build:update`")
  42. try:
  43. from jupyter_packaging import get_data_files, npm_builder, wrap_installers
  44. npm = ["node", pjoin(HERE, NAME, "staging", "yarn.js")]
  45. # In develop mode, just run yarn, unless this is an sdist.
  46. if os.path.exists(os.path.join(HERE, "buildutils")):
  47. builder = npm_builder(build_cmd=None, npm=npm, force=True)
  48. cmdclass = wrap_installers(
  49. post_develop=builder, post_dist=post_dist, ensured_targets=ensured_targets
  50. )
  51. else:
  52. cmdclass = wrap_installers(post_dist=post_dist, ensured_targets=ensured_targets)
  53. setup_args = dict(
  54. cmdclass=cmdclass,
  55. data_files=get_data_files(data_files_spec)
  56. )
  57. except ImportError:
  58. setup_args = dict()
  59. if __name__ == "__main__":
  60. setup(**setup_args)