Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Enhance setup (#2)
Browse files Browse the repository at this point in the history
* Enhance setup

* Fix pyproject

* Fix build workflow

* Fix manifest
  • Loading branch information
fcollonval authored Apr 18, 2022
1 parent e648d43 commit 7bca36f
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 89 deletions.
129 changes: 85 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 *~
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jlab-enhanced/recents",
"version": "3.0.1",
"version": "3.1.0",
"description": "Track recent files and folders.",
"keywords": [
"jupyter",
Expand Down
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
85 changes: 43 additions & 42 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7bca36f

Please sign in to comment.