setup.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 sys
  9. # Our own imports
  10. from setupbase import (
  11. create_cmdclass, ensure_python, find_packages, get_version,
  12. command_for_func, combine_commands, install_npm, HERE, run,
  13. skip_npm, which, log
  14. )
  15. from setuptools import setup
  16. from setuptools.command.develop import develop
  17. NAME = 'jupyterlab'
  18. DESCRIPTION = 'The JupyterLab notebook server extension.'
  19. with open(pjoin(HERE, 'README.md')) as fid:
  20. LONG_DESCRIPTION = fid.read()
  21. ensure_python(['>=3.5'])
  22. data_files_spec = [
  23. ('share/jupyter/lab/static', '%s/static' % NAME, '**'),
  24. ('share/jupyter/lab/schemas', '%s/schemas' % NAME, '**'),
  25. ('share/jupyter/lab/listings', '%s/listings' % NAME, '**'),
  26. ('share/jupyter/lab/themes', '%s/themes' % NAME, '**'),
  27. ('etc/jupyter/jupyter_notebook_config.d',
  28. 'jupyter-config/jupyter_notebook_config.d', 'jupyterlab.json'),
  29. ]
  30. package_data_spec = dict()
  31. package_data_spec[NAME] = [
  32. 'staging/*', 'staging/templates/*', 'static/**', 'tests/mock_packages/**',
  33. 'themes/**', 'schemas/**', 'listings/**', '*.js'
  34. ]
  35. def exclude(filename):
  36. """Exclude JavaScript map files"""
  37. return filename.endswith('.js.map')
  38. staging = pjoin(HERE, NAME, 'staging')
  39. npm = ['node', pjoin(staging, 'yarn.js')]
  40. VERSION = get_version('%s/_version.py' % NAME)
  41. def check_assets():
  42. from distutils.version import LooseVersion
  43. # Representative files that should exist after a successful build
  44. targets = [
  45. 'static/package.json',
  46. 'schemas/@jupyterlab/shortcuts-extension/shortcuts.json',
  47. 'listings/@jupyterlab/extensionmanager-extension/listings.json',
  48. 'themes/@jupyterlab/theme-light-extension/index.css'
  49. ]
  50. for t in targets:
  51. if not os.path.exists(pjoin(HERE, NAME, t)):
  52. msg = ('Missing file: %s, `build:prod` script did not complete '
  53. 'successfully' % t)
  54. raise ValueError(msg)
  55. if 'sdist' not in sys.argv and 'bdist_wheel' not in sys.argv:
  56. return
  57. target = pjoin(HERE, NAME, 'static', 'package.json')
  58. with open(target) as fid:
  59. version = json.load(fid)['jupyterlab']['version']
  60. if LooseVersion(version) != LooseVersion(VERSION):
  61. raise ValueError('Version mismatch, please run `build:update`')
  62. cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec,
  63. package_data_spec=package_data_spec, exclude=exclude)
  64. cmdclass['jsdeps'] = combine_commands(
  65. install_npm(build_cmd='build:prod', path=staging, source_dir=staging,
  66. build_dir=pjoin(HERE, NAME, 'static'), npm=npm),
  67. command_for_func(check_assets)
  68. )
  69. class JupyterlabDevelop(develop):
  70. """A custom develop command that runs yarn"""
  71. def run(self):
  72. if not skip_npm:
  73. if not which('node'):
  74. error_message = """
  75. Please install nodejs and npm before continuing installation.
  76. nodejs may be installed using conda or directly from: https://nodejs.org/
  77. """
  78. log.error(error_message)
  79. return
  80. run(npm, cwd=HERE)
  81. develop.run(self)
  82. # Use default develop - we can ensure core mode later if needed.
  83. cmdclass['develop'] = JupyterlabDevelop
  84. setup_args = dict(
  85. name=NAME,
  86. description=DESCRIPTION,
  87. long_description=LONG_DESCRIPTION,
  88. long_description_content_type='text/markdown',
  89. version=VERSION,
  90. packages=find_packages(),
  91. cmdclass=cmdclass,
  92. author='Jupyter Development Team',
  93. author_email='jupyter@googlegroups.com',
  94. url='http://jupyter.org',
  95. license='BSD',
  96. platforms='Linux, Mac OS X, Windows',
  97. keywords=['ipython', 'jupyter', 'Web'],
  98. classifiers=[
  99. 'Development Status :: 5 - Production/Stable',
  100. 'Intended Audience :: Developers',
  101. 'Intended Audience :: System Administrators',
  102. 'Intended Audience :: Science/Research',
  103. 'License :: OSI Approved :: BSD License',
  104. 'Programming Language :: Python',
  105. 'Programming Language :: Python :: 3',
  106. 'Programming Language :: Python :: 3.5',
  107. 'Programming Language :: Python :: 3.6',
  108. 'Programming Language :: Python :: 3.7',
  109. ],
  110. )
  111. setup_args['install_requires'] = [
  112. 'notebook>=4.3.1',
  113. 'tornado!=6.0.0, !=6.0.1, !=6.0.2',
  114. 'jupyterlab_server@ git+https://github.com/datalayer-contrib/jupyterlab-server@bw-list',
  115. 'jinja2>=2.10'
  116. ]
  117. setup_args['extras_require'] = {
  118. 'test': [
  119. 'pytest',
  120. 'pytest-check-links',
  121. 'requests'
  122. ],
  123. 'docs': [
  124. 'sphinx',
  125. 'recommonmark',
  126. 'sphinx_rtd_theme',
  127. 'sphinx-copybutton'
  128. ],
  129. }
  130. setup_args['package_data'] = package_data_spec
  131. setup_args['include_package_data'] = True
  132. setup_args['python_requires'] = '>=3.5'
  133. # Force entrypoints with setuptools (needed for Windows, unconditional
  134. # because of wheels)
  135. setup_args['entry_points'] = {
  136. 'console_scripts': [
  137. 'jupyter-lab = jupyterlab.labapp:main',
  138. 'jupyter-labextension = jupyterlab.labextensions:main',
  139. 'jupyter-labhub = jupyterlab.labhubapp:main',
  140. 'jlpm = jupyterlab.jlpmapp:main',
  141. ]
  142. }
  143. if __name__ == '__main__':
  144. setup(**setup_args)