setup.py 5.3 KB

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