setup.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/themes', '%s/themes' % NAME, '**'),
  26. ('etc/jupyter/jupyter_notebook_config.d',
  27. 'jupyter-config/jupyter_notebook_config.d', 'jupyterlab.json'),
  28. ]
  29. package_data_spec = dict()
  30. package_data_spec[NAME] = [
  31. 'staging/*', 'staging/templates/*', 'staging/.yarnrc',
  32. 'static/**', 'tests/mock_packages/**', 'themes/**', 'schemas/**', '*.js'
  33. ]
  34. def exclude(filename):
  35. """Exclude JavaScript map files"""
  36. return filename.endswith('.js.map')
  37. staging = pjoin(HERE, NAME, 'staging')
  38. npm = ['node', pjoin(staging, 'yarn.js')]
  39. VERSION = get_version('%s/_version.py' % NAME)
  40. def check_assets():
  41. from distutils.version import LooseVersion
  42. # Representative files that should exist after a successful build
  43. targets = [
  44. 'static/package.json',
  45. 'schemas/@jupyterlab/shortcuts-extension/shortcuts.json',
  46. 'themes/@jupyterlab/theme-light-extension/index.css'
  47. ]
  48. for t in targets:
  49. if not os.path.exists(pjoin(HERE, NAME, t)):
  50. msg = ('Missing file: %s, `build:prod` script did not complete '
  51. 'successfully' % t)
  52. raise ValueError(msg)
  53. if 'sdist' not in sys.argv and 'bdist_wheel' not in sys.argv:
  54. return
  55. target = pjoin(HERE, NAME, 'static', 'package.json')
  56. with open(target) as fid:
  57. version = json.load(fid)['jupyterlab']['version']
  58. if LooseVersion(version) != LooseVersion(VERSION):
  59. raise ValueError('Version mismatch, please run `build:update`')
  60. cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec,
  61. package_data_spec=package_data_spec, exclude=exclude)
  62. cmdclass['jsdeps'] = combine_commands(
  63. install_npm(build_cmd='build:prod', path=staging, source_dir=staging,
  64. build_dir=pjoin(HERE, NAME, 'static'), npm=npm),
  65. command_for_func(check_assets)
  66. )
  67. class JupyterlabDevelop(develop):
  68. """A custom develop command that runs yarn"""
  69. def run(self):
  70. if not skip_npm:
  71. if not which('node'):
  72. error_message = """
  73. Please install nodejs and npm before continuing installation.
  74. nodejs may be installed using conda or directly from: https://nodejs.org/
  75. """
  76. log.error(error_message)
  77. return
  78. run(npm, cwd=HERE)
  79. develop.run(self)
  80. # Use default develop - we can ensure core mode later if needed.
  81. cmdclass['develop'] = JupyterlabDevelop
  82. setup_args = dict(
  83. name=NAME,
  84. description=DESCRIPTION,
  85. long_description=LONG_DESCRIPTION,
  86. long_description_content_type='text/markdown',
  87. version=VERSION,
  88. packages=find_packages(),
  89. cmdclass=cmdclass,
  90. author='Jupyter Development Team',
  91. author_email='jupyter@googlegroups.com',
  92. url='http://jupyter.org',
  93. license='BSD',
  94. platforms='Linux, Mac OS X, Windows',
  95. keywords=['ipython', 'jupyter', 'Web'],
  96. classifiers=[
  97. 'Development Status :: 5 - Production/Stable',
  98. 'Intended Audience :: Developers',
  99. 'Intended Audience :: System Administrators',
  100. 'Intended Audience :: Science/Research',
  101. 'License :: OSI Approved :: BSD License',
  102. 'Programming Language :: Python',
  103. 'Programming Language :: Python :: 3',
  104. 'Programming Language :: Python :: 3.5',
  105. 'Programming Language :: Python :: 3.6',
  106. 'Programming Language :: Python :: 3.7',
  107. ],
  108. )
  109. setup_args['install_requires'] = [
  110. 'notebook>=4.3.1',
  111. 'tornado!=6.0.0, !=6.0.1, !=6.0.2',
  112. 'jupyterlab_server>=1.1.0',
  113. 'jinja2>=2.10'
  114. ]
  115. setup_args['extras_require'] = {
  116. 'test': [
  117. 'pytest',
  118. 'pytest-check-links',
  119. 'requests',
  120. 'wheel',
  121. 'virtualenv'
  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. 'jlpm = jupyterlab.jlpmapp:main',
  140. ]
  141. }
  142. if __name__ == '__main__':
  143. setup(**setup_args)