Skip to content

Commit

Permalink
Merge pull request #436 from chirizxc/develop
Browse files Browse the repository at this point in the history
drop support python 3.8, drop flake 8, add ruff
  • Loading branch information
Tishka17 authored Nov 6, 2024
2 parents 33dacdf + 6897cc6 commit e3598bf
Show file tree
Hide file tree
Showing 111 changed files with 953 additions and 601 deletions.
41 changes: 0 additions & 41 deletions .flake8

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand All @@ -34,15 +33,16 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . -r requirements_dev.txt
pip install diagrams
uv pip install . -r requirements_dev.txt --system
uv pip install diagrams --system
- name: Run flake8
run: |
python -m flake8 src/aiogram_dialog tests example
- name: Run Ruff
run: ruff check src/aiogram_dialog tests example

- name: Run tests
run: |
Expand Down
74 changes: 74 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
line-length = 79
target-version="py39"
src = ["src"]

include = ["src/**.py", "tests/**.py", "example/**.py"]
exclude = ["docs"]

lint.select = ["ALL"]
lint.ignore = [
"ARG",
"ANN",
"D",
"DTZ",
"TD",
"EM101",
"EM102",
"PT001",
"PT023",
"SIM108",
"SIM114",
"TRY003",
"TCH003",
"PLW2901",
"RET505",
"PLR0913",
"UP038",
"TCH001",
"SIM103",
"ISC003",
"A002",
"FA100",
"TRY400",
"FBT001",
"FBT002",
"S311",
"N818",
"B904",
"FIX002",
"RUF012",
"TCH002",
"TRY201",
"ISC002",
"ASYNC230",
"UP007",
"N804",
"B008",
"BLE001",
"RUF009",
"PYI034",
]

[lint.per-file-ignores]
"src/aiogram_dialog/tools/**" = [
"S101",
"SLF001",
"PTH",
]
"src/aiogram_dialog/test_tools/**"= [
"S101",
"PTH"
]
"tests/**" = [
"TID252",
"PLR2004",
"S101",
"INP001",
"FBT003",
]
"example/**" = [
"INP001",
"ERA001",
"RUF001",
"PTH",
]
24 changes: 12 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath("."))

import datetime

# -- Project information -----------------------------------------------------

project = 'aiogram-dialog'
copyright = f'{datetime.date.today().year}, Tishka17'
author = 'Tishka17'
master_doc = 'index'
project = "aiogram-dialog"
copyright = f"{datetime.date.today().year}, Tishka17"
author = "Tishka17"
master_doc = "index"

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx_copybutton',
"sphinx.ext.autodoc",
"sphinx_copybutton",
]
autodoc_type_aliases = {
}
autodoc_typehints = 'description'
autodoc_typehints = "description"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -49,9 +49,9 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_theme = "furo"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
12 changes: 6 additions & 6 deletions example/custom_media_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
from io import BytesIO
from typing import Union


from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import BufferedInputFile, ContentType, InputFile, Message
from PIL import Image, ImageDraw, ImageFont


from aiogram_dialog import (
Dialog, DialogManager, setup_dialogs,
StartMode, Window,
Dialog,
DialogManager,
StartMode,
Window,
setup_dialogs,
)
from aiogram_dialog.api.entities import MediaAttachment
from aiogram_dialog.manager.message_manager import MessageManager
from aiogram_dialog.widgets.kbd import Back, Next, Row
from aiogram_dialog.widgets.media import StaticMedia
from aiogram_dialog.widgets.text import Const


src_dir = os.path.normpath(os.path.join(__file__, os.path.pardir))

API_TOKEN = os.getenv("BOT_TOKEN")
Expand Down Expand Up @@ -115,5 +115,5 @@ async def main():
await dp.start_polling(bot)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(main())
8 changes: 6 additions & 2 deletions example/i18n/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
from i18n_middleware import I18nMiddleware

from aiogram_dialog import (
Dialog, DialogManager, setup_dialogs, StartMode, Window,
Dialog,
DialogManager,
StartMode,
Window,
setup_dialogs,
)
from aiogram_dialog.widgets.kbd import Button, Cancel, Row

Expand Down Expand Up @@ -87,5 +91,5 @@ async def main():
await dp.start_polling(bot)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(main())
4 changes: 2 additions & 2 deletions example/i18n/i18n_format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Protocol
from typing import Any, Protocol

from aiogram_dialog.api.protocols import DialogManager
from aiogram_dialog.widgets.common import WhenCondition
Expand All @@ -21,7 +21,7 @@ def __init__(self, text: str, when: WhenCondition = None):
super().__init__(when)
self.text = text

async def _render_text(self, data: Dict, manager: DialogManager) -> str:
async def _render_text(self, data: dict, manager: DialogManager) -> str:
format_text = manager.middleware_data.get(
I18N_FORMAT_KEY, default_format_text,
)
Expand Down
9 changes: 5 additions & 4 deletions example/i18n/i18n_middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Awaitable, Callable, Dict, Union
from collections.abc import Awaitable, Callable
from typing import Any, Union

from aiogram.dispatcher.middlewares.base import BaseMiddleware
from aiogram.types import CallbackQuery, Message
Expand All @@ -9,7 +10,7 @@
class I18nMiddleware(BaseMiddleware):
def __init__(
self,
l10ns: Dict[str, FluentLocalization],
l10ns: dict[str, FluentLocalization],
default_lang: str,
):
super().__init__()
Expand All @@ -19,11 +20,11 @@ def __init__(
async def __call__(
self,
handler: Callable[
[Union[Message, CallbackQuery], Dict[str, Any]],
[Union[Message, CallbackQuery], dict[str, Any]],
Awaitable[Any],
],
event: Union[Message, CallbackQuery],
data: Dict[str, Any],
data: dict[str, Any],
) -> Any:
# some language/locale retrieving logic
if event.from_user:
Expand Down
10 changes: 7 additions & 3 deletions example/input_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from aiogram.types import CallbackQuery, Message

from aiogram_dialog import (
Dialog, DialogManager, setup_dialogs, StartMode, Window,
Dialog,
DialogManager,
StartMode,
Window,
setup_dialogs,
)
from aiogram_dialog.api.entities import MediaAttachment, MediaId
from aiogram_dialog.widgets.common import ManagedScroll
Expand Down Expand Up @@ -57,7 +61,7 @@ async def getter(dialog_manager: DialogManager, **kwargs) -> dict:
)
else:
media = MediaAttachment(
url="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Image_not_available.png/800px-Image_not_available.png?20210219185637", # noqa: E501
url="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Image_not_available.png/800px-Image_not_available.png?20210219185637",
type=ContentType.PHOTO,
)
return {
Expand Down Expand Up @@ -105,5 +109,5 @@ async def main():
await dp.start_polling(bot)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(main())
9 changes: 7 additions & 2 deletions example/launch_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from aiogram.types import Message

from aiogram_dialog import (
Dialog, DialogManager, LaunchMode, setup_dialogs, StartMode, Window,
Dialog,
DialogManager,
LaunchMode,
StartMode,
Window,
setup_dialogs,
)
from aiogram_dialog.widgets.kbd import Cancel, Row, Start
from aiogram_dialog.widgets.text import Const, Format
Expand Down Expand Up @@ -93,5 +98,5 @@ async def main():
await dp.start_polling(bot)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(main())
Loading

0 comments on commit e3598bf

Please sign in to comment.