Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt sp-repo-review #89

Merged
merged 9 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 36 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,47 @@ 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]

- 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
43 changes: 21 additions & 22 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 @@ -21,32 +20,32 @@ class MyApplication(JupyterApp):
Register an event schema with the logger.

```python
schema = """
$id: http://myapplication.org/my-method
version: 1
title: My Method Executed
description: My method was executed one time.
properties:
msg:
title: Message
type: string
"""

self.eventlogger.register_event_schema(
schema=schema
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent here was intentional, since it's part of the method from the preview code chunk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

schema = """
$id: http://myapplication.org/my-method
version: 1
title: My Method Executed
description: My method was executed one time.
properties:
msg:
title: Message
type: string
"""

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

Call `.emit(...)` within the application to emit an instance of the event.

```python
def my_method(self):
# Do something
...
# Emit event telling listeners that this event happened.
self.eventlogger.emit(schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"})
# Do something else...
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This indent is intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this was auto-formatted by blacken-docs, maybe we need to skip this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by skipping

def my_method(self):
# Do something
...
# Emit event telling listeners that this event happened.
self.eventlogger.emit(
schema_id="myapplication.org/my-method", data={"msg": "Hello, world!"}
)
# Do something else...
...
```

Great! Now your application is logging events from within. Deployers of your application can configure the system to listen to this event using Jupyter's configuration system. This usually means reading a `jupyter_config.py` file like this:
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
Loading