setup.py 2.5 KB

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