浏览代码

Upgrade to Jupyter Packaging 0.9 (#10096)

Jeremy Tuloup 4 年之前
父节点
当前提交
f0790b3ffd
共有 7 个文件被更改,包括 115 次插入177 次删除
  1. 12 3
      MANIFEST.in
  2. 2 2
      dev_mode/package.json
  3. 17 4
      pyproject.toml
  4. 2 1
      scripts/ci_install.sh
  5. 3 0
      scripts/ci_script.sh
  6. 52 0
      setup.cfg
  7. 27 167
      setup.py

+ 12 - 3
MANIFEST.in

@@ -1,13 +1,16 @@
 include package.json
 include LICENSE
-include CONTRIBUTING.md
-include README.md
+include *.md
 include pyproject.toml
 include setup.py
+include setup.cfg
+include conftest.py
 
 # Documentation
 graft docs
 exclude docs/\#*
+prune docs/api
+prune docs/build
 
 # We must include the package_data files since include_package_data=True
 # See https://github.com/pypa/setuptools/issues/1461
@@ -15,10 +18,16 @@ include jupyterlab/staging/*
 include jupyterlab/staging/templates/*
 include jupyterlab/staging/.yarnrc
 graft jupyterlab/static
+graft jupyterlab
+graft jupyterlab/tests
 graft jupyterlab/tests/mock_packages
 graft jupyterlab/themes
 graft jupyterlab/schemas
+graft jupyter-config
 recursive-include jupyterlab *.js
 
-prune jupyterlab/staging/node_modules
+prune jupyterlab/**/node_modules
 prune jupyterlab/staging/build
+
+recursive-exclude jupyterlab *.pyc
+recursive-exclude jupyterlab *.js.map

+ 2 - 2
dev_mode/package.json

@@ -3,8 +3,8 @@
   "version": "3.1.0-alpha.4",
   "private": true,
   "scripts": {
-    "build": "jlpm run clean && webpack",
-    "build:dev": "jlpm run build",
+    "build": "npm run clean && webpack",
+    "build:dev": "npm run build",
     "build:prod": "webpack --config webpack.prod.config.js",
     "build:prod:minimize": "webpack --config webpack.prod.minimize.config.js",
     "build:prod:release": "webpack --config webpack.prod.release.config.js",

+ 17 - 4
pyproject.toml

@@ -1,6 +1,19 @@
 [build-system]
-requires=["setuptools", "wheel", "jupyter_packaging~=0.7.3"]
-build-backend = "setuptools.build_meta"
+requires=["jupyter_packaging~=0.9"]
+build-backend = "jupyter_packaging.build_api"
+
+[license]
+file="LICENSE"
+
+[tool.jupyter-packaging.builder]
+factory = "jupyter_packaging.npm_builder"
+
+[tool.jupyter-packaging.build-args]
+build_cmd = "build:prod:minimize"
+path = "jupyterlab/staging"
+source_dir= "jupyterlab/staging"
+build_dir = "jupyterlab/static"
+npm = ["node", "yarn.js"]
 
 [tool.pytest.ini_options]
 testpaths="jupyterlab/tests"
@@ -8,5 +21,5 @@ norecursedirs="node_modules .git _build"
 addopts="--pdbcls=IPython.terminal.debugger:Pdb -v --junitxml=junit.xml"
 ignore="tests examples"
 
-[license]
-file="LICENSE"
+[tool.check-manifest]
+ignore = ["binder/**", "builder/**", "buildutils/**", "design/**", "dev_mode/**", "examples/**", "packages/**", "scripts/**", "testutils/**", "*.json", "yarn.lock", "readthedocs.yml", ".bumpversion.cfg", ".*", "clean.py", "lint-staged.config.js", "release/*", "typedoc-theme/**", "typedoc.js", "jupyterlab/schemas/**", "jupyterlab/static/**", "jupyterlab/themes/**", "jupyterlab/style.js"]

+ 2 - 1
scripts/ci_install.sh

@@ -41,7 +41,8 @@ fi
 
 if [[ $GROUP == nonode ]]; then
     # Build the wheel
-    python setup.py bdist_wheel sdist
+    pip install build
+    python -m build .
 
     # Remove NodeJS, twice to take care of system and locally installed node versions.
     sudo rm -rf $(which node)

+ 3 - 0
scripts/ci_script.sh

@@ -102,6 +102,9 @@ if [[ $GROUP == integrity2 ]]; then
     # Run the integrity script to link binary files
     jlpm integrity
 
+    # Check the manifest
+    check-manifest -v
+
     # Build the packages individually.
     jlpm run build:src
 

+ 52 - 0
setup.cfg

@@ -0,0 +1,52 @@
+[metadata]
+name = jupyterlab
+version = attr: jupyterlab._version.__version__
+description = JupyterLab computational environment
+long_description = file: README.md
+long_description_content_type = text/markdown
+license_file = LICENSE
+author = Jupyter Development Team
+author_email = jupyter@googlegroups.com
+url = https://jupyter.org
+platforms = Linux, Mac OS X, Windows
+keywords = ipython, jupyter
+classifiers =
+    Development Status :: 5 - Production/Stable
+    Intended Audience :: Developers
+    Intended Audience :: System Administrators
+    Intended Audience :: Science/Research
+    License :: OSI Approved :: BSD License
+    Programming Language :: Python
+    Programming Language :: Python :: 3.6
+    Programming Language :: Python :: 3.7
+    Programming Language :: Python :: 3.8
+    Programming Language :: Python :: 3.9
+
+[options]
+zip_safe = False
+include_package_data = True
+packages = find:
+python_requires = >=3.6
+install_requires =
+    ipython
+    packaging
+    tornado>=6.1.0
+    jupyter_core
+    jupyter_packaging~=0.9
+    jupyterlab_server~=2.3
+    jupyter_server~=1.4
+    nbclassic~=0.2
+    jinja2>=2.1
+
+[options.extras_require]
+test = coverage; pytest>=6.0; pytest-cov; pytest-console-scripts; pytest-check-links>=0.5; jupyterlab_server[test]~=2.2; requests; requests_cache; virtualenv; check-manifest
+
+[options.entry_points]
+console_scripts =
+    jupyter-lab = jupyterlab.labapp:main
+    jupyter-labextension = jupyterlab.labextensions:main
+    jupyter-labhub = jupyterlab.labhubapp:main
+    jlpm = jupyterlab.jlpmapp:main
+
+[options.packages.find]
+exclude = ['docs*', 'examples*']

+ 27 - 167
setup.py

@@ -6,192 +6,52 @@
 from os.path import join as pjoin
 import json
 import os
+import os.path as osp
 import sys
 
-# Our own imports
-from jupyter_packaging import (
-    create_cmdclass, get_version,
-    command_for_func, combine_commands, install_npm, run,
-    skip_npm, which, log
-)
-
-from setuptools import setup, find_packages
-from setuptools.command.develop import develop
-
-
-HERE = os.path.abspath(os.path.dirname(__file__))
-
+from jupyter_packaging import wrap_installers, npm_builder, get_data_files, get_version
+from packaging.version import Version
+from setuptools import setup
 
-NAME = 'jupyterlab'
-DESCRIPTION = 'The JupyterLab server extension.'
+NAME = "jupyterlab"
+HERE = osp.dirname(osp.abspath(__file__))
 
-with open(pjoin(HERE, 'README.md')) as fid:
-    LONG_DESCRIPTION = fid.read()
-
-
-data_files_spec = [
-    ('share/jupyter/lab/static', '%s/static' % NAME, '**'),
-    ('share/jupyter/lab/schemas', '%s/schemas' % NAME, '**'),
-    ('share/jupyter/lab/themes', '%s/themes' % NAME, '**'),
-    ('etc/jupyter/jupyter_server_config.d',
-     'jupyter-config/jupyter_server_config.d', 'jupyterlab.json'),
-    ('etc/jupyter/jupyter_notebook_config.d',
-     'jupyter-config/jupyter_notebook_config.d', 'jupyterlab.json'),
+ensured_targets = [
+    'static/package.json',
+    'schemas/@jupyterlab/shortcuts-extension/shortcuts.json',
+    'themes/@jupyterlab/theme-light-extension/index.css'
 ]
+ensured_targets = [osp.join(HERE, NAME, t) for t in ensured_targets]
 
-package_data_spec = dict()
-package_data_spec[NAME] = [
-    'staging/*', 'staging/templates/*', 'staging/.yarnrc',
-    'static/**', 'tests/mock_packages/**', 'themes/**', 'schemas/**', '*.js'
-]
-
-
-def exclude(filename):
-    """Exclude JavaScript map files"""
-    return filename.endswith('.js.map')
-
-staging = pjoin(HERE, NAME, 'staging')
-npm = ['node', pjoin(staging, 'yarn.js')]
-VERSION = get_version('%s/_version.py' % NAME)
-
-
-def check_assets():
-    from packaging.version import Version
-
-    # Representative files that should exist after a successful build
-    targets = [
-        'static/package.json',
-        'schemas/@jupyterlab/shortcuts-extension/shortcuts.json',
-        'themes/@jupyterlab/theme-light-extension/index.css'
-    ]
-
-    for t in targets:
-        if not os.path.exists(pjoin(HERE, NAME, t)):
-            msg = ('Missing file: %s, `build:prod` script did not complete '
-                   'successfully' % t)
-            raise ValueError(msg)
-
-    if 'sdist' not in sys.argv and 'bdist_wheel' not in sys.argv:
-        return
 
+def post_dist():
     target = pjoin(HERE, NAME, 'static', 'package.json')
     with open(target) as fid:
         version = json.load(fid)['jupyterlab']['version']
 
-    if Version(version) != Version(VERSION):
+    if Version(version) != Version(get_version(f'{NAME}/_version.py')):
         raise ValueError('Version mismatch, please run `build:update`')
 
 
-cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec,
-                           package_data_spec=package_data_spec, exclude=exclude)
-cmdclass['jsdeps'] = combine_commands(
-    install_npm(build_cmd='build:prod', path=staging, source_dir=staging,
-                build_dir=pjoin(HERE, NAME, 'static'), npm=npm),
-    command_for_func(check_assets)
-)
-
-
-class JupyterlabDevelop(develop):
-    """A custom develop command that runs yarn"""
-
-    def run(self):
-        if not skip_npm:
-            if not which('node'):
-                error_message = """
-Please install nodejs and npm before continuing installation.
-nodejs may be installed using conda or directly from: https://nodejs.org/
-"""
-                log.error(error_message)
-                return
-            run(npm, cwd=HERE)
-        develop.run(self)
-
-
-# Use default develop - we can ensure core mode later if needed.
-cmdclass['develop'] = JupyterlabDevelop
+npm = ['node', pjoin(HERE, NAME, 'staging', 'yarn.js')]
+# In develop mode, just run yarn
+builder = npm_builder(build_cmd=None, npm=npm, force=True)
+cmdclass = wrap_installers(post_develop=builder, post_dist=post_dist, ensured_targets=ensured_targets)
 
+data_files_spec = [
+    ('share/jupyter/lab/static', f'{NAME}/static', '**'),
+    ('share/jupyter/lab/schemas', f'{NAME}/schemas', '**'),
+    ('share/jupyter/lab/themes', f'{NAME}/themes', '**'),
+    ('etc/jupyter/jupyter_server_config.d',
+     'jupyter-config/jupyter_server_config.d', f'{NAME}.json'),
+    ('etc/jupyter/jupyter_notebook_config.d',
+     'jupyter-config/jupyter_notebook_config.d', f'{NAME}.json'),
+]
 
 setup_args = dict(
-    name=NAME,
-    description=DESCRIPTION,
-    long_description=LONG_DESCRIPTION,
-    long_description_content_type='text/markdown',
-    version=VERSION,
-    packages=find_packages(),
     cmdclass=cmdclass,
-    author='Jupyter Development Team',
-    author_email='jupyter@googlegroups.com',
-    url='http://jupyter.org',
-    license='BSD',
-    platforms='Linux, Mac OS X, Windows',
-    keywords=['ipython', 'jupyter', 'Web'],
-    python_requires=">=3.6",
-    classifiers=[
-        'Development Status :: 5 - Production/Stable',
-        'Intended Audience :: Developers',
-        'Intended Audience :: System Administrators',
-        'Intended Audience :: Science/Research',
-        'License :: OSI Approved :: BSD License',
-        'Programming Language :: Python',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-    ],
+    data_files=get_data_files(data_files_spec)
 )
 
-
-setup_args['install_requires'] = [
-    'ipython',
-    'packaging',
-    'tornado>=6.1.0',
-    'jupyter_core',
-    'jupyter_packaging~=0.7',
-    'jupyterlab_server~=2.3',
-    'jupyter_server~=1.4',
-    'nbclassic~=0.2',
-    'jinja2>=2.10'
-]
-
-
-setup_args['extras_require'] = {
-    'test': [
-        'pytest>=6.0',
-        'pytest-cov',
-        'pytest-console-scripts',
-        'pytest-check-links>=0.5',
-        'jupyterlab_server[test]~=2.2',
-        'requests',
-        'requests_cache',
-        'wheel',
-        'virtualenv'
-    ],
-    'test:sys_platform == "win32"': ['nose-exclude'],
-    'docs': [
-        'jsx-lexer',
-        'recommonmark',
-        'sphinx',
-        'sphinx_rtd_theme',
-        'sphinx-copybutton'
-    ],
-}
-
-
-setup_args['package_data'] = package_data_spec
-setup_args['include_package_data'] = True
-setup_args['python_requires'] = '>=3.6'
-
-# Force entrypoints with setuptools (needed for Windows, unconditional
-# because of wheels)
-setup_args['entry_points'] = {
-    'console_scripts': [
-        'jupyter-lab = jupyterlab.labapp:main',
-        'jupyter-labextension = jupyterlab.labextensions:main',
-        'jupyter-labhub = jupyterlab.labhubapp:main',
-        'jlpm = jupyterlab.jlpmapp:main',
-    ]
-}
-
-
 if __name__ == '__main__':
     setup(**setup_args)