setup.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. pass
  59. cmdclass = wrap_installers(
  60. post_develop=post_develop, post_dist=post_dist, ensured_targets=ensured_targets
  61. )
  62. else:
  63. cmdclass = wrap_installers(
  64. post_dist=post_dist, ensured_targets=ensured_targets)
  65. setup_args = dict(
  66. cmdclass=cmdclass,
  67. data_files=get_data_files(data_files_spec)
  68. )
  69. except ImportError:
  70. setup_args = dict()
  71. if __name__ == "__main__":
  72. setup(**setup_args)