Skip to content

Commit b39a369

Browse files
authored
Adopt linters and releaser (#12)
1 parent f4190da commit b39a369

9 files changed

+238
-23
lines changed

.github/dependabot.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
version: 2
22
updates:
3-
# Set update schedule for GitHub Actions
43
- package-ecosystem: "github-actions"
54
directory: "/"
65
schedule:
7-
# Check for updates to GitHub Actions every weekday
6+
interval: "weekly"
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
810
interval: "weekly"

.github/workflows/prep-release.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "Step 1: Prep Release"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version_spec:
6+
description: "New Version Specifier"
7+
default: "next"
8+
required: false
9+
branch:
10+
description: "The branch to target"
11+
required: false
12+
post_version_spec:
13+
description: "Post Version Specifier"
14+
required: false
15+
since:
16+
description: "Use PRs with activity since this date or git reference"
17+
required: false
18+
since_last_stable:
19+
description: "Use PRs with activity since the last stable git tag"
20+
required: false
21+
type: boolean
22+
jobs:
23+
prep_release:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
27+
28+
- name: Prep Release
29+
id: prep-release
30+
uses: jupyter-server/jupyter_releaser/.github/actions/prep-release@v2
31+
with:
32+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
33+
version_spec: ${{ github.event.inputs.version_spec }}
34+
post_version_spec: ${{ github.event.inputs.post_version_spec }}
35+
target: ${{ github.event.inputs.target }}
36+
branch: ${{ github.event.inputs.branch }}
37+
since: ${{ github.event.inputs.since }}
38+
since_last_stable: ${{ github.event.inputs.since_last_stable }}
39+
40+
- name: "** Next Step **"
41+
run: |
42+
echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}"

.github/workflows/publish-release.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "Step 2: Publish Release"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
branch:
6+
description: "The target branch"
7+
required: false
8+
release_url:
9+
description: "The URL of the draft GitHub release"
10+
required: false
11+
steps_to_skip:
12+
description: "Comma separated list of steps to skip"
13+
required: false
14+
15+
jobs:
16+
publish_release:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
20+
21+
- name: Populate Release
22+
id: populate-release
23+
uses: jupyter-server/jupyter_releaser/.github/actions/populate-release@v2
24+
with:
25+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
26+
target: ${{ github.event.inputs.target }}
27+
branch: ${{ github.event.inputs.branch }}
28+
release_url: ${{ github.event.inputs.release_url }}
29+
steps_to_skip: ${{ github.event.inputs.steps_to_skip }}
30+
31+
- name: Finalize Release
32+
id: finalize-release
33+
env:
34+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
35+
PYPI_TOKEN_MAP: ${{ secrets.PYPI_TOKEN_MAP }}
36+
TWINE_USERNAME: __token__
37+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38+
uses: jupyter-server/jupyter-releaser/.github/actions/finalize-release@v2
39+
with:
40+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
41+
target: ${{ github.event.inputs.target }}
42+
release_url: ${{ steps.populate-release.outputs.release_url }}
43+
44+
- name: "** Next Step **"
45+
if: ${{ success() }}
46+
run: |
47+
echo "Verify the final release"
48+
echo ${{ steps.finalize-release.outputs.release_url }}
49+
50+
- name: "** Failure Message **"
51+
if: ${{ failure() }}
52+
run: |
53+
echo "Failed to Publish the Draft Release Url:"
54+
echo ${{ steps.populate-release.outputs.release_url }}

.github/workflows/python-tests.yml

+39-6
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,55 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
os: [ubuntu-latest, windows-latest, macos-latest]
17-
python-version: ["3.7", "3.10"]
17+
python-version: ["3.7", "3.11"]
1818
include:
1919
- os: windows-latest
2020
python-version: "3.9"
2121
- os: ubuntu-latest
2222
python-version: "pypy-3.8"
2323
- os: ubuntu-latest
24-
python-version: "3.11"
24+
python-version: "3.10"
2525
- os: macos-latest
2626
python-version: "3.8"
2727
steps:
2828
- name: Checkout
2929
uses: actions/checkout@v3
3030
- name: Base Setup
3131
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
32-
- name: Install and test
33-
run:
34-
pip install -e .[test]
35-
pytest
32+
- name: Run test
33+
run: hatch run test:test
34+
35+
test_lint:
36+
name: Test Lint
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v3
40+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
41+
- name: Run Linters
42+
run: |
43+
hatch run typing:test
44+
hatch run lint:style
45+
pipx run 'validate-pyproject[all]' pyproject.toml
46+
47+
check_release:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
- name: Base Setup
53+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
54+
- name: Install Dependencies
55+
run: |
56+
pip install -e .
57+
- name: Check Release
58+
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2
59+
with:
60+
version_spec: 100.100.100
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
63+
check_links:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v3
67+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
68+
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
<!-- <START NEW CHANGELOG ENTRY> -->
6+
7+
## 0.1.2
8+
9+
Initial release
10+
11+
<!-- <END NEW CHANGELOG ENTRY> -->

