setup.py 1.8 KB

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