Skip to content

Commit 707d3d6

Browse files
authored
feat: add some new types.
1 parent e3b0b02 commit 707d3d6

31 files changed

+282
-101
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ name: Build-docs
22

33
on:
44
push:
5-
tags:
6-
- "*"
75
branches:
8-
- err
9-
workflow_dispatch:
10-
{}
6+
- test
117

128
jobs:
139
build:
@@ -19,4 +15,4 @@ jobs:
1915
- name: Build
2016
run: bash build-docs.sh
2117
env:
22-
DOCS_KEY: ${{ secrets.GX_TOKEN }}
18+
GITHUB_TOKEN: ${{ secrets.GX_TOKEN }}

.github/workflows/format_and_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Format and Test Code with Rye
33
on:
44
push:
55
branches:
6-
- err
6+
- test
77

88
jobs:
99
lint-format-and-test:
@@ -39,7 +39,7 @@ jobs:
3939
if git diff-index --quiet HEAD --; then
4040
echo "No changes to commit."
4141
else
42-
git commit -m "InkyPinkyPonky [no ci]"
42+
git commit -m "InkyPinkyPonky [no ci]" --signoff
4343
git push origin ${{ github.ref }}
4444
fi
4545
env:

.github/workflows/tag_and_publish.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,40 @@ jobs:
1313
- name: Checkout Repository
1414
uses: actions/checkout@v4
1515

16-
- name: Set Version from File
16+
- name: Extract Version from File
1717
id: version
1818
run: |
1919
VERSION=$(grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2)
2020
echo "VERSION=$VERSION" >> $GITHUB_ENV
2121
22-
- name: Check Existing Tag
23-
id: check_tag
22+
- name: Check for Existing Release
23+
id: check_release
2424
run: |
25-
TAG_EXISTS=$(git tag -l "${{ env.VERSION }}")
26-
if [ -n "$TAG_EXISTS" ]; then
27-
echo "Tag ${{ env.VERSION }} already exists."
28-
echo "TAG_EXISTS=true" >> $GITHUB_ENV # Set environment variable
25+
TAG_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/${{ env.VERSION }})
26+
if [ "$TAG_EXISTS" -eq 200 ]; then
27+
echo "Release with tag ${{ env.VERSION }} already exists."
28+
echo "RELEASE_EXISTS=true" >> $GITHUB_ENV
2929
else
30-
echo "TAG_EXISTS=false" >> $GITHUB_ENV
30+
echo "RELEASE_EXISTS=false" >> $GITHUB_ENV
3131
fi
3232
33-
- name: Create Tag
34-
if: env.TAG_EXISTS != 'true'
35-
run: |
36-
git tag ${{ env.VERSION }}
37-
git push origin ${{ env.VERSION }}
33+
- name: Create New Release
34+
if: env.RELEASE_EXISTS == 'false'
35+
uses: actions/create-release@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GX_TOKEN }}
38+
with:
39+
tag_name: ${{ env.VERSION }}
40+
release_name: Release ${{ env.VERSION }}
41+
body: Release ${{ env.VERSION }}
3842

39-
- name: Upload Python Package
40-
if: env.TAG_EXISTS != 'true'
43+
- name: Build and Publish Python Package
44+
if: env.RELEASE_EXISTS == 'false'
4145
run: |
4246
python -m pip install --upgrade pip
4347
pip install -e '.[dev]'
4448
hatch build
4549
hatch publish
4650
env:
4751
HATCH_INDEX_USER: __token__
48-
HATCH_INDEX_AUTH: ${{ secrets.PYPI_API_TOKEN }}
52+
HATCH_INDEX_AUTH: ${{ secrets.PYPI_API_TOKEN }}

build-docs.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash
22

3-
export DOCS_KEY
3+
export GITHUB_TOKEN
44
VENV="$(pwd)/venv"
55
export VENV
66

7-
87
make clean
98
make clean-docs
109
make venv
@@ -17,21 +16,20 @@ cd ../..
1716

1817
"$VENV/bin/sphinx-build" -b html "docs/source" "docs/build/html" -j auto
1918

20-
git clone https://5hojib:"$DOCS_KEY"@github.com/5hojib/Electrogram-docs.git
19+
git clone https://5hojib:"$GITHUB_TOKEN"@github.com/5hojib/Electrogram-docs.git
2120
cd Electrogram-docs
2221

