Skip to content

Commit

Permalink
Merge pull request #449 from Tishka17/develop
Browse files Browse the repository at this point in the history
2.3.0
  • Loading branch information
Tishka17 authored Dec 16, 2024
2 parents 143d8d8 + 8a30174 commit 94b7f6e
Show file tree
Hide file tree
Showing 125 changed files with 1,371 additions and 678 deletions.
41 changes: 0 additions & 41 deletions .flake8

This file was deleted.

15 changes: 8 additions & 7 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- uses: actions/checkout@v2
Expand All @@ -34,15 +34,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
68 changes: 68 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
line-length = 79
target-version="py39"
src = ["src"]

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

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


[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",
]
27 changes: 12 additions & 15 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import datetime

# sys.path.insert(0, os.path.abspath("."))
# -- Project information -----------------------------------------------------

project = 'aiogram-dialog'
copyright = f'{datetime.date.today().year}, Tishka17'
author = 'Tishka17'
master_doc = 'index'
project = "aiogram-dialog"
copyright = "%Y, 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 +46,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"]
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from typing import Dict, List

from aiogram.filters.state import StatesGroup, State
from aiogram.filters.state import State, StatesGroup
from aiogram.types import InlineKeyboardButton
from aiogram_dialog import Dialog, Window
from aiogram_dialog import DialogManager

from aiogram_dialog import Dialog, DialogManager, Window
from aiogram_dialog.widgets.kbd import SwitchInlineQuery
from aiogram_dialog.widgets.text import Const


class SwitchInlineQueryCurrentChat(SwitchInlineQuery):
async def _render_keyboard(
self,
data: Dict,
data: dict,
manager: DialogManager,
) -> List[List[InlineKeyboardButton]]:
) -> list[list[InlineKeyboardButton]]:
return [
[
InlineKeyboardButton(
Expand All @@ -34,8 +32,8 @@ class MySG(StatesGroup):
Window(
SwitchInlineQueryCurrentChat(
Const("Some search"), # Button text
Const("query") # additional query. Optional
Const("query"), # additional query. Optional
),
state=MySG.main
)
state=MySG.main,
),
)
12 changes: 5 additions & 7 deletions docs/widgets/hiding/example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Dict

from aiogram.filters.state import StatesGroup, State
from aiogram.filters.state import State, StatesGroup
from magic_filter import F

from aiogram_dialog import Window, DialogManager
from aiogram_dialog import DialogManager, Window
from aiogram_dialog.widgets.common import Whenable
from aiogram_dialog.widgets.kbd import Button, Row, Group
from aiogram_dialog.widgets.kbd import Button, Group, Row
from aiogram_dialog.widgets.text import Const, Format, Multi


Expand All @@ -20,15 +18,15 @@ async def get_data(**kwargs):
}


def is_tishka17(data: Dict, widget: Whenable, manager: DialogManager):
def is_tishka17(data: dict, widget: Whenable, manager: DialogManager):
return data.get("name") == "Tishka17"


window = Window(
Multi(
Const("Hello"),
Format("{name}", when="extended"),
sep=" "
sep=" ",
),
Group(
Row(
Expand Down
8 changes: 5 additions & 3 deletions docs/widgets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Widgets and Rendering
Base information
********************

Currently there are 4 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>` and you can create your own :ref:`widgets<custom_widgets>`.
Currently there are 5 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>`, :ref:`link preview<link_preview>` and you can create your own :ref:`widgets<custom_widgets>`.

* **Texts** used to render text anywhere in dialog. It can be message text, button title and so on.
* **Keyboards** represent parts of ``InlineKeyboard``
* **Media** represent media attachment to message
* **Input** allows to process incoming messages from user. Is has no representation.
* **Link Preview** used to manage link previews in messages.

Widgets can display static (e.g. ``Const``) and dynamic (e.g. ``Format``) content. To use dynamic data you have to set it. See :ref:`passing data <passing_data>`.

Expand All @@ -37,5 +38,6 @@ Also there are 2 general types:
keyboard/index
input/index
media/index
link_preview/index
hiding/index
custom_widgets/index
custom_widgets/index
15 changes: 9 additions & 6 deletions docs/widgets/keyboard/calendar/custom.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from typing import Dict

from aiogram_dialog import DialogManager
from aiogram_dialog.widgets.kbd import (
Calendar, CalendarScope, CalendarUserConfig,
Calendar,
CalendarScope,
CalendarUserConfig,
)
from aiogram_dialog.widgets.kbd.calendar_kbd import (
CalendarDaysView, CalendarMonthView, CalendarScopeView, CalendarYearsView,
CalendarDaysView,
CalendarMonthView,
CalendarScopeView,
CalendarYearsView,
)
from aiogram_dialog.widgets.text import Const, Format


class CustomCalendar(Calendar):
def _init_views(self) -> Dict[CalendarScope, CalendarScopeView]:
def _init_views(self) -> dict[CalendarScope, CalendarScopeView]:
return {
CalendarScope.DAYS: CalendarDaysView(
self._item_callback_data, self.config,
Expand All @@ -28,7 +31,7 @@ def _init_views(self) -> Dict[CalendarScope, CalendarScopeView]:

async def _get_user_config(
self,
data: Dict,
data: dict,
manager: DialogManager,
) -> CalendarUserConfig:
return CalendarUserConfig(
Expand Down
27 changes: 27 additions & 0 deletions docs/widgets/link_preview/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from aiogram.filters.state import State, StatesGroup

from aiogram_dialog import Window
from aiogram_dialog.widgets.link_preview import LinkPreview
from aiogram_dialog.widgets.text import Const


class SG(StatesGroup):
MAIN = State()
SECOND = State()


window = Window(
Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
LinkPreview(is_disabled=True),
state=SG.MAIN,
)

second_window = Window(
Const("some text"),
LinkPreview(
url=Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
prefer_small_media=True,
show_above_text=True,
),
state=SG.MAIN,
)
23 changes: 23 additions & 0 deletions docs/widgets/link_preview/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _link_preview:

LinkPreview
*************

The **LinkPreview** widget is used to manage link previews in messages.

Parameters:

* ``url``: A ``TextWidget`` with URL to be used in the link preview. If not provided, the first URL found in the message will be used.
* ``is_disabled``: that controls whether the link preview is displayed. If ``True``, the preview will be disabled.
* ``prefer_small_media``: that controls if the media in the link preview should be displayed in a smaller size. Ignored if media size change is not supported.
* ``prefer_large_media``: that controls if the media in the link preview should be enlarged. Ignored if media size change is not supported.
* ``show_above_text``: that specifies whether the link preview should be displayed above the message text. If ``True``, link preview be displayed above the message text.


Code example:

.. literalinclude:: ./example.py

.. autoclass:: aiogram_dialog.widgets.link_preview.LinkPreview
:special-members: __init__
:members: render_link_preview, _render_link_preview
Loading

0 comments on commit 94b7f6e

Please sign in to comment.