Skip to content

Commit 47f8a4e

Browse files
committed
Add generate command to setup.py
1 parent d6a0fcf commit 47f8a4e

1 file changed

Lines changed: 80 additions & 13 deletions

File tree

setup.py

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,56 @@ def read(file: str) -> list:
3333
return [i.strip() for i in r]
3434

3535

36-
if len(argv) > 1 and argv[1] != "sdist":
37-
api_compiler.start()
38-
docs_compiler.start()
39-
error_compiler.start()
40-
41-
4236
def get_version():
4337
with open("pyrogram/__init__.py", encoding="utf-8") as f:
4438
return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
4539

4640

4741
def get_readme():
48-
# PyPI doesn't like raw html
42+
# PyPI doesn"t like raw html
4943
with open("README.rst", encoding="utf-8") as f:
5044
readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
5145
return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
5246

5347

5448
class Clean(Command):
55-
PATHS = [
49+
DIST = [
5650
"./build",
5751
"./dist",
58-
"./Pyrogram.egg-info",
52+
"./Pyrogram.egg-info"
53+
]
54+
55+
API = [
5956
"pyrogram/api/errors/exceptions",
6057
"pyrogram/api/functions",
6158
"pyrogram/api/types",
6259
"pyrogram/api/all.py",
60+
]
61+
62+
DOCS = [
6363
"docs/source/functions",
64-
"docs/source/types"
64+
"docs/source/types",
65+
"docs/build"
6566
]
6667

67-
user_options = []
68+
ALL = DIST + API + DOCS
69+
70+
description = "Clean generated files"
71+
72+
user_options = [
73+
("dist", None, "Clean distribution files"),
74+
("api", None, "Clean generated API files"),
75+
("docs", None, "Clean generated docs files"),
76+
("all", None, "Clean all generated files"),
77+
]
78+
79+
def __init__(self, dist, **kw):
80+
super().__init__(dist, **kw)
81+
82+
self.dist = None
83+
self.api = None
84+
self.docs = None
85+
self.all = None
6886

6987
def initialize_options(self):
7088
pass
@@ -73,14 +91,62 @@ def finalize_options(self):
7391
pass
7492

7593
def run(self):
76-
for path in self.PATHS:
94+
paths = set()
95+
96+
if self.dist:
97+
paths.update(Clean.DIST)
98+
99+
if self.api:
100+
paths.update(Clean.API)
101+
102+
if self.docs:
103+
paths.update(Clean.DOCS)
104+
105+
if self.all:
106+
paths.update(Clean.ALL)
107+
108+
for path in sorted(list(paths)):
77109
try:
78110
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
79111
except OSError:
80112
print("skipping {}".format(path))
81113
else:
82114
print("removing {}".format(path))
83115

116+
117+
class Generate(Command):
118+
description = "Generate Pyrogram files"
119+
120+
user_options = [
121+
("api", None, "Generate API files"),
122+
("docs", None, "Generate docs files"),
123+
]
124+
125+
def __init__(self, dist, **kw):
126+
super().__init__(dist, **kw)
127+
128+
self.api = None
129+
self.docs = None
130+
131+
def initialize_options(self):
132+
pass
133+
134+
def finalize_options(self):
135+
pass
136+
137+
def run(self):
138+
if self.api:
139+
error_compiler.start()
140+
api_compiler.start()
141+
142+
if self.docs:
143+
docs_compiler.start()
144+
145+
146+
if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]:
147+
error_compiler.start()
148+
api_compiler.start()
149+
84150
setup(
85151
name="Pyrogram",
86152
version=get_version(),
@@ -124,6 +190,7 @@ def run(self):
124190
install_requires=read("requirements.txt"),
125191
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
126192
cmdclass={
127-
"clean": Clean
193+
"clean": Clean,
194+
"generate": Generate,
128195
}
129196
)

0 commit comments

Comments
 (0)