From caecbef2f6f241681dff9990a9765dbd92783b64 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 24 Aug 2018 16:03:52 +0200
Subject: [PATCH 1/9] Add phone_number type of entity to docs
---
pyrogram/client/types/messages_and_media/message_entity.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pyrogram/client/types/messages_and_media/message_entity.py b/pyrogram/client/types/messages_and_media/message_entity.py
index db2eee3e..f8f41734 100644
--- a/pyrogram/client/types/messages_and_media/message_entity.py
+++ b/pyrogram/client/types/messages_and_media/message_entity.py
@@ -26,9 +26,9 @@ class MessageEntity(Object):
Args:
type (``str``):
Type of the entity.
- Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "bold" (bold text),
- italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text
- URLs), "text_mention" (for users without usernames).
+ Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "phone_number", "bold"
+ (bold text), italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link"
+ (for clickable text URLs), "text_mention" (for users without usernames).
offset (``int``):
Offset in UTF-16 code units to the start of the entity.
From 0b6b59805934a1897324b306cab066539f539941 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 24 Aug 2018 17:39:55 +0200
Subject: [PATCH 2/9] Log unknown constructors
---
pyrogram/api/core/object.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/pyrogram/api/core/object.py b/pyrogram/api/core/object.py
index a1e20726..3cf12329 100644
--- a/pyrogram/api/core/object.py
+++ b/pyrogram/api/core/object.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+import logging
from collections import OrderedDict
from datetime import datetime
from io import BytesIO
@@ -23,13 +24,23 @@ from json import JSONEncoder, dumps
from ..all import objects
+log = logging.getLogger(__name__)
+
class Object:
all = {}
@staticmethod
def read(b: BytesIO, *args):
- return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args)
+ constructor_id = int.from_bytes(b.read(4), "little")
+
+ try:
+ return Object.all[constructor_id].read(b, *args)
+ except KeyError:
+ log.error("Unknown constructor found: {}. Full data: {}".format(
+ hex(constructor_id),
+ b.getvalue().hex())
+ )
def write(self, *args) -> bytes:
pass
From 77a1d5871485ac1f9f479612d6b1a13d2842a653 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 24 Aug 2018 18:13:07 +0200
Subject: [PATCH 3/9] Normalize "0.8.0dev1" to "0.8.0.dev1"
---
pyrogram/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 7ef07777..1de05f2c 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès
Date: Sat, 25 Aug 2018 13:53:48 +0200
Subject: [PATCH 4/9] Add clean command to setup.py
---
setup.py | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/setup.py b/setup.py
index 00f9be63..a5ad052d 100644
--- a/setup.py
+++ b/setup.py
@@ -17,9 +17,10 @@
# along with Pyrogram. If not, see .
import re
+import shutil
from sys import argv
-from setuptools import setup, find_packages
+from setuptools import setup, find_packages, Command
from compiler.api import compiler as api_compiler
from compiler.docs import compiler as docs_compiler
@@ -44,6 +45,24 @@ with open("README.rst", encoding="utf-8") as f:
readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
+
+class Clean(Command):
+ PATHS = "./build ./dist ./Pyrogram.egg-info".split()
+
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ for path in self.PATHS:
+ print("removing {}".format(path))
+ shutil.rmtree(path, ignore_errors=True)
+
+
setup(
name="Pyrogram",
version=version,
@@ -85,5 +104,8 @@ setup(
packages=find_packages(exclude=["compiler*"]),
zip_safe=False,
install_requires=read("requirements.txt"),
- extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]}
+ extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
+ cmdclass={
+ "clean": Clean
+ }
)
From 1e56f70b9309ab974de1ac396dc67ef9e090f456 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 25 Aug 2018 13:58:55 +0200
Subject: [PATCH 5/9] Also clean generated filed
---
setup.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index a5ad052d..ee716857 100644
--- a/setup.py
+++ b/setup.py
@@ -47,7 +47,15 @@ with open("README.rst", encoding="utf-8") as f:
class Clean(Command):
- PATHS = "./build ./dist ./Pyrogram.egg-info".split()
+ PATHS = [
+ "./build",
+ "./dist",
+ "./Pyrogram.egg-info",
+ "pyrogram/api/errors/exceptions",
+ "pyrogram/api/functions",
+ "pyrogram/api/types",
+ "pyrogram/api/all.py"
+ ]
user_options = []
From c9a946bc02ef8f1c44774fd3c05790d145b4e37c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 25 Aug 2018 14:00:04 +0200
Subject: [PATCH 6/9] Turn version and readme into function
---
setup.py | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/setup.py b/setup.py
index ee716857..f9153dfe 100644
--- a/setup.py
+++ b/setup.py
@@ -37,13 +37,17 @@ if len(argv) > 1 and argv[1] != "sdist":
docs_compiler.start()
error_compiler.start()
-with open("pyrogram/__init__.py", encoding="utf-8") as f:
- version = re.findall(r"__version__ = \"(.+)\"", f.read())[0]
-# PyPI doesn't like raw html
-with open("README.rst", encoding="utf-8") as f:
- readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
- readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
+def get_version():
+ with open("pyrogram/__init__.py", encoding="utf-8") as f:
+ return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
+
+
+def get_readme():
+ # PyPI doesn't like raw html
+ with open("README.rst", encoding="utf-8") as f:
+ readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
+ return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
class Clean(Command):
@@ -73,9 +77,9 @@ class Clean(Command):
setup(
name="Pyrogram",
- version=version,
+ version=get_version(),
description="Telegram MTProto API Client Library for Python",
- long_description=readme,
+ long_description=get_readme(),
url="https://github.com/pyrogram",
download_url="https://github.com/pyrogram/pyrogram/releases/latest",
author="Dan Tès",
From d6a0fcf4adaacf9315a41282904c0f89cc9aed1e Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 25 Aug 2018 14:22:19 +0200
Subject: [PATCH 7/9] Also clean docs generated files
---
setup.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/setup.py b/setup.py
index f9153dfe..929222db 100644
--- a/setup.py
+++ b/setup.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+import os
import re
import shutil
from sys import argv
@@ -58,7 +59,9 @@ class Clean(Command):
"pyrogram/api/errors/exceptions",
"pyrogram/api/functions",
"pyrogram/api/types",
- "pyrogram/api/all.py"
+ "pyrogram/api/all.py",
+ "docs/source/functions",
+ "docs/source/types"
]
user_options = []
@@ -71,9 +74,12 @@ class Clean(Command):
def run(self):
for path in self.PATHS:
- print("removing {}".format(path))
- shutil.rmtree(path, ignore_errors=True)
-
+ try:
+ shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
+ except OSError:
+ print("skipping {}".format(path))
+ else:
+ print("removing {}".format(path))
setup(
name="Pyrogram",
From 47f8a4eb34b17cd3f4bba493e6ec83e505200903 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 25 Aug 2018 15:14:51 +0200
Subject: [PATCH 8/9] Add generate command to setup.py
---
setup.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 81 insertions(+), 14 deletions(-)
diff --git a/setup.py b/setup.py
index 929222db..6cc10340 100644
--- a/setup.py
+++ b/setup.py
@@ -33,38 +33,56 @@ def read(file: str) -> list:
return [i.strip() for i in r]
-if len(argv) > 1 and argv[1] != "sdist":
- api_compiler.start()
- docs_compiler.start()
- error_compiler.start()
-
-
def get_version():
with open("pyrogram/__init__.py", encoding="utf-8") as f:
return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
def get_readme():
- # PyPI doesn't like raw html
+ # PyPI doesn"t like raw html
with open("README.rst", encoding="utf-8") as f:
readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
class Clean(Command):
- PATHS = [
+ DIST = [
"./build",
"./dist",
- "./Pyrogram.egg-info",
+ "./Pyrogram.egg-info"
+ ]
+
+ API = [
"pyrogram/api/errors/exceptions",
"pyrogram/api/functions",
"pyrogram/api/types",
"pyrogram/api/all.py",
- "docs/source/functions",
- "docs/source/types"
]
- user_options = []
+ DOCS = [
+ "docs/source/functions",
+ "docs/source/types",
+ "docs/build"
+ ]
+
+ ALL = DIST + API + DOCS
+
+ description = "Clean generated files"
+
+ user_options = [
+ ("dist", None, "Clean distribution files"),
+ ("api", None, "Clean generated API files"),
+ ("docs", None, "Clean generated docs files"),
+ ("all", None, "Clean all generated files"),
+ ]
+
+ def __init__(self, dist, **kw):
+ super().__init__(dist, **kw)
+
+ self.dist = None
+ self.api = None
+ self.docs = None
+ self.all = None
def initialize_options(self):
pass
@@ -73,7 +91,21 @@ class Clean(Command):
pass
def run(self):
- for path in self.PATHS:
+ paths = set()
+
+ if self.dist:
+ paths.update(Clean.DIST)
+
+ if self.api:
+ paths.update(Clean.API)
+
+ if self.docs:
+ paths.update(Clean.DOCS)
+
+ if self.all:
+ paths.update(Clean.ALL)
+
+ for path in sorted(list(paths)):
try:
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
except OSError:
@@ -81,6 +113,40 @@ class Clean(Command):
else:
print("removing {}".format(path))
+
+class Generate(Command):
+ description = "Generate Pyrogram files"
+
+ user_options = [
+ ("api", None, "Generate API files"),
+ ("docs", None, "Generate docs files"),
+ ]
+
+ def __init__(self, dist, **kw):
+ super().__init__(dist, **kw)
+
+ self.api = None
+ self.docs = None
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ if self.api:
+ error_compiler.start()
+ api_compiler.start()
+
+ if self.docs:
+ docs_compiler.start()
+
+
+if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]:
+ error_compiler.start()
+ api_compiler.start()
+
setup(
name="Pyrogram",
version=get_version(),
@@ -124,6 +190,7 @@ setup(
install_requires=read("requirements.txt"),
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
cmdclass={
- "clean": Clean
+ "clean": Clean,
+ "generate": Generate,
}
)
From ccc3cb0c876ae43c3fbcffd82bb96d9c38c78c73 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 26 Aug 2018 19:18:14 +0200
Subject: [PATCH 9/9] Rename generate to build Replaces the default build
behaviour
---
setup.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/setup.py b/setup.py
index 6cc10340..5df52747 100644
--- a/setup.py
+++ b/setup.py
@@ -114,12 +114,12 @@ class Clean(Command):
print("removing {}".format(path))
-class Generate(Command):
- description = "Generate Pyrogram files"
+class Build(Command):
+ description = "Build Pyrogram files"
user_options = [
- ("api", None, "Generate API files"),
- ("docs", None, "Generate docs files"),
+ ("api", None, "Build API files"),
+ ("docs", None, "Build docs files"),
]
def __init__(self, dist, **kw):
@@ -191,6 +191,6 @@ setup(
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
cmdclass={
"clean": Clean,
- "generate": Generate,
+ "build": Build,
}
)