Skip to content

Commit

Permalink
Adopt sp-repo-review (#89)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
blink1073 authored Oct 15, 2023
1 parent eb711c3 commit e3edb6a
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 235 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Run Linters
run: |
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run interrogate .
Expand All @@ -83,7 +83,7 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
dependency_type: minimum
- name: Install with miniumum versions and optional deps
- name: Install with minimum versions and optional deps
run: |
pip install -e .[test]
pip install jsonschema[format-nongpl,format_nongpl]
Expand Down
39 changes: 37 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -28,14 +29,48 @@ repos:
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/psf/black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: prettier
types_or: [yaml, html, json]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]
exclude: docs/user_guide/application.md

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell
args: ["-L", "sur,nd"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]

- repo: https://github.com/scientific-python/cookie
rev: "2023.09.21"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
14 changes: 14 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.9"
sphinx:
configuration: docs/source/conf.py
python:
install:
# install itself with pip install .
- method: pip
path: .
extra_requirements:
- docs
2 changes: 1 addition & 1 deletion docs/demo/demo-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"metadata": {},
"outputs": [],
"source": [
"# We will import one of the handlers from Python's logging libray\n",
"# We will import one of the handlers from Python's logging library\n",
"from logging import StreamHandler\n",
"\n",
"handler = StreamHandler()\n",
Expand Down
9 changes: 4 additions & 5 deletions docs/user_guide/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from jupyter_events import Event


class MyApplication(JupyterApp):

classes = [EventLogger, ...]
eventlogger = Instance(EventLogger)

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

self.eventlogger.register_event_schema(
schema=schema
)
self.eventlogger.register_event_schema(schema=schema)
```

Call `.emit(...)` within the application to emit an instance of the event.
Expand All @@ -44,7 +41,9 @@ Call `.emit(...)` within the application to emit an instance of the event.
# Do something
...
# Emit event telling listeners that this event happened.
self.eventlogger.emit(schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"})
self.eventlogger.emit(
schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"}
)
# Do something else...
...
```
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is usually done using a Jupyter configuration file, e.g. `jupyter_config.py
from logging import FileHandler

# Log events to a local file on disk.
handler = FileHandler('events.txt')
handler = FileHandler("events.txt")

# Explicitly list the types of events
# to record and what properties or what categories
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/event-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ Schema: {

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

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.
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.
8 changes: 2 additions & 6 deletions docs/user_guide/first-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ logger.register_event_schema(schema)
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.

```python
# We will import one of the handlers from Python's logging libray
# We will import one of the handlers from Python's logging library
from logging import StreamHandler

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

logger.emit(
schema_id="http://myapplication.org/example-event",
data={
"name": "My Event"
}
)
schema_id="http://myapplication.org/example-event", data={"name": "My Event"}
)
```

Expand Down
5 changes: 4 additions & 1 deletion docs/user_guide/listeners.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ Define a listener (async) function:
```python
from jupyter_events.logger import EventLogger


async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None:
print("hello, from my listener")
```

Hook this listener to a specific event type:

```python
event_logger.add_listener(schema_id="http://event.jupyter.org/my-event", listener=my_listener)
event_logger.add_listener(
schema_id="http://event.jupyter.org/my-event", listener=my_listener
)
```

Now, every time a `"http://event.jupyter.org/test"` event is emitted from the EventLogger, this listener will be called.
8 changes: 4 additions & 4 deletions jupyter_events/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RC:

OK = 0
INVALID = 1
UNPARSEABLE = 2
UNPARSABLE = 2
NOT_FOUND = 3


Expand All @@ -38,7 +38,7 @@ class EMOJI:

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

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

Expand Down
Loading

0 comments on commit e3edb6a

Please sign in to comment.