From 6d6c3fedcbb92110d169a61685ad8b484fe8ae8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Tue, 19 Apr 2022 10:08:59 +0200 Subject: [PATCH] Enhance setup (#78) * Enhance setup * Fix pyproject and manifest * Install missing check-manifest * Upgrade publication workflow --- .github/workflows/build.yml | 105 +++++++++++++++++++++++++++------- .github/workflows/publish.yml | 62 ++++++++++---------- MANIFEST.in | 3 + package.json | 2 +- pyproject.toml | 18 +++++- setup.cfg | 1 - setup.py | 97 ++++++++++++++++--------------- 7 files changed, 186 insertions(+), 102 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 931feb0..3e56751 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,24 +10,87 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install node - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: Install Python - uses: actions/setup-python@v2 - with: - python-version: '3.7' - architecture: 'x64' - - name: Install dependencies - run: python -m pip install jupyterlab - - name: Build the extension - run: | - jlpm - jlpm run eslint:check - python -m pip install . - - jupyter labextension list 2>&1 | grep -ie "jupyterlab-kernelspy.*OK" - python -m jupyterlab.browser_check + - name: Checkout + uses: actions/checkout@v2 + - name: Install node + uses: actions/setup-node@v1 + with: + node-version: '14.x' + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + architecture: 'x64' + + - name: Setup pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: pip-3.8-${{ hashFiles('package.json') }} + restore-keys: | + pip-3.8- + pip- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Setup yarn cache + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn- + - name: Install dependencies + run: python -m pip install jupyterlab~=3.0 check-manifest + - name: Build the extension + run: | + jlpm + jlpm run eslint:check + python -m pip install . + + jupyter labextension list 2>&1 | grep -ie "jupyterlab-kernelspy.*OK" + python -m jupyterlab.browser_check + + - name: Build package + run: | + set -eux + check-manifest -v + + pip install build + python -m build --sdist + cp dist/*.tar.gz myextension.tar.gz + pip uninstall -y myextension jupyterlab + rm -rf myextension + + - uses: actions/upload-artifact@v2 + with: + name: myextension-sdist + path: myextension.tar.gz + + test_isolated: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + architecture: 'x64' + - uses: actions/download-artifact@v2 + with: + name: myextension-sdist + - name: Install and Test + run: | + set -eux + # Remove NodeJS, twice to take care of system and locally installed node versions. + sudo rm -rf $(which node) + sudo rm -rf $(which node) + pip install myextension.tar.gz + pip install jupyterlab + jupyter labextension list 2>&1 | grep -ie "jupyterlab-kernelspy.*OK" + python -m jupyterlab.browser_check --no-chrome-test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1e7b51c..4d9c175 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,38 +3,40 @@ name: Publish Package on: release: types: [published] - + workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install node - uses: actions/setup-node@v1 - with: - node-version: '14.x' - registry-url: 'https://registry.npmjs.org' - - name: Install Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install jupyter_packaging~=0.7.9 jupyterlab~=3.0 packaging setuptools twine wheel - - name: Publish the Python package - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* - - name: Publish the NPM package - run: | - echo $PRE_RELEASE - if [[ $PRE_RELEASE == "true" ]]; then export TAG="next"; else export TAG="latest"; fi - npm publish --tag ${TAG} --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - PRE_RELEASE: ${{ github.event.release.prerelease }} + - uses: actions/checkout@v2 + - name: Install node + uses: actions/setup-node@v1 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install "jupyterlab~=3.0" "jupyter_packaging~=0.10,<2" twine build + - name: Publish the Python package + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + jlpm + + python -m build + twine upload --skip-existing dist/* + - name: Publish the NPM package + run: | + echo $PRE_RELEASE + if [[ $PRE_RELEASE == "true" ]]; then export TAG="next"; else export TAG="latest"; fi + npm publish --tag ${TAG} --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + PRE_RELEASE: ${{ github.event.release.prerelease }} diff --git a/MANIFEST.in b/MANIFEST.in index f47bcc9..3175e23 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -15,6 +15,9 @@ graft src graft style prune **/node_modules prune lib +prune binder + +exclude screenshot.png # Patterns to exclude from any directory global-exclude *~ diff --git a/package.json b/package.json index a1b331e..046bb84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab-kernelspy", - "version": "3.0.6", + "version": "3.1.0", "description": "A Jupyter Lab extension for inspecting messages to/from a kernel", "keywords": [ "jupyter", diff --git a/pyproject.toml b/pyproject.toml index 5f53684..aa57bce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,17 @@ [build-system] -requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0rc13,==3.*", "setuptools>=40.8.0", "wheel"] -build-backend = "setuptools.build_meta" +requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1"] +build-backend = "jupyter_packaging.build_api" + +[tool.jupyter-packaging.options] +skip-if-exists = ["jupyterlab_kernelspy/labextension/static/style.js"] +ensured-targets = ["jupyterlab_kernelspy/labextension/static/style.js", "jupyterlab_kernelspy/labextension/package.json"] + +[tool.jupyter-packaging.builder] +factory = "jupyter_packaging.npm_builder" + +[tool.jupyter-packaging.build-args] +build_cmd = "build:prod" +npm = ["jlpm"] + +[tool.check-manifest] +ignore = ["jupyterlab_kernelspy/labextension/**", "yarn.lock", ".*", "package-lock.json"] diff --git a/setup.cfg b/setup.cfg index 0aa5ed9..ba4286c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,4 @@ [metadata] -description-file = README.md license_file = LICENSE [manifix] diff --git a/setup.py b/setup.py index a0633e0..8ad1b0d 100644 --- a/setup.py +++ b/setup.py @@ -2,90 +2,93 @@ jupyterlab_kernelspy setup """ import json -import os +import sys +from pathlib import Path -from jupyter_packaging import ( - create_cmdclass, - install_npm, - ensure_targets, - combine_commands, - skip_if_exists, -) import setuptools -HERE = os.path.abspath(os.path.dirname(__file__)) +HERE = Path(__file__).parent.resolve() # The name of the project -name = "jupyterlab_kernelspy" - -# Get our version -with open(os.path.join(HERE, "package.json")) as f: - version = json.load(f)["version"] +name="jupyterlab_kernelspy" -lab_path = os.path.join(HERE, name, "labextension") +lab_path = HERE / name.replace("-", "_") / "labextension" # Representative files that should exist after a successful build -jstargets = [ - os.path.join(lab_path, "package.json"), -] - -package_data_spec = {name: ["*"]} +ensured_targets = [str(lab_path / "package.json"), str(lab_path / "static/style.js")] labext_name = "jupyterlab-kernelspy" data_files_spec = [ - ("share/jupyter/labextensions/%s" % labext_name, lab_path, "**"), - ("share/jupyter/labextensions/%s" % labext_name, HERE, "install.json"), + ( + "share/jupyter/labextensions/%s" % labext_name, + str(lab_path.relative_to(HERE)), + "**", + ), + ("share/jupyter/labextensions/%s" % labext_name, str("."), "install.json"), ] -cmdclass = create_cmdclass( - "jsdeps", package_data_spec=package_data_spec, data_files_spec=data_files_spec -) +long_description = (HERE / "README.md").read_text() -js_command = combine_commands( - install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]), - ensure_targets(jstargets), +# Get the package info from package.json +pkg_json = json.loads((HERE / "package.json").read_bytes()) +version = ( + pkg_json["version"] + .replace("-alpha.", "a") + .replace("-beta.", "b") + .replace("-rc.", "rc") ) -is_repo = os.path.exists(os.path.join(HERE, ".git")) -if is_repo: - cmdclass["jsdeps"] = js_command -else: - cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command) - -with open("README.md", "r") as fh: - long_description = fh.read() - setup_args = dict( name=name.replace("_", "-"), version=version, - url="https://github.com/jupyterlab-contrib/jupyterlab-kernelspy.git", - author="Vidar Tonaas Fauske", - description="A Jupyter Lab extension for inspecting messages to/from a kernel", + url=pkg_json["homepage"], + author=pkg_json["author"], + description=pkg_json["description"], + license=pkg_json["license"], long_description=long_description, long_description_content_type="text/markdown", - cmdclass=cmdclass, packages=setuptools.find_packages(), - install_requires=[ - "jupyterlab>=3.0.0rc13,==3.*", - ], zip_safe=False, include_package_data=True, - python_requires=">=3.6", - license="BSD-3-Clause", + python_requires=">=3.7", platforms="Linux, Mac OS X, Windows", keywords=["Jupyter", "JupyterLab", "JupyterLab3"], classifiers=[ "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", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Framework :: Jupyter", + "Framework :: Jupyter :: JupyterLab", + "Framework :: Jupyter :: JupyterLab :: 3", + "Framework :: Jupyter :: JupyterLab :: Extensions", + "Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt", ], ) +try: + from jupyter_packaging import wrap_installers, npm_builder, get_data_files + + post_develop = npm_builder( + build_cmd="install:extension", source_dir="src", build_dir=lab_path + ) + setup_args["cmdclass"] = wrap_installers( + post_develop=post_develop, ensured_targets=ensured_targets + ) + setup_args["data_files"] = get_data_files(data_files_spec) +except ImportError as e: + import logging + + logging.basicConfig(format="%(levelname)s: %(message)s") + logging.warning( + "Build tool `jupyter-packaging` is missing. Install it with pip or conda." + ) + if not ("--name" in sys.argv or "--version" in sys.argv): + raise e if __name__ == "__main__": setuptools.setup(**setup_args)