From 7bca36f573dd0f5ee7e911f7c914cbf129215c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Mon, 18 Apr 2022 18:39:56 +0200 Subject: [PATCH] Enhance setup (#2) * Enhance setup * Fix pyproject * Fix build workflow * Fix manifest --- .github/workflows/build.yml | 129 ++++++++++++++++++++++++------------ MANIFEST.in | 3 + package.json | 2 +- pyproject.toml | 18 ++++- setup.py | 85 ++++++++++++------------ 5 files changed, 148 insertions(+), 89 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6ae4967..9603d44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,47 +10,88 @@ 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: Setup pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: pip-3.7-${{ hashFiles('package.json') }} - restore-keys: | - pip-3.7- - 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 -U jupyterlab~=3.0 jupyter_packaging~=0.7.9 - - name: Build the extension - run: | - jlpm - jlpm run eslint:check - python -m pip install . - - jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/recents.*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.7' + architecture: 'x64' + + - name: Setup pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: pip-3.7-${{ hashFiles('package.json') }} + restore-keys: | + pip-3.7- + 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 -U 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 "@jlab-enhanced/recents.*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 "@jlab-enhanced/recents.*OK" + python -m jupyterlab.browser_check --no-chrome-test diff --git a/MANIFEST.in b/MANIFEST.in index d468778..72ee36a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -14,6 +14,9 @@ graft src graft style prune **/node_modules prune lib +prune binder + +exclude jupyterlab-recents.gif # Patterns to exclude from any directory global-exclude *~ diff --git a/package.json b/package.json index 4b674ee..136b261 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jlab-enhanced/recents", - "version": "3.0.1", + "version": "3.1.0", "description": "Track recent files and folders.", "keywords": [ "jupyter", diff --git a/pyproject.toml b/pyproject.toml index ba04c53..50b25be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,17 @@ [build-system] -requires = ["jupyter_packaging~=0.7.9", "jupyterlab~=3.0", "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_recents/labextension/static/style.js"] +ensured-targets = ["jupyterlab_recents/labextension/static/style.js", "jupyterlab_recents/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_recents/labextension/**", "yarn.lock", ".*", "package-lock.json"] diff --git a/setup.py b/setup.py index 44576c3..45ff516 100644 --- a/setup.py +++ b/setup.py @@ -1,93 +1,94 @@ """ -jupyterlab_recents setup +jlab_enhanced_launcher setup """ import json +import sys from pathlib import Path -from jupyter_packaging import ( - create_cmdclass, - install_npm, - ensure_targets, - combine_commands, - skip_if_exists -) import setuptools HERE = Path(__file__).parent.resolve() # The name of the project -name = "jupyterlab_recents" +name="jupyterlab_recents" -lab_path = (HERE / name / "labextension") +lab_path = HERE / name.replace("-", "_") / "labextension" # Representative files that should exist after a successful build -jstargets = [ - str(lab_path / "package.json"), -] - -package_data_spec = { - name: ["*"], -} +ensured_targets = [str(lab_path / "package.json"), str(lab_path / "static/style.js")] labext_name = "@jlab-enhanced/recents" data_files_spec = [ - ("share/jupyter/labextensions/%s" % labext_name, str(lab_path), "**"), - ("share/jupyter/labextensions/%s" % labext_name, str(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 -) - -js_command = combine_commands( - install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]), - ensure_targets(jstargets), -) - -is_repo = (HERE / ".git").exists() -if is_repo: - cmdclass["jsdeps"] = js_command -else: - cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command) - long_description = (HERE / "README.md").read_text() # 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") +) setup_args = dict( name=name, - version=pkg_json["version"], + version=version, url=pkg_json["homepage"], author=pkg_json["author"]["name"], 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", - ], zip_safe=False, include_package_data=True, - python_requires=">=3.6", + python_requires=">=3.7", platforms="Linux, Mac OS X, Windows", keywords=pkg_json["keywords"], 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)