Skip to content

Commit

Permalink
style: format files with ruff (#107)
Browse files Browse the repository at this point in the history
* style: format files with ruff

* chore: run tests on python 3.9 and newer

- removed all older tests version
- removed sort
- use ruff instead of black

* tests: default test are on py 3.12

* fix: remove unused imports

* fix: add SlackBackend to __all__

* fix: ensure certain checks are run on py 3.12
  • Loading branch information
sijis authored Oct 28, 2024
1 parent e9b0b62 commit 17460e2
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 93 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.2.2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5.2.0
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -41,21 +41,16 @@ jobs:
tox -e py
- name: Check Distribution
if: ${{ matrix.python-version }} == '3.9'
if: ${{ matrix.python-version == '3.12' }}
run: |
tox -e dist-check
- name: Codestyle
if: ${{ matrix.python-version }} == '3.9'
if: ${{ matrix.python-version == '3.12' }}
run: |
tox -e codestyle
- name: Lint - sort
if: ${{ matrix.python-version }} == '3.9'
run: |
tox -e sort
- name: Security
if: ${{ matrix.python-version }} == '3.9'
if: ${{ matrix.python-version == '3.12' }}
run: |
tox -e security
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.isort]
multi_line_output = 3
line_length = 100
line_length = 120
include_trailing_comma = true

[tool.black]
line-length = 100
line-length = 120
2 changes: 2 additions & 0 deletions src/slackv3/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .slackv3 import SlackBackend

__all__ = ["SlackBackend"]
8 changes: 6 additions & 2 deletions src/slackv3/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
from markdown.extensions.extra import ExtraExtension
from markdown.preprocessors import Preprocessor

MARKDOWN_LINK_REGEX = re.compile(r"(?<!!)\[(?P<text>[^\]]+?)\]\((?P<uri>[a-zA-Z0-9]+?:\S+?)\)")
MARKDOWN_LINK_REGEX = re.compile(
r"(?<!!)\[(?P<text>[^\]]+?)\]\((?P<uri>[a-zA-Z0-9]+?:\S+?)\)"
)


def slack_markdown_converter(compact_output=False):
"""
This is a Markdown converter for use with Slack.
"""
enable_format("imtext", IMTEXT_CHRS, borders=not compact_output)
md = Markdown(output_format="imtext", extensions=[ExtraExtension(), AnsiExtension()])
md = Markdown(
output_format="imtext", extensions=[ExtraExtension(), AnsiExtension()]
)
md.preprocessors.register(LinkPreProcessor(md), "LinkPreProcessor", 30)
md.stripTopLevelTags = False
return md
Expand Down
14 changes: 10 additions & 4 deletions src/slackv3/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class SlackPerson(Person):
def __init__(self, webclient: WebClient, userid=None, channelid=None):
if userid is not None and userid[0] not in ("U", "W", "B"):
raise Exception(
f"This is not a Slack user or bot id: {userid} " "(should start with B, U or W)"
f"This is not a Slack user or bot id: {userid} "
"(should start with B, U or W)"
)

if channelid is not None and channelid[0] not in ("D", "C", "G"):
raise Exception(
f"This is not a valid Slack channelid: {channelid} " "(should start with D, C or G)"
f"This is not a valid Slack channelid: {channelid} "
"(should start with D, C or G)"
)

self._userid = userid
Expand Down Expand Up @@ -93,13 +95,17 @@ def _cache_user_info(self):
res = self._webclient.users_info(user=self._userid)

if res["ok"] is False:
log.error(f"Cannot find user with ID {self._userid}. Slack Error: {res['error']}")
log.error(
f"Cannot find user with ID {self._userid}. Slack Error: {res['error']}"
)
else:
if "bot" in res:
self._user_info["display_name"] = res["bot"].get("name", "")
else:
for attribute in ["real_name", "display_name", "email"]:
self._user_info[attribute] = res["user"]["profile"].get(attribute, "")
self._user_info[attribute] = res["user"]["profile"].get(
attribute, ""
)

team = None
# Normal users
Expand Down
11 changes: 8 additions & 3 deletions src/slackv3/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def create(self, private=False):
try:
if private:
log.info(f"Creating private conversation {self}.")
self._bot.slack_web.conversations_create(name=self.name, is_private=True)
self._bot.slack_web.conversations_create(
name=self.name, is_private=True
)
else:
log.info(f"Creating conversation {self}.")
self._bot.slack_web.conversations_create(name=self.name)
Expand Down Expand Up @@ -238,7 +240,9 @@ def occupants(self):
)
if res["ok"] is True:
for member in res["members"]:
occupants.append(SlackRoomOccupant(self._webclient, member, self.id, self._bot))
occupants.append(
SlackRoomOccupant(self._webclient, member, self.id, self._bot)
)
cursor = res["response_metadata"]["next_cursor"]
else:
log.exception(
Expand All @@ -249,7 +253,8 @@ def occupants(self):

def invite(self, *args):
users = {
user["name"]: user["id"] for user in self._webclient.api_call("users.list")["members"]
user["name"]: user["id"]
for user in self._webclient.api_call("users.list")["members"]
}

for user in args:
Expand Down
Loading

0 comments on commit 17460e2

Please sign in to comment.