Skip to content

Commit 35f30e2

Browse files
authored
Merge pull request #163 from david-lev/dev
Dev
2 parents 91f2d00 + afc144e commit 35f30e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1266
-913
lines changed

.github/scripts/send_release_to_telegram.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import os
21
import asyncio
2+
import logging
3+
import os
34

45
from pyrogram import Client, types
56

@@ -65,7 +66,7 @@ async def send_to_telegram():
6566
release_body = os.getenv("RELEASE_BODY")
6667

6768
message = format_release_message(release_tag, release_name, release_body)
68-
print(message)
69+
logging.info("Formatted message:\n%s", message)
6970

7071
bot = Client(name="pywa_bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token)
7172

.github/workflows/lint.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
# This workflow copied from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#the-whole-ci-cd-workflow
2-
31
name: Publish Python Package to PyPI
42

53
on:
6-
release:
7-
types: [published]
4+
workflow_run:
5+
workflows: [ "tests" ]
6+
types: [ completed ]
87

98
jobs:
109
build:
1110
name: Build distribution 📦
11+
if: >
12+
github.event.workflow_run.conclusion == 'success' &&
13+
github.event.workflow_run.event == 'release'
1214
runs-on: ubuntu-latest
1315
permissions:
1416
contents: read
1517
actions: write
1618

1719
steps:
18-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v6
1921
with:
2022
persist-credentials: false
2123
- name: Set up Python
22-
uses: actions/setup-python@v5
24+
uses: actions/setup-python@v6
2325
with:
2426
python-version: "3.x"
2527
- name: Install pypa/build
@@ -31,15 +33,16 @@ jobs:
3133
- name: Build a binary wheel and a source tarball
3234
run: python3 -m build
3335
- name: Store the distribution packages
34-
uses: actions/upload-artifact@v4
36+
uses: actions/upload-artifact@v5
3537
with:
3638
name: python-package-distributions
3739
path: dist/
3840

41+
3942
publish-to-pypi:
4043
name: >-
41-
Publish Python Package to PyPI
42-
44+
Publish Python 🐍 distribution 📦 to PyPI
45+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
4346
needs:
4447
- build
4548
runs-on: ubuntu-latest
@@ -51,7 +54,7 @@ jobs:
5154

5255
steps:
5356
- name: Download all the dists
54-
uses: actions/download-artifact@v4
57+
uses: actions/download-artifact@v6
5558
with:
5659
name: python-package-distributions
5760
path: dist/

.github/workflows/tests.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
name: Tests with pytest
22

3-
on: [ push, pull_request ]
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [ published ]
48

59
permissions:
610
contents: read
711

812
jobs:
9-
build:
13+
tests:
14+
name: Tests with pytest
1015
runs-on: ${{ matrix.os }}
1116
strategy:
17+
fail-fast: false
1218
matrix:
1319
os: [ ubuntu-latest, macos-latest, windows-latest ]
14-
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
20+
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
1521

1622
steps:
1723
- uses: actions/checkout@v4
1824
- name: Set up Python ${{ matrix.python-version }}
1925
uses: actions/setup-python@v5
2026
with:
2127
python-version: ${{ matrix.python-version }}
28+
cache: pip
2229

2330
- name: Install dependencies
2431
run: |
@@ -27,9 +34,3 @@ jobs:
2734
2835
- name: Run tests
2936
run: pytest
30-
# run: pytest --cov --cov-report=xml
31-
#
32-
# - name: Upload results to Codecov
33-
# uses: codecov/codecov-action@v5
34-
# with:
35-
# token: ${{ secrets.CODECOV_TOKEN }}

.pre-commit-config.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
4+
ci:
5+
autoupdate_branch: dev
6+
autoupdate_schedule: quarterly
7+
38
repos:
49
- repo: https://github.com/pre-commit/pre-commit-hooks
510
rev: v6.0.0
@@ -8,9 +13,17 @@ repos:
813
- id: end-of-file-fixer
914
- id: check-yaml
1015
- id: check-added-large-files
16+
- id: check-executables-have-shebangs
17+
- id: check-illegal-windows-names
18+
- id: check-json
19+
# - id: detect-private-key
20+
# - id: pretty-format-json
21+
# args: [ --autofix ]
22+
1123

1224
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.14.3
25+
rev: v0.14.10
1426
hooks:
15-
- id: ruff
27+
- id: ruff-check
28+
args: [ --fix ]
1629
- id: ruff-format

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 David Lev
3+
Copyright (c) 2026 David Lev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sphinx-book-theme==1.1.4
22
sphinx-copybutton==0.5.2
3-
sphinxext-opengraph==0.12.0
3+
sphinxext-opengraph==0.13.0
44
sphinx-togglebutton==0.3.2
55
myst-parser==4.0.1
66
sphinxcontrib-googleanalytics==0.5

docs/source/content/types/others.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Others
5050
.. autoclass:: ConversationalAutomation()
5151

5252
.. autoclass:: QRCode()
53+
:members: fetch_image, update, delete
54+
55+
.. autoclass:: QRCodeImageType()
5356

5457
.. autoclass:: Command()
5558

pyproject.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,27 @@ cryptography = ["cryptography"]
5050
"Funding" = "https://github.com/sponsors/david-lev"
5151
"Changelog" = "https://github.com/david-lev/pywa/blob/master/CHANGELOG.md"
5252

53+
54+
[tool.ruff]
55+
extend-exclude = [
56+
"pywa*/__init__.py",
57+
]
58+
5359
[tool.ruff.lint]
54-
ignore = ["E731", "F401", "E402", "F405"]
60+
select = [
61+
"E4",
62+
"E7",
63+
"E9",
64+
"F",
65+
"T",
66+
"B",
67+
"C4",
68+
"I",
69+
]
70+
ignore = [
71+
"E402",
72+
"F405",
73+
]
5574

5675

5776
[tool.coverage.run]

pywa/_helpers.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,42 @@
2727
import threading
2828
from concurrent import futures
2929
from typing import (
30+
TYPE_CHECKING,
3031
Any,
32+
AsyncIterable,
33+
AsyncIterator,
3134
BinaryIO,
3235
Iterable,
33-
TYPE_CHECKING,
34-
NamedTuple,
35-
Literal,
3636
Iterator,
37-
AsyncIterable,
38-
AsyncIterator,
37+
Literal,
38+
NamedTuple,
3939
)
4040

4141
import httpx
4242

43+
from pywa.types.others import InteractiveType
44+
4345
from .types import (
44-
FlowMetricName,
45-
FlowMetricGranularity,
46-
FlowJSON,
46+
Button,
47+
ButtonUrl,
4748
CallbackData,
49+
CallPermissionRequestButton,
50+
FlowButton,
51+
FlowJSON,
52+
FlowMetricGranularity,
53+
FlowMetricName,
54+
SectionList,
4855
URLButton,
4956
VoiceCallButton,
50-
SectionList,
51-
FlowButton,
52-
Button,
53-
CallPermissionRequestButton,
54-
ButtonUrl,
5557
)
56-
from pywa.types.others import InteractiveType
5758
from .types.media import Media
5859
from .types.templates import (
60+
BaseParams,
61+
Carousel,
62+
HeaderFormatType,
5963
TemplateBaseComponent,
6064
_BaseMediaHeaderComponent,
61-
HeaderFormatType,
62-
Carousel,
6365
_BaseMediaParams,
64-
BaseParams,
6566
)
6667

6768
if TYPE_CHECKING:
@@ -382,12 +383,13 @@ def get_media_from_file_like_obj(
382383
try:
383384
length = os.fstat(file_obj.fileno()).st_size
384385
except (AttributeError, OSError):
385-
pos = file_obj.tell()
386-
file_obj.seek(0, io.SEEK_END)
387-
length = file_obj.tell()
388-
file_obj.seek(pos)
389-
except (AttributeError, OSError):
390-
length = None
386+
try:
387+
pos = file_obj.tell()
388+
file_obj.seek(0, io.SEEK_END)
389+
length = file_obj.tell()
390+
file_obj.seek(pos)
391+
except (AttributeError, OSError):
392+
length = None
391393
filename = getattr(file_obj, "name", None)
392394
return MediaInfo(
393395
content=file_obj,
@@ -458,6 +460,7 @@ def internal_upload_media(
458460
media_type: str | None,
459461
mime_type: str | None,
460462
filename: str | None,
463+
ttl_minutes: int | None = None,
461464
download_chunk_size: int | None,
462465
wa: WhatsApp,
463466
phone_id: str,
@@ -526,9 +529,11 @@ def internal_upload_media(
526529
or media_info.mime_type
527530
or _media_types_default_mime_types.get(media_type, "text/plain"),
528531
filename=final_filename,
532+
ttl_minutes=ttl_minutes,
529533
)["id"],
530534
uploaded_to=phone_id,
531535
filename=final_filename,
536+
ttl_minutes=ttl_minutes,
532537
)
533538

534539
finally:

0 commit comments

Comments
 (0)