Skip to content

Commit e3edb6a

Browse files
authored
Adopt sp-repo-review (#89)
* adopt sp-repo-review * add readthedocs config * wip address typing * wip address typing * update tests * restore indents * handle warning and typings * fix types and do not run coverage on pypy
1 parent eb711c3 commit e3edb6a

21 files changed

+218
-235
lines changed

.github/workflows/python-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ jobs:
5656
steps:
5757
- uses: actions/checkout@v4
5858
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
59-
- name: Run Linters
60-
run: |
59+
- name: Run Linters
60+
run: |
6161
hatch run typing:test
6262
hatch run lint:style
6363
pipx run interrogate .
@@ -83,7 +83,7 @@ jobs:
8383
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
8484
with:
8585
dependency_type: minimum
86-
- name: Install with miniumum versions and optional deps
86+
- name: Install with minimum versions and optional deps
8787
run: |
8888
pip install -e .[test]
8989
pip install jsonschema[format-nongpl,format_nongpl]

.pre-commit-config.yaml

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ci:
22
autoupdate_schedule: monthly
3+
autoupdate_commit_msg: "chore: update pre-commit hooks"
34

45
repos:
56
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -28,14 +29,48 @@ repos:
2829
rev: 0.7.17
2930
hooks:
3031
- id: mdformat
32+
additional_dependencies:
33+
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
3134

32-
- repo: https://github.com/psf/black
35+
- repo: https://github.com/pre-commit/mirrors-prettier
36+
rev: "v3.0.3"
37+
hooks:
38+
- id: prettier
39+
types_or: [yaml, html, json]
40+
41+
- repo: https://github.com/adamchainz/blacken-docs
42+
rev: "1.16.0"
43+
hooks:
44+
- id: blacken-docs
45+
additional_dependencies: [black==23.7.0]
46+
exclude: docs/user_guide/application.md
47+
48+
- repo: https://github.com/psf/black-pre-commit-mirror
3349
rev: 23.9.1
3450
hooks:
3551
- id: black
3652

53+
- repo: https://github.com/codespell-project/codespell
54+
rev: "v2.2.6"
55+
hooks:
56+
- id: codespell
57+
args: ["-L", "sur,nd"]
58+
59+
- repo: https://github.com/pre-commit/pygrep-hooks
60+
rev: "v1.10.0"
61+
hooks:
62+
- id: rst-backticks
63+
- id: rst-directive-colons
64+
- id: rst-inline-touching-normal
65+
3766
- repo: https://github.com/astral-sh/ruff-pre-commit
3867
rev: v0.0.292
3968
hooks:
4069
- id: ruff
41-
args: ["--fix"]
70+
args: ["--fix", "--show-fixes"]
71+
72+
- repo: https://github.com/scientific-python/cookie
73+
rev: "2023.09.21"
74+
hooks:
75+
- id: sp-repo-review
76+
additional_dependencies: ["repo-review[cli]"]

.readthedocs.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
build:
3+
os: ubuntu-22.04
4+
tools:
5+
python: "3.9"
6+
sphinx:
7+
configuration: docs/source/conf.py
8+
python:
9+
install:
10+
# install itself with pip install .
11+
- method: pip
12+
path: .
13+
extra_requirements:
14+
- docs

docs/demo/demo-notebook.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"metadata": {},
100100
"outputs": [],
101101
"source": [
102-
"# We will import one of the handlers from Python's logging libray\n",
102+
"# We will import one of the handlers from Python's logging library\n",
103103
"from logging import StreamHandler\n",
104104
"\n",
105105
"handler = StreamHandler()\n",

docs/user_guide/application.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ from jupyter_events import Event
99

1010

1111
class MyApplication(JupyterApp):
12-
1312
classes = [EventLogger, ...]
1413
eventlogger = Instance(EventLogger)
1514

@@ -32,9 +31,7 @@ Register an event schema with the logger.
3231
type: string
3332
"""
3433

35-
self.eventlogger.register_event_schema(
36-
schema=schema
37-
)
34+
self.eventlogger.register_event_schema(schema=schema)
3835
```
3936

4037
Call `.emit(...)` within the application to emit an instance of the event.
@@ -44,7 +41,9 @@ Call `.emit(...)` within the application to emit an instance of the event.
4441
# Do something
4542
...
4643
# Emit event telling listeners that this event happened.
47-
self.eventlogger.emit(schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"})
44+
self.eventlogger.emit(
45+
schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"}
46+
)
4847
# Do something else...
4948
...
5049
```

docs/user_guide/configure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is usually done using a Jupyter configuration file, e.g. `jupyter_config.py
99
from logging import FileHandler
1010

1111
# Log events to a local file on disk.
12-
handler = FileHandler('events.txt')
12+
handler = FileHandler("events.txt")
1313

1414
# Explicitly list the types of events
1515
# to record and what properties or what categories

docs/user_guide/event-schemas.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ Schema: {
5252

5353
The registry's validators will be used to check incoming events to ensure all outgoing, emitted events are registered and follow the expected form.
5454

55-
Lastly, if an incoming event is not found in the registry, it does not get emitted. This ensures that we only collect data that we explicity register with the logger.
55+
Lastly, if an incoming event is not found in the registry, it does not get emitted. This ensures that we only collect data that we explicitly register with the logger.

docs/user_guide/first-event.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ logger.register_event_schema(schema)
3131
Now that the logger knows about the event, it needs to know _where_ to send it. To do this, we register a logging _Handler_ —borrowed from Python's standard [`logging`](https://docs.python.org/3/library/logging.html) library—to route the events to the proper place.
3232

3333
```python
34-
# We will import one of the handlers from Python's logging libray
34+
# We will import one of the handlers from Python's logging library
3535
from logging import StreamHandler
3636

3737
handler = StreamHandler()
@@ -45,11 +45,7 @@ The logger knows about the event and where to send it; all that's left is to emi
4545
from jupyter_events import Event
4646

4747
logger.emit(
48-
schema_id="http://myapplication.org/example-event",
49-
data={
50-
"name": "My Event"
51-
}
52-
)
48+
schema_id="http://myapplication.org/example-event", data={"name": "My Event"}
5349
)
5450
```
5551

docs/user_guide/listeners.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ Define a listener (async) function:
1111
```python
1212
from jupyter_events.logger import EventLogger
1313

14+
1415
async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None:
1516
print("hello, from my listener")
1617
```
1718

1819
Hook this listener to a specific event type:
1920

2021
```python
21-
event_logger.add_listener(schema_id="http://event.jupyter.org/my-event", listener=my_listener)
22+
event_logger.add_listener(
23+
schema_id="http://event.jupyter.org/my-event", listener=my_listener
24+
)
2225
```
2326

2427
Now, every time a `"http://event.jupyter.org/test"` event is emitted from the EventLogger, this listener will be called.

jupyter_events/cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RC:
2121

2222
OK = 0
2323
INVALID = 1
24-
UNPARSEABLE = 2
24+
UNPARSABLE = 2
2525
NOT_FOUND = 3
2626

2727

@@ -38,7 +38,7 @@ class EMOJI:
3838

3939
@click.group()
4040
@click.version_option()
41-
def main():
41+
def main() -> None:
4242
"""A simple CLI tool to quickly validate JSON schemas against
4343
Jupyter Event's custom validator.
4444
@@ -77,7 +77,7 @@ def validate(ctx: click.Context, schema: str) -> int:
7777
# no need for full tracestack for user error exceptions. just print
7878
# the error message and return
7979
error_console.print(f"[bold red]ERROR[/]: {e}")
80-
return ctx.exit(RC.UNPARSEABLE)
80+
return ctx.exit(RC.UNPARSABLE)
8181

8282
# Print what was found.
8383
schema_json = JSON(json.dumps(_schema))
@@ -93,7 +93,7 @@ def validate(ctx: click.Context, schema: str) -> int:
9393
error_console.rule("Results", style=Style(color="red"))
9494
error_console.print(f"[red]{EMOJI.X} [white]The schema failed to validate.")
9595
error_console.print("\nWe found the following error with your schema:")
96-
out = escape(str(err)) # type:ignore
96+
out = escape(str(err)) # type:ignore[assignment]
9797
error_console.print(Padding(out, (1, 0, 1, 4)))
9898
return ctx.exit(RC.INVALID)
9999

0 commit comments

Comments
 (0)