mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add generate command to setup.py
This commit is contained in:
parent
d6a0fcf4ad
commit
47f8a4eb34
95
setup.py
95
setup.py
@ -33,38 +33,56 @@ def read(file: str) -> list:
|
|||||||
return [i.strip() for i in r]
|
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():
|
def get_version():
|
||||||
with open("pyrogram/__init__.py", encoding="utf-8") as f:
|
with open("pyrogram/__init__.py", encoding="utf-8") as f:
|
||||||
return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
|
return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
|
||||||
|
|
||||||
|
|
||||||
def get_readme():
|
def get_readme():
|
||||||
# PyPI doesn't like raw html
|
# PyPI doesn"t like raw html
|
||||||
with open("README.rst", encoding="utf-8") as f:
|
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"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
|
||||||
return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
|
return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
|
||||||
|
|
||||||
|
|
||||||
class Clean(Command):
|
class Clean(Command):
|
||||||
PATHS = [
|
DIST = [
|
||||||
"./build",
|
"./build",
|
||||||
"./dist",
|
"./dist",
|
||||||
"./Pyrogram.egg-info",
|
"./Pyrogram.egg-info"
|
||||||
|
]
|
||||||
|
|
||||||
|
API = [
|
||||||
"pyrogram/api/errors/exceptions",
|
"pyrogram/api/errors/exceptions",
|
||||||
"pyrogram/api/functions",
|
"pyrogram/api/functions",
|
||||||
"pyrogram/api/types",
|
"pyrogram/api/types",
|
||||||
"pyrogram/api/all.py",
|
"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):
|
def initialize_options(self):
|
||||||
pass
|
pass
|
||||||
@ -73,7 +91,21 @@ class Clean(Command):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
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:
|
try:
|
||||||
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
|
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -81,6 +113,40 @@ class Clean(Command):
|
|||||||
else:
|
else:
|
||||||
print("removing {}".format(path))
|
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(
|
setup(
|
||||||
name="Pyrogram",
|
name="Pyrogram",
|
||||||
version=get_version(),
|
version=get_version(),
|
||||||
@ -124,6 +190,7 @@ setup(
|
|||||||
install_requires=read("requirements.txt"),
|
install_requires=read("requirements.txt"),
|
||||||
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
|
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
|
||||||
cmdclass={
|
cmdclass={
|
||||||
"clean": Clean
|
"clean": Clean,
|
||||||
|
"generate": Generate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user