Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 48 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Linting
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
ruff:
name: Ruff Linter & Formatter
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Poetry
run: pip install poetry

- name: Cache poetry virtualenv
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Install dependencies
run: poetry install

- name: Cache ruff
uses: actions/cache@v4
with:
path: .ruff_cache
key: ${{ runner.os }}-ruff-${{ github.ref_name }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-ruff-main-${{ hashFiles('poetry.lock') }}

- name: Run ruff formatter check
run: poetry run ruff format --check .

- name: Run ruff linter
run: poetry run ruff check .
56 changes: 0 additions & 56 deletions .github/workflows/pylint.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.8
hooks:
- id: ruff-format
- id: ruff-check
args: [ --fix ]
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ Symphony BDK for Python provides tools for building bots and integrating with Sy
- Install dependencies: `poetry install`
- Build the package: `poetry build`
- Run tests: `poetry run pytest`
- Perform a pylint scan locally: `poetry run pylint <module_name>`
- Perform a lint scan locally: `poetry run ruff check .`
- Format code locally: `poetry run ruff format .`
- Generate documentation locally: `cd docsrc && make html`

### Setting Up Git Hooks
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.

1. **Install development dependencies** (this will also install `pre--commit` and `ruff`):
```bash
poetry install
```
2. **Install the git hooks**:
```bash
poetry run pre-commit install
```
Now, `ruff` will automatically run on every commit, formatting your code and checking for linting errors.

### Verification
Verify the successful installation by running any of the following commands:
```
Expand Down
4 changes: 3 additions & 1 deletion examples/activities/command_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async def on_activity(self, context: CommandContext):
await self._messages.send_message(context.stream_id, "<messageML>Hello, World!</messageML>")


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

try:
logging.info("Running activity example...")
Expand Down
18 changes: 12 additions & 6 deletions examples/activities/form_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ def __init__(self, messages: MessageService):
self.messages = messages

def matches(self, context: FormReplyContext) -> bool:
return context.form_id == "gif-category-form" \
and context.get_form_value("action") == "submit" \
and context.get_form_value("category")
return (
context.form_id == "gif-category-form"
and context.get_form_value("action") == "submit"
and context.get_form_value("category")
)

async def on_activity(self, context: FormReplyContext):
category = context.get_form_value("category")
await self.messages.send_message(context.source_event.stream.stream_id,
"<messageML> You just submitted this category: " + category + "</messageML>")
await self.messages.send_message(
context.source_event.stream.stream_id,
"<messageML> You just submitted this category: " + category + "</messageML>",
)


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


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

try:
logging.info("Running activity example...")
Expand Down
4 changes: 3 additions & 1 deletion examples/activities/slash_command_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async def on_hello(context: CommandContext):
await bdk.datafeed().start()


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

try:
logging.info("Running activity example...")
Expand Down
10 changes: 6 additions & 4 deletions examples/activities/slash_command_with_arguments_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ async def run():
@activities.slash("/echo {@mention_argument}")
async def on_echo_mention(context: CommandContext):
mentioned_user = context.arguments.get_mention("mention_argument")
message = f"Mentioned user: {mentioned_user.user_display_name}, id: {mentioned_user.user_id}"
message = (
f"Mentioned user: {mentioned_user.user_display_name}, id: {mentioned_user.user_id}"
)

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

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

@activities.slash("/echo {first_string_argument} {second_string_argument}")
async def on_echo_string_arguments(context: CommandContext):

# Get string argument with get_string
first_string_argument = context.arguments.get_string("first_string_argument")

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


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

try:
logging.info("Running activity example...")
asyncio.run(run())
except KeyboardInterrupt:
logging.info("Ending activity example")

16 changes: 11 additions & 5 deletions examples/activities/user_joined_room_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import logging.config
from pathlib import Path

from symphony.bdk.core.activity.user_joined_room import UserJoinedRoomActivity, UserJoinedRoomContext
from symphony.bdk.core.activity.user_joined_room import (
UserJoinedRoomActivity,
UserJoinedRoomContext,
)
from symphony.bdk.core.config.loader import BdkConfigLoader
from symphony.bdk.core.service.message.message_service import MessageService
from symphony.bdk.core.symphony_bdk import SymphonyBdk
Expand All @@ -23,14 +26,17 @@ def matches(self, context: UserJoinedRoomContext) -> bool:
return True

async def on_activity(self, context: UserJoinedRoomContext):
await self._messages.send_message(context.stream_id,
"<messageML>Welcome to the room</messageML>")
await self._messages.send_message(
context.stream_id, "<messageML>Welcome to the room</messageML>"
)


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

try:
logging.info("Running activity example...")
asyncio.run(run())
except KeyboardInterrupt:
logging.info("Ending activity example")
logging.info("Ending activity example")
4 changes: 3 additions & 1 deletion examples/authentication/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ async def run():
logging.info(await obo_auth_session.session_token)


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

asyncio.run(run())
8 changes: 6 additions & 2 deletions examples/authentication/ext_app_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ async def run():
# nosemgrep - please don't log secrets in production; this is just for demo purposes
logging.debug("App token: %s, Symphony token: %s", ta, ts)
# nosemgrep
logging.debug("Is token pair valid: %s", await ext_app_authenticator.is_token_pair_valid(ta, ts))
logging.debug(
"Is token pair valid: %s", await ext_app_authenticator.is_token_pair_valid(ta, ts)
)


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)

asyncio.run(run())
1 change: 0 additions & 1 deletion examples/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from symphony.bdk.core.config.loader import BdkConfigLoader


config_1 = BdkConfigLoader.load_from_file("/absolute/path/to/config.yaml")

with open("/absolute/path/to/config.yaml") as config_file:
Expand Down
5 changes: 3 additions & 2 deletions examples/datafeed/datafeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ async def run():


class RealTimeEventListenerImpl(RealTimeEventListener):

async def on_message_sent(self, initiator: V4Initiator, event: V4MessageSent):
# We do not recommend logging full events in production as it could expose sensitive data
logging.debug("Received event: %s", event)


logging.config.fileConfig(Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False)
logging.config.fileConfig(
Path(__file__).parent.parent / "logging.conf", disable_existing_loggers=False
)


try:
Expand Down
49 changes: 25 additions & 24 deletions examples/datafeed/datafeed_stop_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async def run():


class RealTimeEventListenerImpl(RealTimeEventListener):

async def on_message_sent(self, initiator: V4Initiator, event: V4MessageSent):
logging.debug("Received event: %s", event.message.message_id)
await asyncio.sleep(5)
Expand All @@ -41,32 +40,34 @@ def filter(self, record):
return True


logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
"filters": {"contextFilter": {"()": "__main__.EventListenerLoggingFilter"}},
"formatters": {
"standard": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(context_id)s - %(message)s"
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"filters": {"contextFilter": {"()": "__main__.EventListenerLoggingFilter"}},
"formatters": {
"standard": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(context_id)s - %(message)s"
},
},
"handlers": {
"default": {
"level": "DEBUG",
"formatter": "standard",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout", # Default is stderr
"filters": ["contextFilter"],
},
},
},
"handlers": {
"default": {
"level": "DEBUG",
"formatter": "standard",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout", # Default is stderr
"filters": ["contextFilter"]
"loggers": {
"": { # root logger
"handlers": ["default"],
"level": "DEBUG",
"propagate": False,
}
},
},
"loggers": {
"": { # root logger
"handlers": ["default"],
"level": "DEBUG",
"propagate": False
}
}
})
)

try:
logging.info("Running datafeed example...")
Expand Down
Loading
Loading