Skip to content

Commit 6d6c3fe

Browse files
authored
Enhance setup (#78)
* Enhance setup * Fix pyproject and manifest * Install missing check-manifest * Upgrade publication workflow
1 parent cad8563 commit 6d6c3fe

File tree

7 files changed

+186
-102
lines changed

7 files changed

+186
-102
lines changed

.github/workflows/build.yml

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

.github/workflows/publish.yml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@ name: Publish Package
33
on:
44
release:
55
types: [published]
6-
6+
workflow_dispatch:
77

88
jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- name: Install node
14-
uses: actions/setup-node@v1
15-
with:
16-
node-version: '14.x'
17-
registry-url: 'https://registry.npmjs.org'
18-
- name: Install Python
19-
uses: actions/setup-python@v2
20-
with:
21-
python-version: '3.x'
22-
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
pip install jupyter_packaging~=0.7.9 jupyterlab~=3.0 packaging setuptools twine wheel
26-
- name: Publish the Python package
27-
env:
28-
TWINE_USERNAME: __token__
29-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
30-
run: |
31-
python setup.py sdist bdist_wheel
32-
twine upload dist/*
33-
- name: Publish the NPM package
34-
run: |
35-
echo $PRE_RELEASE
36-
if [[ $PRE_RELEASE == "true" ]]; then export TAG="next"; else export TAG="latest"; fi
37-
npm publish --tag ${TAG} --access public
38-
env:
39-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
40-
PRE_RELEASE: ${{ github.event.release.prerelease }}
12+
- uses: actions/checkout@v2
13+
- name: Install node
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: '14.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
- name: Install Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: '3.x'
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install "jupyterlab~=3.0" "jupyter_packaging~=0.10,<2" twine build
26+
- name: Publish the Python package
27+
env:
28+
TWINE_USERNAME: __token__
29+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
30+
run: |
31+
jlpm
32+
33+
python -m build
34+
twine upload --skip-existing dist/*
35+
- name: Publish the NPM package
36+
run: |
37+
echo $PRE_RELEASE
38+
if [[ $PRE_RELEASE == "true" ]]; then export TAG="next"; else export TAG="latest"; fi
39+
npm publish --tag ${TAG} --access public
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
PRE_RELEASE: ${{ github.event.release.prerelease }}

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ graft src
1515
graft style
1616
prune **/node_modules
1717
prune lib
18+
prune binder
19+
20+
exclude screenshot.png
1821

1922
# Patterns to exclude from any directory
2023
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": "jupyterlab-kernelspy",
3-
"version": "3.0.6",
3+
"version": "3.1.0",
44
"description": "A Jupyter Lab extension for inspecting messages to/from a kernel",
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 = ["jupyterlab_kernelspy/labextension/static/style.js"]
7+
ensured-targets = ["jupyterlab_kernelspy/labextension/static/style.js", "jupyterlab_kernelspy/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 = ["jupyterlab_kernelspy/labextension/**", "yarn.lock", ".*", "package-lock.json"]

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[metadata]
2-
description-file = README.md
32
license_file = LICENSE
43

54
[manifix]

setup.py

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

7-
from jupyter_packaging import (
8-
create_cmdclass,
9-
install_npm,
10-
ensure_targets,
11-
combine_commands,
12-
skip_if_exists,
13-
)
148
import setuptools
159

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

1812
# The name of the project
19-
name = "jupyterlab_kernelspy"
20-
21-
# Get our version
22-
with open(os.path.join(HERE, "package.json")) as f:
23-
version = json.load(f)["version"]
13+
name="jupyterlab_kernelspy"
2414

25-
lab_path = os.path.join(HERE, name, "labextension")
15+
lab_path = HERE / name.replace("-", "_") / "labextension"
2616

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

3420
labext_name = "jupyterlab-kernelspy"
3521

3622
data_files_spec = [
37-
("share/jupyter/labextensions/%s" % labext_name, lab_path, "**"),
38-
("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"),
3929
]
4030

41-
cmdclass = create_cmdclass(
42-
"jsdeps", package_data_spec=package_data_spec, data_files_spec=data_files_spec
43-
)
31+
long_description = (HERE / "README.md").read_text()
4432

45-
js_command = combine_commands(
46-
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
47-
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")
4840
)
4941

50-
is_repo = os.path.exists(os.path.join(HERE, ".git"))
51-
if is_repo:
52-
cmdclass["jsdeps"] = js_command
53-
else:
54-
cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command)
55-
56-
with open("README.md", "r") as fh:
57-
long_description = fh.read()
58-
5942
setup_args = dict(
6043
name=name.replace("_", "-"),
6144
version=version,
62-
url="https://github.com/jupyterlab-contrib/jupyterlab-kernelspy.git",
63-
author="Vidar Tonaas Fauske",
64-
description="A Jupyter Lab extension for inspecting messages to/from a kernel",
45+
url=pkg_json["homepage"],
46+
author=pkg_json["author"],
47+
description=pkg_json["description"],
48+
license=pkg_json["license"],
6549
long_description=long_description,
6650
long_description_content_type="text/markdown",
67-
cmdclass=cmdclass,
6851
packages=setuptools.find_packages(),
69-
install_requires=[
70-
"jupyterlab>=3.0.0rc13,==3.*",
71-
],
7252
zip_safe=False,
7353
include_package_data=True,
74-
python_requires=">=3.6",
75-
license="BSD-3-Clause",
54+
python_requires=">=3.7",
7655
platforms="Linux, Mac OS X, Windows",
7756
keywords=["Jupyter", "JupyterLab", "JupyterLab3"],
7857
classifiers=[
7958
"License :: OSI Approved :: BSD License",
8059
"Programming Language :: Python",
8160
"Programming Language :: Python :: 3",
82-
"Programming Language :: Python :: 3.6",
8361
"Programming Language :: Python :: 3.7",
8462
"Programming Language :: Python :: 3.8",
63+
"Programming Language :: Python :: 3.9",
64+
"Programming Language :: Python :: 3.10",
8565
"Framework :: Jupyter",
66+
"Framework :: Jupyter :: JupyterLab",
67+
"Framework :: Jupyter :: JupyterLab :: 3",
68+
"Framework :: Jupyter :: JupyterLab :: Extensions",
69+
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
8670
],
8771
)
8872

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
8992

9093
if __name__ == "__main__":
9194
setuptools.setup(**setup_args)

0 commit comments

Comments
 (0)