Skip to content

Commit 47c667a

Browse files
authored
Enhance setup (#31)
* Enhance setup * Fix python author from package.json * Fix pyproject and manifest
1 parent 2733b65 commit 47c667a

File tree

5 files changed

+168
-77
lines changed

5 files changed

+168
-77
lines changed

.github/workflows/build.yml

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,105 @@ on:
44
push:
55
branches: master
66
pull_request:
7-
branches: '*'
87

98
jobs:
109
build:
1110
runs-on: ubuntu-latest
1211
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v2
15-
- name: Install node
16-
uses: actions/setup-node@v1
17-
with:
18-
node-version: '14.x'
19-
- name: Install Python
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: '3.9'
23-
architecture: 'x64'
24-
- name: Install dependencies
25-
run: python -m pip install jupyterlab~=3.0
26-
- name: Build the extension
27-
run: |
28-
jlpm
29-
jlpm run eslint:check
30-
python -m pip install .
31-
32-
jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/launcher.*OK"
33-
python -m jupyterlab.browser_check
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
- name: Install node
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: '14.x'
18+
- name: Install Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: '3.9'
22+
architecture: 'x64'
23+
24+
- name: Setup pip cache
25+
uses: actions/cache@v2
26+
with:
27+
path: ~/.cache/pip
28+
key: pip-3.8-${{ hashFiles('package.json') }}
29+
restore-keys: |
30+
pip-3.8-
31+
pip-
32+
33+
- name: Get yarn cache directory path
34+
id: yarn-cache-dir-path
35+
run: echo "::set-output name=dir::$(yarn cache dir)"
36+
- name: Setup yarn cache
37+
uses: actions/cache@v2
38+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
39+
with:
40+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
41+
key: yarn-${{ hashFiles('**/yarn.lock') }}
42+
restore-keys: |
43+
yarn-
44+
45+
- name: Install dependencies
46+
run: |
47+
set -eux
48+
sudo apt-get update
49+
sudo apt-get install ripgrep
50+
51+
python -m pip install -U jupyterlab~=3.1 check-manifest
52+
53+
- name: Build the extension
54+
run: |
55+
set -eux
56+
jlpm
57+
jlpm run eslint:check
58+
python -m pip install .
59+
60+
- name: Check JupyterLab installation
61+
run: |
62+
set -eux
63+
64+
jupyter labextension list
65+
jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/launcher.*OK"
66+
python -m jupyterlab.browser_check
67+
68+
- name: Build package
69+
run: |
70+
set -eux
71+
check-manifest -v
72+
73+
pip install build
74+
python -m build --sdist
75+
cp dist/*.tar.gz myextension.tar.gz
76+
pip uninstall -y myextension jupyterlab
77+
rm -rf myextension
78+
79+
- uses: actions/upload-artifact@v2
80+
with:
81+
name: myextension-sdist
82+
path: myextension.tar.gz
83+
84+
test_isolated:
85+
needs: build
86+
runs-on: ubuntu-latest
87+
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v2
91+
- name: Install Python
92+
uses: actions/setup-python@v2
93+
with:
94+
python-version: '3.8'
95+
architecture: 'x64'
96+
- uses: actions/download-artifact@v2
97+
with:
98+
name: myextension-sdist
99+
- name: Install and Test
100+
run: |
101+
set -eux
102+
# Remove NodeJS, twice to take care of system and locally installed node versions.
103+
sudo rm -rf $(which node)
104+
sudo rm -rf $(which node)
105+
pip install myextension.tar.gz
106+
pip install jupyterlab
107+
jupyter labextension list 2>&1 | grep -ie "@jlab-enhanced/launcher.*OK"
108+
python -m jupyterlab.browser_check --no-chrome-test

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ graft jlab_enhanced_launcher/labextension
1212
# Javascript files
1313
graft src
1414
graft style
15+
graft schema
1516
prune **/node_modules
1617
prune lib
18+
prune binder
19+
20+
exclude enh_launcher.gif
1721

1822
# Patterns to exclude from any directory
1923
global-exclude *~

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jlab-enhanced/launcher",
3-
"version": "3.0.3",
3+
"version": "3.1.0",
44
"description": "A enhanced launcher for JupyterLab",
55
"keywords": [
66
"jupyter",

pyproject.toml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
[build-system]
2-
requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0rc13,==3.*", "setuptools>=40.8.0", "wheel"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["jupyter_packaging~=0.10,<2", "jupyterlab~=3.1"]
3+
build-backend = "jupyter_packaging.build_api"
4+
5+
[tool.jupyter-packaging.options]
6+
skip-if-exists = ["jlab_enhanced_launcher/labextension/static/style.js"]
7+
ensured-targets = ["jlab_enhanced_launcher/labextension/static/style.js", "jlab_enhanced_launcher/labextension/package.json"]
8+
9+
[tool.jupyter-packaging.builder]
10+
factory = "jupyter_packaging.npm_builder"
11+
12+
[tool.jupyter-packaging.build-args]
13+
build_cmd = "build:prod"
14+
npm = ["jlpm"]
15+
16+
[tool.check-manifest]
17+
ignore = ["jlab_enhanced_launcher/labextension/**", "yarn.lock", ".*", "package-lock.json"]

setup.py

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,93 @@
22
jlab_enhanced_launcher setup
33
"""
44
import json
5-
import os
5+
import sys
6+
from pathlib import Path
67

78
import setuptools
8-
from jupyter_packaging import (
9-
create_cmdclass, install_npm, ensure_targets,
10-
combine_commands, skip_if_exists
11-
)
12-
from packaging.version import parse
139

14-
HERE = os.path.abspath(os.path.dirname(__file__))
10+
HERE = Path(__file__).parent.resolve()
1511

1612
# The name of the project
1713
name="jlab_enhanced_launcher"
1814

19-
# Get our version
20-
with open(os.path.join(HERE, 'package.json')) as f:
21-
version = str(parse(json.load(f)['version']))
22-
23-
lab_path = os.path.join(HERE, name, "labextension")
15+
lab_path = HERE / name.replace("-", "_") / "labextension"
2416

2517
# Representative files that should exist after a successful build
26-
jstargets = [
27-
os.path.join(lab_path, "package.json"),
28-
]
29-
30-
package_data_spec = {
31-
name.replace("_", "-"): [
32-
"*"
33-
]
34-
}
18+
ensured_targets = [str(lab_path / "package.json"), str(lab_path / "static/style.js")]
3519

3620
labext_name = "@jlab-enhanced/launcher"
3721

3822
data_files_spec = [
39-
("share/jupyter/labextensions/%s" % labext_name, lab_path, "**"),
40-
("share/jupyter/labextensions/%s" % labext_name, HERE, "install.json"),
23+
(
24+
"share/jupyter/labextensions/%s" % labext_name,
25+
str(lab_path.relative_to(HERE)),
26+
"**",
27+
),
28+
("share/jupyter/labextensions/%s" % labext_name, str("."), "install.json"),
4129
]
4230

43-
cmdclass = create_cmdclass("jsdeps",
44-
package_data_spec=package_data_spec,
45-
data_files_spec=data_files_spec
46-
)
31+
long_description = (HERE / "README.md").read_text()
4732

48-
js_command = combine_commands(
49-
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
50-
ensure_targets(jstargets),
33+
# Get the package info from package.json
34+
pkg_json = json.loads((HERE / "package.json").read_bytes())
35+
version = (
36+
pkg_json["version"]
37+
.replace("-alpha.", "a")
38+
.replace("-beta.", "b")
39+
.replace("-rc.", "rc")
5140
)
5241

53-
is_repo = os.path.exists(os.path.join(HERE, ".git"))
54-
if is_repo:
55-
cmdclass["jsdeps"] = js_command
56-
else:
57-
cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command)
58-
59-
with open("README.md", "r") as fh:
60-
long_description = fh.read()
61-
6242
setup_args = dict(
63-
name=name.replace("_", "-"),
43+
name=name,
6444
version=version,
65-
url="https://github.com/jupyterlab-contrib/jlab-enhanced-launcher.git",
66-
author="Frederic COLLONVAL",
67-
description="A enhanced launcher for JupyterLab",
68-
long_description= long_description,
45+
url=pkg_json["homepage"],
46+
author=pkg_json["author"],
47+
description=pkg_json["description"],
48+
license=pkg_json["license"],
49+
long_description=long_description,
6950
long_description_content_type="text/markdown",
70-
cmdclass= cmdclass,
7151
packages=setuptools.find_packages(),
72-
install_requires=[
73-
"jupyterlab>=3.0.0rc13,==3.*",
74-
"packaging"
75-
],
7652
zip_safe=False,
7753
include_package_data=True,
78-
python_requires=">=3.6",
79-
license="BSD-3-Clause",
54+
python_requires=">=3.7",
8055
platforms="Linux, Mac OS X, Windows",
8156
keywords=["Jupyter", "JupyterLab", "JupyterLab3"],
8257
classifiers=[
8358
"License :: OSI Approved :: BSD License",
8459
"Programming Language :: Python",
8560
"Programming Language :: Python :: 3",
86-
"Programming Language :: Python :: 3.6",
8761
"Programming Language :: Python :: 3.7",
8862
"Programming Language :: Python :: 3.8",
8963
"Programming Language :: Python :: 3.9",
64+
"Programming Language :: Python :: 3.10",
9065
"Framework :: Jupyter",
66+
"Framework :: Jupyter :: JupyterLab",
67+
"Framework :: Jupyter :: JupyterLab :: 3",
68+
"Framework :: Jupyter :: JupyterLab :: Extensions",
69+
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
9170
],
9271
)
9372

73+
try:
74+
from jupyter_packaging import wrap_installers, npm_builder, get_data_files
75+
76+
post_develop = npm_builder(
77+
build_cmd="install:extension", source_dir="src", build_dir=lab_path
78+
)
79+
setup_args["cmdclass"] = wrap_installers(
80+
post_develop=post_develop, ensured_targets=ensured_targets
81+
)
82+
setup_args["data_files"] = get_data_files(data_files_spec)
83+
except ImportError as e:
84+
import logging
85+
86+
logging.basicConfig(format="%(levelname)s: %(message)s")
87+
logging.warning(
88+
"Build tool `jupyter-packaging` is missing. Install it with pip or conda."
89+
)
90+
if not ("--name" in sys.argv or "--version" in sys.argv):
91+
raise e
9492

9593
if __name__ == "__main__":
9694
setuptools.setup(**setup_args)

0 commit comments

Comments
 (0)