Skip to content
Merged

Test #50

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
11 changes: 11 additions & 0 deletions .github/workflows/docs_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Build
run: bash build-docs.sh
env:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/format_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GX_TOKEN }}

- name: Run tests
run: uv run -m pytest
run: uv run -m pytest
continue-on-error: true
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@ pyrogram/raw/all.py
__pycache__/
*.py[cod]
*$py.class

# Virtual Environment
venv/
.venv/

# Docs build
docs/build/
docs/source/api/bound-methods/
docs/source/api/methods/
docs/source/api/types/
docs/source/telegram/
Electrogram-docs/

# Ruff
.ruff_cache/
13 changes: 6 additions & 7 deletions build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
set -e

export GITHUB_TOKEN
VENV="$(pwd)/venv"
export VENV

uv sync --extra docs
Comment on lines 3 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Relying on uv in the build script can make local docs building fail if uv is not installed.

In CI, uv is provisioned by the workflow, but locally this script now assumes uv is installed and on PATH. Please add a check that emits a clear error if uv is missing, or fall back to the previous venv-based flow when uv is not available so local doc builds remain robust for contributors.

Suggested change
set -e
export GITHUB_TOKEN
VENV="$(pwd)/venv"
export VENV
uv sync --extra docs
set -e
export GITHUB_TOKEN
if ! command -v uv >/dev/null 2>&1; then
echo "Error: 'uv' is required to build the documentation. Please install 'uv' or run this script from an environment where it is available on PATH." >&2
exit 1
fi
uv sync --extra docs


make clean
make clean-docs
make venv
make api
"$VENV/bin/pip" install -e '.[docs]'
(cd compiler/api && uv run python compiler.py)
(cd compiler/errors && uv run python compiler.py)

cd compiler/docs
"$VENV/bin/python" compiler.py
uv run python compiler.py
cd ../..

"$VENV/bin/sphinx-build" -b html "docs/source" "docs/build/html" -j auto
uv run sphinx-build -b html "docs/source" "docs/build/html" -j auto

REPO_URL="https://5hojib:$GITHUB_TOKEN@github.com/5hojib/Electrogram-docs.git"
CLONE_DIR="Electrogram-docs"
Expand Down
5 changes: 2 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
autodoc_member_order = "bysource"

# Paths for templates and static files
templates_path = ["../resources/templates"]
templates_path = []

# HTML options
html_copy_source = False
Expand All @@ -45,7 +45,7 @@
html_permalinks = False
html_show_copyright = False
html_show_sphinx = False
html_static_path = ["../resources/static", "_static"]
html_static_path = ["_static"]

# Napoleon settings
napoleon_use_rtype = False
Expand Down Expand Up @@ -110,7 +110,6 @@

