Skip to content

Commit 94669cf

Browse files
authored
CAIP-9 extend tooling with ruff formatter(replacing pylint) (#372)
* CAIP-9 add pre commit hook to run linter * CAIP-9 update ruff config * CAIP-9 update ruff config * CAIP-9 update ruff config * CAIP-9 try adding py file * CAIP-9 add ruff formatter * CAIP-9 rename workflow file and update readme * CAIP-9 remove dependencies * CAIP-9 update readme * CAIP-9 rebase from main * CAIP-9 fix broken tests * CAIP-9 extend line length * CAIP-9 fix missing files
1 parent 9576b92 commit 94669cf

159 files changed

Lines changed: 4406 additions & 3248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linting.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Linting
2+
on:
3+
push:
4+
branches: [ "main" ]
5+
pull_request:
6+
branches: [ "main" ]
7+
8+
jobs:
9+
ruff:
10+
name: Ruff Linter & Formatter
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python 3.9
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.9
21+
22+
- name: Install Poetry
23+
run: pip install poetry
24+
25+
- name: Cache poetry virtualenv
26+
uses: actions/cache@v4
27+
with:
28+
path: ~/.cache/pypoetry/virtualenvs
29+
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-poetry-
32+
33+
- name: Install dependencies
34+
run: poetry install
35+
36+
- name: Cache ruff
37+
uses: actions/cache@v4
38+
with:
39+
path: .ruff_cache
40+
key: ${{ runner.os }}-ruff-${{ github.ref_name }}-${{ hashFiles('poetry.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-ruff-main-${{ hashFiles('poetry.lock') }}
43+
44+
- name: Run ruff formatter check
45+
run: poetry run ruff format --check .
46+
47+
- name: Run ruff linter
48+
run: poetry run ruff check .

.github/workflows/pylint.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.12.8
4+
hooks:
5+
- id: ruff-format
6+
- id: ruff-check
7+
args: [ --fix ]

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,23 @@ Symphony BDK for Python provides tools for building bots and integrating with Sy
2323
- Install dependencies: `poetry install`
2424
- Build the package: `poetry build`
2525
- Run tests: `poetry run pytest`
26-
- Perform a pylint scan locally: `poetry run pylint <module_name>`
26+
- Perform a lint scan locally: `poetry run ruff check .`
27+
- Format code locally: `poetry run ruff format .`
2728
- Generate documentation locally: `cd docsrc && make html`
2829

30+
### Setting Up Git Hooks
31+
This project uses `pre-commit` with `ruff` to automatically format and lint code. This is the recommended setup for contributors to ensure code style consistency.
32+
33+
1. **Install development dependencies** (this will also install `pre--commit` and `ruff`):
34+
```bash
35+
poetry install
36+
```
37+
2. **Install the git hooks**:
38+
```bash
39+
poetry run pre-commit install
40+
```
41+
Now, `ruff` will automatically run on every commit, formatting your code and checking for linting errors.
42+
2943
### Verification
3044
Verify the successful installation by running any of the following commands:
3145
```

examples/activities/command_activity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ async def on_activity(self, context: CommandContext):
2626
await self._messages.send_message(context.stream_id, "<messageML>Hello, World!</messageML>")
2727

2828

29-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
29+
logging.config.fileConfig(
30+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
31+
)
3032

3133
try:
3234
logging.info("Running activity example...")

examples/activities/form_activity.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,27 @@ def __init__(self, messages: MessageService):
3232
self.messages = messages
3333

3434
def matches(self, context: FormReplyContext) -> bool:
35-
return context.form_id == "gif-category-form" \
36-
and context.get_form_value("action") == "submit" \
37-
and context.get_form_value("category")
35+
return (
36+
context.form_id == "gif-category-form"
37+
and context.get_form_value("action") == "submit"
38+
and context.get_form_value("category")
39+
)
3840

3941
async def on_activity(self, context: FormReplyContext):
4042
category = context.get_form_value("category")
41-
await self.messages.send_message(context.source_event.stream.stream_id,
42-
"<messageML> You just submitted this category: " + category + "</messageML>")
43+
await self.messages.send_message(
44+
context.source_event.stream.stream_id,
45+
"<messageML> You just submitted this category: " + category + "</messageML>",
46+
)
4347

4448

4549
def load_gif_elements_form():
4650
return (Path(__file__).parent.parent / "resources/gif.mml.xml").read_text(encoding="utf-8")
4751

4852

49-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
53+
logging.config.fileConfig(
54+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
55+
)
5056

5157
try:
5258
logging.info("Running activity example...")

examples/activities/slash_command_activity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ async def on_hello(context: CommandContext):
2222
await bdk.datafeed().start()
2323

2424

25-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
25+
logging.config.fileConfig(
26+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
27+
)
2628

2729
try:
2830
logging.info("Running activity example...")

examples/activities/slash_command_with_arguments_activity.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ async def run():
1616
@activities.slash("/echo {@mention_argument}")
1717
async def on_echo_mention(context: CommandContext):
1818
mentioned_user = context.arguments.get_mention("mention_argument")
19-
message = f"Mentioned user: {mentioned_user.user_display_name}, id: {mentioned_user.user_id}"
19+
message = (
20+
f"Mentioned user: {mentioned_user.user_display_name}, id: {mentioned_user.user_id}"
21+
)
2022

2123
await messages.send_message(context.stream_id, f"<messageML>{message}</messageML>")
2224

@@ -36,7 +38,6 @@ async def on_echo_cashtag(context: CommandContext):
3638

3739
@activities.slash("/echo {first_string_argument} {second_string_argument}")
3840
async def on_echo_string_arguments(context: CommandContext):
39-
4041
# Get string argument with get_string
4142
first_string_argument = context.arguments.get_string("first_string_argument")
4243

@@ -52,11 +53,12 @@ async def on_echo_string_arguments(context: CommandContext):
5253
await bdk.datafeed().start()
5354

5455

55-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
56+
logging.config.fileConfig(
57+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
58+
)
5659

5760
try:
5861
logging.info("Running activity example...")
5962
asyncio.run(run())
6063
except KeyboardInterrupt:
6164
logging.info("Ending activity example")
62-

examples/activities/user_joined_room_activity.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import logging.config
33
from pathlib import Path
44

5-
from symphony.bdk.core.activity.user_joined_room import UserJoinedRoomActivity, UserJoinedRoomContext
5+
from symphony.bdk.core.activity.user_joined_room import (
6+
UserJoinedRoomActivity,
7+
UserJoinedRoomContext,
8+
)
69
from symphony.bdk.core.config.loader import BdkConfigLoader
710
from symphony.bdk.core.service.message.message_service import MessageService
811
from symphony.bdk.core.symphony_bdk import SymphonyBdk
@@ -23,14 +26,17 @@ def matches(self, context: UserJoinedRoomContext) -> bool:
2326
return True
2427

2528
async def on_activity(self, context: UserJoinedRoomContext):
26-
await self._messages.send_message(context.stream_id,
27-
"<messageML>Welcome to the room</messageML>")
29+
await self._messages.send_message(
30+
context.stream_id, "<messageML>Welcome to the room</messageML>"
31+
)
2832

2933

30-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
34+
logging.config.fileConfig(
35+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
36+
)
3137

3238
try:
3339
logging.info("Running activity example...")
3440
asyncio.run(run())
3541
except KeyboardInterrupt:
36-
logging.info("Ending activity example")
42+
logging.info("Ending activity example")

examples/authentication/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ async def run():
1818
logging.info(await obo_auth_session.session_token)
1919

2020

21-
logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
21+
logging.config.fileConfig(
22+
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
23+
)
2224

2325
asyncio.run(run())

0 commit comments

Comments
 (0)