setup.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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, 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. min_version = (3, 6)
  18. if sys.version_info < min_version:
  19. error = """
  20. Python {0} or above is required, you are using Python {1}.
  21. This may be due to an out of date pip.
  22. Make sure you have pip >= 9.0.1.
  23. """.format('.'.join(str(n) for n in min_version),
  24. '.'.join(str(n) for n in sys.version_info[:3]))
  25. sys.exit(error)
  26. NAME = 'jupyterlab'
  27. DESCRIPTION = 'The JupyterLab server extension.'
  28. with open(pjoin(HERE, 'README.md')) as fid:
  29. LONG_DESCRIPTION = fid.read()
  30. data_files_spec = [
  31. ('share/jupyter/lab/static', '%s/static' % NAME, '**'),
  32. ('share/jupyter/lab/schemas', '%s/schemas' % NAME, '**'),
  33. ('share/jupyter/lab/themes', '%s/themes' % NAME, '**'),
  34. ('etc/jupyter/jupyter_server_config.d',
  35. 'jupyter-config/jupyter_server_config.d', 'jupyterlab.json'),
  36. ]
  37. package_data_spec = dict()
  38. package_data_spec[NAME] = [
  39. 'staging/*', 'staging/templates/*', 'staging/.yarnrc',
  40. 'static/**', 'tests/mock_packages/**', 'themes/**', 'schemas/**', '*.js'
  41. ]
  42. def exclude(filename):
  43. """Exclude JavaScript map files"""
  44. return filename.endswith('.js.map')
  45. staging = pjoin(HERE, NAME, 'staging')
  46. npm = ['node', pjoin(staging, 'yarn.js')]
  47. VERSION = get_version('%s/_version.py' % NAME)
  48. def check_assets():
  49. from distutils.version import LooseVersion
  50. # Representative files that should exist after a successful build
  51. targets = [
  52. 'static/package.json',
  53. 'schemas/@jupyterlab/shortcuts-extension/shortcuts.json',
  54. 'themes/@jupyterlab/theme-light-extension/index.css'
  55. ]
  56. for t in targets:
  57. if not os.path.exists(pjoin(HERE, NAME, t)):
  58. msg = ('Missing file: %s, `build:prod` script did not complete '
  59. 'successfully' % t)
  60. raise ValueError(msg)
  61. if 'sdist' not in sys.argv and 'bdist_wheel' not in sys.argv:
  62. return
  63. target = pjoin(HERE, NAME, 'static', 'package.json')
  64. with open(target) as fid:
  65. version = json.load(fid)['jupyterlab']['version']
  66. if LooseVersion(version) != LooseVersion(VERSION):
  67. raise ValueError('Version mismatch, please run `build:update`')
  68. cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec,
  69. package_data_spec=package_data_spec, exclude=exclude)
  70. cmdclass['jsdeps'] = combine_commands(
  71. install_npm(build_cmd='build:prod', path=staging, source_dir=staging,
  72. build_dir=pjoin(HERE, NAME, 'static'), npm=npm),
  73. command_for_func(check_assets)
  74. )
  75. class JupyterlabDevelop(develop):
  76. """A custom develop command that runs yarn"""
  77. def run(self):
  78. if not skip_npm:
  79. if not which('node'):
  80. error_message = """
  81. Please install nodejs and npm before continuing installation.
  82. nodejs may be installed using conda or directly from: https://nodejs.org/
  83. """
  84. log.error(error_message)
  85. return
  86. run(npm, cwd=HERE)
  87. develop.run(self)
  88. # Use default develop - we can ensure core mode later if needed.
  89. cmdclass['develop'] = JupyterlabDevelop
  90. setup_args = dict(
  91. name=NAME,
  92. description=DESCRIPTION,
  93. long_description=LONG_DESCRIPTION,
  94. long_description_content_type='text/markdown',
  95. version=VERSION,
  96. packages=find_packages(),
  97. cmdclass=cmdclass,
  98. author='Jupyter Development Team',
  99. author_email='jupyter@googlegroups.com',
  100. url='http://jupyter.org',
  101. license='BSD',
  102. platforms='Linux, Mac OS X, Windows',
  103. keywords=['ipython', 'jupyter', 'Web'],
  104. classifiers=[
  105. 'Development Status :: 5 - Production/Stable',
  106. 'Intended Audience :: Developers',
  107. 'Intended Audience :: System Administrators',
  108. 'Intended Audience :: Science/Research',
  109. 'License :: OSI Approved :: BSD License',
  110. 'Programming Language :: Python',
  111. 'Programming Language :: Python :: 3',
  112. 'Programming Language :: Python :: 3.6',
  113. 'Programming Language :: Python :: 3.7',
  114. 'Programming Language :: Python :: 3.8',
  115. ],
  116. )
  117. setup_args['install_requires'] = [
  118. 'ipython',
  119. 'tornado!=6.0.0, !=6.0.1, !=6.0.2',
  120. 'jupyterlab_server~=2.0.0b5',
  121. 'jupyter_server~=1.0.0rc13',
  122. 'nbclassic~=0.2.0rc4',
  123. 'jinja2>=2.10'
  124. ]
  125. setup_args['extras_require'] = {
  126. 'test': [
  127. 'pytest==5.3.2',
  128. 'pytest-cov',
  129. 'pytest-tornasync',
  130. 'pytest-console-scripts',
  131. 'pytest-check-links',
  132. 'requests',
  133. 'wheel',
  134. 'virtualenv'
  135. ],
  136. 'test:sys_platform == "win32"': ['nose-exclude'],
  137. 'docs': [
  138. 'jsx-lexer',
  139. 'recommonmark',
  140. 'sphinx',
  141. 'sphinx_rtd_theme',
  142. 'sphinx-copybutton'
  143. ],
  144. }
  145. setup_args['package_data'] = package_data_spec
  146. setup_args['include_package_data'] = True
  147. setup_args['python_requires'] = '>=3.6'
  148. # Force entrypoints with setuptools (needed for Windows, unconditional
  149. # because of wheels)
  150. setup_args['entry_points'] = {
  151. 'console_scripts': [
  152. 'jupyter-lab = jupyterlab.labapp:main',
  153. 'jupyter-labextension = jupyterlab.labextensions:main',
  154. 'jupyter-labhub = jupyterlab.labhubapp:main',
  155. 'jlpm = jupyterlab.jlpmapp:main',
  156. ],
  157. 'pytest11': [
  158. 'pytest_jupyterlab = jupyterlab.pytest_plugin'
  159. ],
  160. }
  161. if __name__ == '__main__':
  162. setup(**setup_args)