23-
mkdir -p main
24-
cd main
25-
2622
rm -rf _includes api genindex.html intro py-modindex.html sitemap.xml \
2723
support.html topics _static faq index.html objects.inv \
2824
searchindex.js start telegram
2925

30-
cp -r ../../docs/build/html/* .
31-
26+
cp -r ../docs/build/html/* .
3227
git config --local user.name "5hojib"
3328
git config --local user.email "yesiamshojib@gmail.com"
34-
3529
git add --all
36-
git commit -a -m "docs: main: Update docs $(date '+%Y-%m-%d | %H:%m:%S %p %Z')" --signoff
37-
git push -u origin --all
30+
git commit -m "Update docs" --signoff
31+
git checkout --orphan x
32+
git commit -m "Update docs" --signoff
33+
git branch -D main
34+
git branch -m main
35+
git push --force origin main

compiler/docs/compiler.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
import os
55
import re
66
import shutil
7+
from pathlib import Path
78

89
HOME = "compiler/docs"
910
DESTINATION = "docs/source/telegram"
1011
PYROGRAM_API_DEST = "docs/source/api"
11-
1212
FUNCTIONS_PATH = "pyrogram/raw/functions"
1313
TYPES_PATH = "pyrogram/raw/types"
1414
BASE_PATH = "pyrogram/raw/base"
15-
1615
FUNCTIONS_BASE = "functions"
1716
TYPES_BASE = "types"
1817
BASE_BASE = "base"
1918

2019

21-
def snek(s: str):
20+
def snake(s: str):
2221
s = re.sub(r"(.)([A-Z][a-z]+)", r"\1_\2", s)
2322
return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", s).lower()
2423

@@ -34,7 +33,7 @@ def build(path, level=0):
3433
if not i.startswith("__"):
3534
build("/".join([path, i]), level=level + 1)
3635
except NotADirectoryError:
37-
with open(path + "/" + i, encoding="utf-8") as f:
36+
with Path(path, i).open(encoding="utf-8") as f:
3837
p = ast.parse(f.read())
3938

4039
for node in ast.walk(p):
@@ -45,10 +44,7 @@ def build(path, level=0):
4544
continue
4645

4746
full_path = (
48-
os.path.basename(path)
49-
+ "/"
50-
+ snek(name).replace("_", "-")
51-
+ ".rst"
47+
Path(path).name + "/" + snake(name).replace("_", "-") + ".rst"
5248
)
5349

5450
if level:
@@ -60,11 +56,11 @@ def build(path, level=0):
6056

6157
full_name = f"{(namespace + '.') if namespace else ''}{name}"
6258

63-
os.makedirs(
64-
os.path.dirname(DESTINATION + "/" + full_path), exist_ok=True
59+
Path(DESTINATION, full_path).parent.mkdir(
60+
parents=True, exist_ok=True
6561
)
6662

67-
with open(DESTINATION + "/" + full_path, "w", encoding="utf-8") as f:
63+
with Path(DESTINATION, full_path).open("w", encoding="utf-8") as f:
6864
f.write(
6965
page_template.format(
7066
title=full_name,
@@ -84,10 +80,7 @@ def build(path, level=0):
8480

8581
for k, v in sorted(all_entities.items()):
8682
v = sorted(v)
87-
entities = []
88-
89-
for i in v:
90-
entities.append(f'{i} <{snek(i).replace("_", "-")}>')
83+
entities = [f'{i} <{snake(i).replace("_", "-")}>' for i in v]
9184

9285
if k != base:
9386
inner_path = base + "/" + k + "/index" + ".rst"
@@ -100,7 +93,7 @@ def build(path, level=0):
10093
inner_path = base + "/index" + ".rst"
10194
module = f"pyrogram.raw.{base}"
10295

103-
with open(DESTINATION + "/" + inner_path, "w", encoding="utf-8") as f:
96+
with Path(DESTINATION, inner_path).open("w", encoding="utf-8") as f:
10497
if k == base:
10598
f.write(":tocdepth: 1\n\n")
10699
k = "Raw " + k
@@ -414,20 +407,20 @@ def get_title_list(s: str) -> list:
414407
root = PYROGRAM_API_DEST + "/methods"
415408

416409
shutil.rmtree(root, ignore_errors=True)
417-
os.mkdir(root)
410+
Path(root).mkdir()
418411

419-
with open(HOME + "/template/methods.rst") as f:
412+
with Path(HOME, "template/methods.rst").open() as f:
420413
template = f.read()
421414

422-
with open(root + "/index.rst", "w") as f:
415+
with Path(root, "index.rst").open("w") as f:
423416
fmt_keys = {}
424417

425418
for k, v in categories.items():
426419
name, *methods = get_title_list(v)
427420
fmt_keys.update({k: "\n ".join(f"{m} <{m}>" for m in methods)})
428421

429422
for method in methods:
430-
with open(root + f"/{method}.rst", "w") as f2:
423+
with Path(root, f"{method}.rst").open("w") as f2:
431424
title = f"{method}()"
432425

433426
f2.write(title + "\n" + "=" * len(title) + "\n\n")
@@ -436,7 +429,7 @@ def get_title_list(s: str) -> list:
436429
functions = ["idle", "compose"]
437430

438431
for func in functions:
439-
with open(root + f"/{func}.rst", "w") as f2:
432+
with Path(root, f"{func}.rst").open("w") as f2:
440433
title = f"{func}()"
441434

442435
f2.write(title + "\n" + "=" * len(title) + "\n\n")
@@ -503,6 +496,8 @@ def get_title_list(s: str) -> list:
503496
Venue
504497
Sticker
505498
StickerSet
499+
ContactRegistered
500+
ScreenshotTaken
506501
Game
507502
GiftedPremium
508503
Giveaway
@@ -691,12 +686,12 @@ def get_title_list(s: str) -> list:
691686
root = PYROGRAM_API_DEST + "/types"
692687

693688
shutil.rmtree(root, ignore_errors=True)
694-
os.mkdir(root)
689+
Path(root).mkdir()
695690

696-
with open(HOME + "/template/types.rst") as f:
691+
with Path(HOME, "template/types.rst").open() as f:
697692
template = f.read()
698693

699-
with open(root + "/index.rst", "w") as f:
694+
with Path(root, "index.rst").open("w") as f:
700695
fmt_keys = {}
701696

702697
for k, v in categories.items():
@@ -705,7 +700,7 @@ def get_title_list(s: str) -> list:
705700
fmt_keys.update({k: "\n ".join(types)})
706701

707702
for type in types:
708-
with open(root + f"/{type}.rst", "w") as f2:
703+
with Path(root, f"{type}.rst").open("w") as f2:
709704
title = f"{type}"
710705

711706
f2.write(title + "\n" + "=" * len(title) + "\n\n")
@@ -836,17 +831,21 @@ def get_title_list(s: str) -> list:
836831
ChatJoinRequest.approve
837832
ChatJoinRequest.decline
838833
""",
834+
"active_session": """
835+
ActiveSession
836+
ActiveSession.reset
837+
""",
839838
}
840839

841840
root = PYROGRAM_API_DEST + "/bound-methods"
842841

843842
shutil.rmtree(root, ignore_errors=True)
844-
os.mkdir(root)
843+
Path(root).mkdir()
845844

846-
with open(HOME + "/template/bound-methods.rst") as f:
845+
with Path(HOME, "template/bound-methods.rst").open() as f:
847846
template = f.read()
848847

849-
with open(root + "/index.rst", "w") as f:
848+
with Path(root, "index.rst").open("w") as f:
850849
fmt_keys = {}
851850

852851
for k, v in categories.items():
@@ -869,9 +868,8 @@ def get_title_list(s: str) -> list:
869868
}
870869
)
871870

872-
# noinspection PyShadowingBuiltins
873871
for bm in bound_methods:
874-
with open(root + f"/{bm}.rst", "w") as f2:
872+
with Path(root, f"{bm}.rst").open("w") as f2:
875873
title = f"{bm}()"
876874

877875
f2.write(title + "\n" + "=" * len(title) + "\n\n")
@@ -881,15 +879,14 @@ def get_title_list(s: str) -> list:
881879

882880

883881
def start():
884-
global page_template
885-
global toctree
882+
global page_template, toctree # noqa: PLW0603
886883

887884
shutil.rmtree(DESTINATION, ignore_errors=True)
888885

889-
with open(HOME + "/template/page.txt", encoding="utf-8") as f:
886+
with Path(HOME, "template/page.txt").open(encoding="utf-8") as f:
890887
page_template = f.read()
891888

892-
with open(HOME + "/template/toctree.txt", encoding="utf-8") as f:
889+
with Path(HOME, "template/toctree.txt").open(encoding="utf-8") as f:
893890
toctree = f.read()
894891

895892
generate(TYPES_PATH, TYPES_BASE)

0 commit comments

Comments
 (0)