Skip to content

Commit

Permalink
Small changes in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JrooTJunior committed May 12, 2021
1 parent 9f902ef commit 74db2c4
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![MIT License](https://img.shields.io/pypi/l/aiogram.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![Supported python versions](https://img.shields.io/pypi/pyversions/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram)
[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-4.6-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-5.2-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
[![PyPi Package Version](https://img.shields.io/pypi/v/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram)
[![PyPi status](https://img.shields.io/pypi/status/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram)
[![Downloads](https://img.shields.io/pypi/dm/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram)
Expand Down
12 changes: 12 additions & 0 deletions aiogram/dispatcher/middlewares/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@


class BaseMiddleware(ABC, Generic[T]):
"""
Generic middleware class
"""

@abstractmethod
async def __call__(
self,
handler: Callable[[T, Dict[str, Any]], Awaitable[Any]],
event: T,
data: Dict[str, Any],
) -> Any: # pragma: no cover
"""
Execute middleware
:param handler: Wrapped handler in middlewares chain
:param event: Incoming event (Subclass of :class:`aiogram.types.base.TelegramObject`)
:param data: Contextual data. Will be mapped to handler arguments
:return: :class:`Any`
"""
pass
1 change: 1 addition & 0 deletions docs2/dispatcher/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Dispatcher is subclass of router and should be always is root router.
class_based_handlers/index
filters/index
filters/magic_filters
middlewares
2 changes: 1 addition & 1 deletion docs2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ aiogram
:target: https://pypi.python.org/pypi/aiogram
:alt: Supported python versions

.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-4.9-blue.svg?logo=telegram
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.2-blue.svg?logo=telegram
:target: https://core.telegram.org/bots/api
:alt: Telegram Bot API

Expand Down
48 changes: 13 additions & 35 deletions docs2/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,31 @@ Using PIP
pip install -U aiogram
Using AUR
---------

Using poetry
------------

.. code-block:: bash
poetry add aiogram
Using Pipenv
------------

.. code-block:: bash
pipenv install aiogram
Using poetry
------------

.. code-block:: bash
poetry add aiogram
*aiogram* 2.x is also available in Arch Linux Repository, so you can install this framework
on any Arch-based distribution like Arch Linux, Antergos, Manjaro, etc.

Using Pacman
------------
*aiogram* is also available in Arch Linux Repository, so you can install this framework on any
Arch-based distribution like Arch Linux, Antergos, Manjaro, etc. To do this, just use pacman
to install the `python-aiogram <https://archlinux.org/packages/community/any/python-aiogram/>`_ package:
To do this, just use pacman to install the *python-aiogram* package:

.. code-block:: bash
pacman -S python-aiogram
$ pacman -S python-aiogram
Development build (3.x)
=======================

From private PyPi index
From test PyPi index
-----------------------

On every push to the `dev-3.x` branch GitHub Actions build the package and publish
to the `2038.host <https://aiogram.2038.io/simple>`_ server with seems like official PyPi files structure.
That's mean you can always install latest (may be unstable) build via next command:

.. code-block:: bash
pip install --extra-index-url https://dev-docs.aiogram.dev/simple --pre aiogram
pip install -U --extra-index-url https://test.pypi.org/simple/ --pre aiogram
From GitHub
-----------

.. code-block:: bash
In this repository available only last success build. All previous builds is always removes
before uploading new one. Also before building this package all tests is also pass.
pip install https://github.com/aiogram/aiogram/archive/refs/heads/dev-3.x.zip
22 changes: 21 additions & 1 deletion scripts/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
BASE_PATTERN = r'({variable} = ")[a-z0-9.+]+(")'
PACKAGE_VERSION = re.compile(BASE_PATTERN.format(variable="__version__"))
API_VERSION = re.compile(BASE_PATTERN.format(variable="__api_version__"))
API_VERSION_BADGE = re.compile(r"(API-)[\d.]+(-blue\.svg)")

STAGE_MAPPING = {
"alpha": "a",
Expand Down Expand Up @@ -37,7 +38,8 @@ def get_telegram_api_version() -> str:


def replace_line(content: str, pattern: re.Pattern, new_value: str) -> str:
return pattern.sub(f"\\g<1>{new_value}\\g<2>", content)
result = pattern.sub(f"\\g<1>{new_value}\\g<2>", content)
return result


def write_package_meta(package_version: str, api_version: str) -> None:
Expand All @@ -51,6 +53,22 @@ def write_package_meta(package_version: str, api_version: str) -> None:
path.write_text(content)


def write_readme(package_version: str, api_version: str) -> None:
path = Path.cwd() / "README.md"
content = path.read_text()
content = replace_line(content, API_VERSION_BADGE, api_version)
print(f"Write {path}")
path.write_text(content)


def write_docs_index(package_version: str, api_version: str) -> None:
path = Path.cwd() / "docs2" / "index.rst"
content = path.read_text()
content = replace_line(content, API_VERSION_BADGE, api_version)
print(f"Write {path}")
path.write_text(content)


def write_docs_meta(package_version: str, api_version: str) -> None:
api_meta = Path.cwd() / "docs" / "_api_version.md"
package_meta = Path.cwd() / "docs" / "_package_version.md"
Expand All @@ -69,6 +87,8 @@ def main():
print(f"Telegram Bot API version: {api_version}")
write_package_meta(package_version=package_version, api_version=api_version)
write_docs_meta(package_version=package_version, api_version=api_version)
write_readme(package_version=package_version, api_version=api_version)
write_docs_index(package_version=package_version, api_version=api_version)


if __name__ == "__main__":
Expand Down
47 changes: 36 additions & 11 deletions tests/test_api/test_types/test_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
from typing import Any, Dict, Type, Union, Optional
from typing import Any, Dict, Optional, Type, Union

import pytest

from aiogram.methods import (
CopyMessage,
SendAnimation,
SendAudio,
SendContact,
Expand All @@ -21,7 +22,6 @@
SendVideo,
SendVideoNote,
SendVoice,
CopyMessage,
TelegramMethod,
)
from aiogram.types import (
Expand All @@ -35,6 +35,7 @@
Game,
Invoice,
Location,
MessageAutoDeleteTimerChanged,
PassportData,
PhotoSize,
Poll,
Expand All @@ -46,10 +47,9 @@
Video,
VideoNote,
Voice,
MessageAutoDeleteTimerChanged,
VoiceChatStarted,
VoiceChatEnded,
VoiceChatParticipantsInvited,
VoiceChatStarted,
)
from aiogram.types.message import ContentType, Message

Expand All @@ -71,7 +71,11 @@
message_id=42,
date=datetime.datetime.now(),
animation=Animation(
file_id="file id", file_unique_id="file id", width=42, height=42, duration=0,
file_id="file id",
file_unique_id="file id",
width=42,
height=42,
duration=0,
),
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
Expand Down Expand Up @@ -106,15 +110,25 @@
message_id=42,
date=datetime.datetime.now(),
sticker=Sticker(
file_id="file id", file_unique_id="file id", width=42, height=42, is_animated=False,
file_id="file id",
file_unique_id="file id",
width=42,
height=42,
is_animated=False,
),
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
)
TEST_MESSAGE_VIDEO = Message(
message_id=42,
date=datetime.datetime.now(),
video=Video(file_id="file id", file_unique_id="file id", width=42, height=42, duration=0,),
video=Video(
file_id="file id",
file_unique_id="file id",
width=42,
height=42,
duration=0,
),
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
)
Expand Down Expand Up @@ -264,7 +278,8 @@
message_id=42,
date=datetime.datetime.now(),
passport_data=PassportData(
data=[], credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
data=[],
credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
),
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
Expand All @@ -275,7 +290,10 @@
poll=Poll(
id="QA",
question="Q",
options=[PollOption(text="A", voter_count=0), PollOption(text="B", voter_count=0),],
options=[
PollOption(text="A", voter_count=0),
PollOption(text="B", voter_count=0),
],
is_closed=False,
is_anonymous=False,
type="quiz",
Expand Down Expand Up @@ -410,7 +428,12 @@ def test_content_type(self, message: Message, content_type: str):
["sticker", dict(sticker="sticker"), SendSticker],
[
"venue",
dict(latitude=0.42, longitude=0.42, title="title", address="address",),
dict(
latitude=0.42,
longitude=0.42,
title="title",
address="address",
),
SendVenue,
],
["video", dict(video="video"), SendVideo],
Expand Down Expand Up @@ -513,7 +536,9 @@ def test_copy_to(self):
],
)
def test_send_copy(
self, message: Message, expected_method: Optional[Type[TelegramMethod]],
self,
message: Message,
expected_method: Optional[Type[TelegramMethod]],
):
if expected_method is None:
with pytest.raises(TypeError, match="This type of message can't be copied."):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dispatcher/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from aiogram.types import (
CallbackQuery,
Chat,
ChatMember,
ChatMemberUpdated,
ChosenInlineResult,
InlineQuery,
Message,
Expand All @@ -26,8 +28,6 @@
ShippingQuery,
Update,
User,
ChatMemberUpdated,
ChatMember,
)
from tests.mocked_bot import MockedBot

Expand Down

0 comments on commit 74db2c4

Please sign in to comment.