comm/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Copyright (c) IPython Development Team.
44
Distributed under the terms of the Modified BSD License.
55
6-
This package provides a way to register a Kernel Comm implementation, as per the Jupyter kernel protocol.
6+
This package provides a way to register a Kernel Comm implementation, as per
7+
the Jupyter kernel protocol.
78
It also provides a base Comm implementation and a default CommManager for the IPython case.
89
"""
910

comm/base_comm.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# Copyright (c) IPython Development Team.
55
# Distributed under the terms of the Modified BSD License.
66

7-
import uuid
87
import logging
9-
import comm
8+
import uuid
109

1110
from traitlets.utils.importstring import import_item
1211

13-
logger = logging.getLogger('Comm')
12+
import comm
1413

14+
logger = logging.getLogger("Comm")
1515

1616

1717
class BaseComm:
@@ -35,7 +35,7 @@ def __init__(
3535
_close_data=None,
3636
**kwargs,
3737
):
38-
super(BaseComm, self).__init__(**kwargs)
38+
super().__init__(**kwargs)
3939

4040
self.comm_id = comm_id if comm_id else uuid.uuid4().hex
4141
self.primary = primary
@@ -66,7 +66,7 @@ def __del__(self):
6666

6767
# publishing messages
6868

69-
def open(self, data=None, metadata=None, buffers=None):
69+
def open(self, data=None, metadata=None, buffers=None): # noqa
7070
"""Open the frontend-side version of this comm"""
7171

7272
if data is None:
@@ -149,7 +149,7 @@ def handle_msg(self, msg):
149149
"""Handle a comm_msg message"""
150150
logger.debug("handle_msg[%s](%s)", self.comm_id, msg)
151151
if self._msg_callback:
152-
from IPython import get_ipython
152+
from IPython import get_ipython # type:ignore
153153

154154
shell = get_ipython()
155155
if shell:
@@ -237,9 +237,7 @@ def comm_open(self, stream, ident, msg):
237237
f(comm, msg)
238238
return
239239
except Exception:
240-
logger.error(
241-
"Exception opening comm with target: %s", target_name, exc_info=True
242-
)
240+
logger.error("Exception opening comm with target: %s", target_name, exc_info=True)
243241

244242
# Failure.
245243
try:

pyproject.toml

+77-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling>1.10"]
2+
requires = ["hatchling>=1.10"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -22,11 +22,11 @@ classifiers = [
2222
"License :: OSI Approved :: BSD License",
2323
"Programming Language :: Python",
2424
"Programming Language :: Python :: 3",
25-
"Programming Language :: Python :: 3.6",
2625
"Programming Language :: Python :: 3.7",
2726
"Programming Language :: Python :: 3.8",
2827
"Programming Language :: Python :: 3.9",
2928
"Programming Language :: Python :: 3.10",
29+
"Programming Language :: Python :: 3.11",
3030
]
3131
dependencies = [
3232
"traitlets>=5.3",
@@ -36,6 +36,13 @@ dependencies = [
3636
test = [
3737
"pytest",
3838
]
39+
lint = [
40+
"black>=22.6.0",
41+
"mdformat>0.7",
42+
"mdformat-gfm>=0.3.5",
43+
"ruff>=0.0.156"
44+
]
45+
typing = ["mypy>=0.990"]
3946

4047
[project.urls]
4148
Homepage = "https://github.com/ipython/comm"
@@ -48,6 +55,74 @@ include = [
4855
"/comm",
4956
]
5057

58+
[tool.hatch.envs.test]
59+
features = ["test"]
60+
[tool.hatch.envs.test.scripts]
61+
test = "python -m pytest -vv {args}"
62+
nowarn = "test -W default {args}"
63+
64+
[tool.hatch.envs.typing]
65+
features = ["typing", "test"]
66+
[tool.hatch.envs.typing.scripts]
67+
test = "mypy --install-types --non-interactive {args:comm tests}"
68+
69+
[tool.hatch.envs.lint]
70+
features = ["lint"]
71+
[tool.hatch.envs.lint.scripts]
72+
style = [
73+
"ruff {args:.}",
74+
"black --check --diff {args:.}",
75+
"mdformat --check {args:*.md}"
76+
]
77+
fmt = [
78+
"black {args:.}",
79+
"ruff --fix {args:.}",
80+
"mdformat {args:*.md}"
81+
]
82+
5183
[tool.pytest.ini_options]
5284
addopts = "-raXs --durations 10 --color=yes"
5385
filterwarnings = ["error"]
86+
87+
[tool.mypy]
88+
check_untyped_defs = true
89+
disallow_incomplete_defs = true
90+
disallow_untyped_decorators = true
91+
no_implicit_optional = true
92+
no_implicit_reexport = true
93+
pretty = true
94+
show_error_context = true
95+
show_error_codes = true
96+
strict_equality = true
97+
strict_optional = true
98+
warn_unused_configs = true
99+
warn_redundant_casts = true
100+
warn_return_any = true
101+
warn_unused_ignores = true
102+
103+
[tool.black]
104+
line-length = 100
105+
skip-string-normalization = true
106+
target-version = ["py37"]
107+
108+
[tool.ruff]
109+
target-version = "py37"
110+
line-length = 100
111+
select = [
112+
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
113+
"UP", "W", "YTT",
114+
]
115+
ignore = [
116+
# FBT002 Boolean default value in function definition
117+
"FBT002", "FBT003",
118+
]
119+
unfixable = [
120+
# Don't touch print statements
121+
"T201",
122+
# Don't touch noqa lines
123+
"RUF100",
124+
]
125+
126+
[tool.ruff.per-file-ignores]
127+
# S101 Use of `assert` detected
128+
"tests/*" = ["S101"]

tests/test_comm.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from comm.base_comm import CommManager, BaseComm
1+
from comm.base_comm import BaseComm, CommManager
22

33

44
class MyComm(BaseComm):
5-
65
def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
76
pass
87

@@ -14,4 +13,4 @@ def test_comm_manager():
1413

1514
def test_base_comm():
1615
test = MyComm()
17-
assert test.target_name == "comm"
16+
assert test.target_name == "comm"

0 commit comments

Comments
 (0)