Skip to content

Commit

Permalink
Adopt the Jupyter Releaser (#73)
Browse files Browse the repository at this point in the history
* Add check-release CI workflow

* Add release hooks

* More releaser config

* Fix pyproject.toml

* Read version from package.json

* Lint

* Expose version_info

* Lint

* Use pathlib

* Run jlpm

* Fix handling of version

* cleanup

* Missing ignore

* Remove unused tests for now
  • Loading branch information
jtpio authored Sep 6, 2021
1 parent 496d4fc commit 09680c9
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 150 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Check Release
on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: write

jobs:
check_release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.9
architecture: 'x64'
- name: Install node
uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache pip
uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg', 'setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache checked links
uses: actions/cache@v2
with:
path: ~/.cache/pytest-link-check
key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/.md') }}-md-links
restore-keys: |
${{ runner.os }}-linkcheck-
- name: Upgrade packaging dependencies
run: |
pip install --upgrade pip setuptools wheel jupyter-packaging~=0.10 --user
- name: Install Dependencies
run: |
pip install .
- name: Check Release
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
42 changes: 0 additions & 42 deletions .github/workflows/publish.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

<!-- <START NEW CHANGELOG ENTRY> -->

## 0.4.1

- Fix jstargets in setup.py: https://github.com/jtpio/ipylab/pull/53

<!-- <END NEW CHANGELOG ENTRY> -->
4 changes: 0 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ graft ipylab/labextension
# Examples
graft examples

# Tests
graft tests
prune tests/build

# Javascript files
graft src
graft style
Expand Down
10 changes: 5 additions & 5 deletions ipylab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# Copyright (c) ipylab contributors.
# Distributed under the terms of the Modified BSD License.

import json
from pathlib import Path

# import version first: https://github.com/pypa/setuptools/issues/1724#issuecomment-627241822
from ._version import __version__, version_info

import json
import os.path as osp

from .jupyterfrontend import JupyterFrontEnd
from .widgets import Panel, SplitPanel

HERE = osp.abspath(osp.dirname(__file__))
HERE = Path(__file__).parent.resolve()

with open(osp.join(HERE, "labextension", "package.json")) as fid:
with open(str(HERE / "labextension" / "package.json")) as fid:
data = json.load(fid)


Expand Down
31 changes: 29 additions & 2 deletions ipylab/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,32 @@
# Copyright (c) ipylab contributors.
# Distributed under the terms of the Modified BSD License.

version_info = (0, 4, 1)
__version__ = ".".join(map(str, version_info))
import re
import json
from pathlib import Path

__all__ = ["__version__"]


def _fetchVersion():
HERE = Path(__file__).parent.resolve()

for settings in HERE.rglob("package.json"):
try:
with settings.open() as f:
return json.load(f)["version"]
except FileNotFoundError:
pass

raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}")


__version__ = _fetchVersion()

# Build up version_info tuple for backwards compatibility
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
match = re.match(pattern, __version__)
parts = [int(match[part]) for part in ["major", "minor", "patch"]]
if match["rest"]:
parts.append(match["rest"])
version_info = tuple(parts)
Empty file removed ipylab/tests/__init__.py
Empty file.
59 changes: 0 additions & 59 deletions ipylab/tests/conftest.py

This file was deleted.

12 changes: 0 additions & 12 deletions ipylab/tests/test_example.py

This file was deleted.

16 changes: 0 additions & 16 deletions ipylab/tests/test_nbextension_path.py

This file was deleted.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,13 @@
"singleton": true
}
}
},
"jupyter-releaser": {
"hooks": {
"before-build-npm": [
"python -m pip install jupyterlab~=3.0",
"jlpm"
]
}
}
}
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ file="LICENSE"

[tool.jupyter-packaging.options]
skip-if-exists = ["ipylab/labextension/static/style.js"]
ensured-targets = ["ipylab/labextension/static/style.js"]
ensured-targets = ["ipylab/labextension/static/style.js", "ipylab/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 = [".binder/**", "*.json", "docs/**", "yarn.lock", "readthedocs.yml", ".*", "ipylab/labextension/**"]
4 changes: 0 additions & 4 deletions pytest.ini

This file was deleted.

1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[metadata]
name = ipylab
version = attr: ipylab._version.__version__
description = Control JupyterLab from Python Notebooks
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
20 changes: 16 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
from pathlib import Path

import setuptools
Expand All @@ -15,24 +16,35 @@
lab_path = HERE / NAME / "labextension"

# Representative files that should exist after a successful build
ensured_targets = [str(lab_path / "static" / "style.js")]
ensured_targets = [
str(lab_path / "static" / "style.js"),
str(lab_path / "package.json"),
]

data_files_spec = [
(f"share/jupyter/labextensions/{NAME}", str(lab_path), "**"),
(f"share/jupyter/labextensions/{NAME}", str(lab_path.relative_to(HERE)), "**"),
(f"share/jupyter/labextensions/{NAME}", str(HERE), "install.json"),
]

# Get the package info from package.json
pkg_json = json.loads((HERE / "package.json").read_bytes())

try:
from jupyter_packaging import wrap_installers, npm_builder, get_data_files

# In develop mode, just run yarn
builder = npm_builder(build_cmd="build", npm="jlpm", force=True)
builder = npm_builder(build_cmd="build", build_dir=lab_path, source_dir="src")
cmdclass = wrap_installers(post_develop=builder, ensured_targets=ensured_targets)

setup_args = dict(cmdclass=cmdclass, data_files=get_data_files(data_files_spec))
setup_args = dict(
cmdclass=cmdclass,
data_files=get_data_files(data_files_spec),
)
except ImportError:
setup_args = dict()


setup_args["version"] = pkg_json["version"]

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

0 comments on commit 09680c9

Please sign in to comment.