Add generate command to setup.py

This commit is contained in:
Dan 2018-08-25 15:14:51 +02:00
parent d6a0fcf4ad
commit 47f8a4eb34

View File

@ -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,
}
)