# LaTeX configuration
latex_engine = "xelatex"
latex_logo = "../resources/static/img/pyrogram.png"
latex_elements = {
"pointsize": "12pt",
"fontpkg": r"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ Another reason could be because you are blocking the event loop for too long.

You can consider the following:

- Use Electrogram asynchronously in its intended way.
- Use shorter non-asynchronous processing loops.
- Use ``asyncio.sleep()`` instead of ``time.sleep()``.
- Use a stable network connection.
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Meta
topics/more-on-updates
topics/client-settings
topics/text-formatting
topics/synchronous
topics/smart-plugins
topics/storage-engines
topics/serializing
Expand Down
29 changes: 2 additions & 27 deletions docs/source/topics/scheduling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Scheduling Tasks
Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is
useful, for example, to send recurring messages to specific chats or users.

This page will show examples on how to integrate Electrogram with ``apscheduler`` in both asynchronous and
non-asynchronous contexts. For more detailed information, you can visit and learn from the library documentation.
This page will show examples of how to integrate Electrogram with ``apscheduler``.
For more detailed information, you can visit and learn from the library documentation.

.. contents:: Contents
:backlinks: none
Expand All @@ -20,9 +20,6 @@ Using apscheduler
- Install with ``pip3 install apscheduler``
- Documentation: https://apscheduler.readthedocs.io

Asynchronously
^^^^^^^^^^^^^^

.. code-block:: python

from apscheduler.schedulers.asyncio import AsyncIOScheduler
Expand All @@ -41,25 +38,3 @@ Asynchronously

scheduler.start()
app.run()

Non-Asynchronously
^^^^^^^^^^^^^^^^^^

.. code-block:: python

from apscheduler.schedulers.background import BackgroundScheduler

from pyrogram import Client

app = Client("my_account")


def job():
app.send_message("me", "Hi!")


scheduler = BackgroundScheduler()
scheduler.add_job(job, "interval", seconds=3)

scheduler.start()
app.run()
73 changes: 0 additions & 73 deletions docs/source/topics/synchronous.rst

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dev = [
]

docs = [
"sphinx",
"sphinx<8.0.0",
"sphinx-immaterial",
"sphinx_copybutton",
"sphinx-autobuild",
Expand Down
5 changes: 3 additions & 2 deletions pyrogram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

__version__ = "v0.2.224"
__version__ = "v0.2.224.1"
__license__ = "MIT License"

from concurrent.futures.thread import ThreadPoolExecutor
Expand All @@ -23,7 +23,8 @@ class ContinuePropagationError(StopAsyncIteration):
# ruff: noqa: E402
from . import enums, errors, filters, handlers, raw, types
from .client import Client
from .sync import compose, idle
from .methods.utilities.compose import compose
from .methods.utilities.idle import idle

__all__ = [
"Client",
Expand Down
7 changes: 0 additions & 7 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,6 @@ def __init__(
}
self.loop = asyncio.get_event_loop()

def __enter__(self):
return self.start()

def __exit__(self, *args):
with contextlib.suppress(ConnectionError):
self.stop()

async def __aenter__(self):
return await self.start()

Expand Down
2 changes: 2 additions & 0 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,10 @@ async def __call__(self, _, message: Message | Story):

class topic(Filter, set):
"""Filter messages coming from one or more topics.

You can use `set bound methods <https://docs.python.org/3/library/stdtypes.html#set>`_ to manipulate the
topics container.

Parameters:
topics (``int`` | ``list``):
Pass one or more topic ids to filter messages in specific topics.
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/business/create_invoice_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def create_invoice_link(
payload=payload.encode() if isinstance(payload, str) else payload,
provider=provider_token,
provider_data=raw.types.DataJSON(
data=provider_data if provider_data else "{}",
data=provider_data or "{}",
),
start_param=start_parameter,
),
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/business/send_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def send_invoice(
payload=encoded_payload,
provider=provider,
provider_data=raw.types.DataJSON(
data=provider_data if provider_data else "{}",
data=provider_data or "{}",
),
photo=raw.types.InputWebDocument(
url=photo_url,
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/messages/get_available_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def get_available_effects(
await types.AvailableEffect._parse(
self,
effect,
documents.get(effect.effect_sticker_id, None),
documents.get(effect.effect_sticker_id),
)
for effect in r.effects
],
Expand Down
2 changes: 0 additions & 2 deletions pyrogram/methods/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .remove_handler import RemoveHandler
from .restart import Restart
from .run import Run
from .run_sync import RunSync
from .start import Start
from .stop import Stop
from .stop_transmission import StopTransmissionError
Expand All @@ -17,7 +16,6 @@ class Utilities(
RemoveHandler,
Restart,
Run,
RunSync,
Start,
Stop,
StopTransmissionError,
Expand Down
7 changes: 1 addition & 6 deletions pyrogram/methods/utilities/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import asyncio
import inspect
from typing import TYPE_CHECKING

from pyrogram.methods.utilities.idle import idle
Expand Down Expand Up @@ -59,11 +58,7 @@ async def main():

if coroutine is not None:
run(coroutine)
elif inspect.iscoroutinefunction(self.start):
else:
run(self.start())
run(idle())
run(self.stop())
else:
self.start()
run(idle())
self.stop()
36 changes: 0 additions & 36 deletions pyrogram/methods/utilities/run_sync.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyrogram/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, client: pyrogram.Client | None) -> None:
self.markdown = Markdown(client)

async def parse(self, text: str, mode: enums.ParseMode | None = None):
text = str(text if text else "").strip()
text = str(text or "").strip()

if mode is None:
mode = self.client.parse_mode if self.client else enums.ParseMode.DEFAULT
Expand Down
Loading