setup.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 jupyter_packaging import (
  11. create_cmdclass, get_version,
  12. command_for_func, combine_commands, install_npm, run,
  13. skip_npm, which, log
  14. )
  15. from setuptools import setup, find_packages
  16. from setuptools.command.develop import develop
  17. HERE = os.path.abspath(os.path.dirname(__file__))
  18. NAME = 'jupyterlab'
  19. DESCRIPTION = 'The JupyterLab server extension.'
  20. with open(pjoin(HERE, 'README.md')) as fid:
  21. LONG_DESCRIPTION = fid.read()
  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_server_config.d',
  27. 'jupyter-config/jupyter_server_config.d', 'jupyterlab.json'),
  28. ('etc/jupyter/jupyter_notebook_config.d',
  29. 'jupyter-config/jupyter_notebook_config.d', 'jupyterlab.json'),
  30. ]
  31. package_data_spec = dict()
  32. package_data_spec[NAME] = [
  33. 'staging/*', 'staging/templates/*', 'staging/.yarnrc',
  34. 'static/**', 'tests/mock_packages/**', 'themes/**', 'schemas/**', '*.js'
  35. ]
  36. def exclude(filename):
  37. """Exclude JavaScript map files"""
  38. return filename.endswith('.js.map')
  39. staging = pjoin(HERE, NAME, 'staging')
  40. npm = ['node', pjoin(staging, 'yarn.js')]
  41. VERSION = get_version('%s/_version.py' % NAME)
  42. def check_assets():
  43. from packaging.version import Version
  44. # Representative files that should exist after a successful build
  45. targets = [
  46. 'static/package.json',
  47. 'schemas/@jupyterlab/shortcuts-extension/shortcuts.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 Version(version) != Version(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. python_requires=">=3.6",
  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.6',
  108. 'Programming Language :: Python :: 3.7',
  109. 'Programming Language :: Python :: 3.8',
  110. ],
  111. )
  112. setup_args['install_requires'] = [
  113. 'ipython',
  114. 'packaging',
  115. 'tornado>=6.1.0',
  116. 'jupyter_core',
  117. 'jupyterlab_server~=2.0',
  118. 'jupyter_server~=1.1',
  119. 'nbclassic~=0.2',
  120. 'jinja2>=2.10'
  121. ]
  122. setup_args['extras_require'] = {
  123. 'test': [
  124. 'pytest>=6.0',
  125. 'pytest-cov',
  126. 'pytest-console-scripts',
  127. 'pytest-check-links',
  128. 'jupyterlab_server[test]~=2.0',
  129. 'requests',
  130. 'wheel',
  131. 'virtualenv'
  132. ],
  133. 'test:sys_platform == "win32"': ['nose-exclude'],
  134. 'docs': [
  135. 'jsx-lexer',
  136. 'recommonmark',
  137. 'sphinx',
  138. 'sphinx_rtd_theme',
  139. 'sphinx-copybutton'
  140. ],
  141. }
  142. setup_args['package_data'] = package_data_spec
  143. setup_args['include_package_data'] = True
  144. setup_args['python_requires'] = '>=3.6'
  145. # Force entrypoints with setuptools (needed for Windows, unconditional
  146. # because of wheels)
  147. setup_args['entry_points'] = {
  148. 'console_scripts': [
  149. 'jupyter-lab = jupyterlab.labapp:main',
  150. 'jupyter-labextension = jupyterlab.labextensions:main',
  151. 'jupyter-labhub = jupyterlab.labhubapp:main',
  152. 'jlpm = jupyterlab.jlpmapp:main',
  153. ]
  154. }
  155. if __name__ == '__main__':
  156. setup(**setup_args)