Skip to content

Commit

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

* Fix python author from package.json

* Fix pyproject and manifest
  • Loading branch information
fcollonval authored Apr 18, 2022
1 parent 2733b65 commit 47c667a
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 77 deletions.
119 changes: 97 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,105 @@ on:
push:
branches: master
pull_request:
branches: '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- 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: Install dependencies
run: python -m pip install jupyterlab~=3.0
- name: Build the extension
run: |
jlpm
jlpm run eslint:check
python -m pip install .
jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/launcher.*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: |
set -eux
sudo apt-get update
sudo apt-get install ripgrep
python -m pip install -U jupyterlab~=3.1 check-manifest
- name: Build the extension
run: |
set -eux
jlpm
jlpm run eslint:check
python -m pip install .
- name: Check JupyterLab installation
run: |
set -eux
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/launcher.*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/launcher.*OK"
python -m jupyterlab.browser_check --no-chrome-test
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ graft jlab_enhanced_launcher/labextension
# Javascript files
graft src
graft style
graft schema
prune **/node_modules
prune lib
prune binder

exclude enh_launcher.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/launcher",
"version": "3.0.3",
"version": "3.1.0",
"description": "A enhanced launcher for JupyterLab",
"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.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 = ["jlab_enhanced_launcher/labextension/static/style.js"]
ensured-targets = ["jlab_enhanced_launcher/labextension/static/style.js", "jlab_enhanced_launcher/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 = ["jlab_enhanced_launcher/labextension/**", "yarn.lock", ".*", "package-lock.json"]
102 changes: 50 additions & 52 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,93 @@
jlab_enhanced_launcher setup
"""
import json
import os
import sys
from pathlib import Path

import setuptools
from jupyter_packaging import (
create_cmdclass, install_npm, ensure_targets,
combine_commands, skip_if_exists
)
from packaging.version import parse

HERE = os.path.abspath(os.path.dirname(__file__))
HERE = Path(__file__).parent.resolve()

# The name of the project
name="jlab_enhanced_launcher"

# Get our version
with open(os.path.join(HERE, 'package.json')) as f:
version = str(parse(json.load(f)['version']))

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.replace("_", "-"): [
"*"
]
}
ensured_targets = [str(lab_path / "package.json"), str(lab_path / "static/style.js")]

labext_name = "@jlab-enhanced/launcher"

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("_", "-"),
name=name,
version=version,
url="https://github.com/jupyterlab-contrib/jlab-enhanced-launcher.git",
author="Frederic COLLONVAL",
description="A enhanced launcher for JupyterLab",
long_description= long_description,
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.*",
"packaging"
],
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)

0 comments on commit 47c667a

Please sign in to comment.