mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-31 06:16:06 +00:00
Migrate setup.py commands to a Makefile
This commit is contained in:
103
setup.py
103
setup.py
@@ -16,15 +16,12 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from sys import argv
|
||||
|
||||
from setuptools import setup, find_packages, Command
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
from compiler.api import compiler as api_compiler
|
||||
from compiler.docs import compiler as docs_compiler
|
||||
from compiler.errors import compiler as errors_compiler
|
||||
|
||||
with open("requirements.txt", encoding="utf-8") as r:
|
||||
@@ -36,96 +33,6 @@ with open("pyrogram/__init__.py", encoding="utf-8") as f:
|
||||
with open("README.md", encoding="utf-8") as f:
|
||||
readme = f.read()
|
||||
|
||||
|
||||
class Clean(Command):
|
||||
DIST = ["./build", "./dist", "./Pyrogram.egg-info"]
|
||||
API = [
|
||||
"pyrogram/errors/exceptions", "pyrogram/raw/functions", "pyrogram/raw/types", "pyrogram/raw/base",
|
||||
"pyrogram/raw/all.py"
|
||||
]
|
||||
DOCS = [
|
||||
"docs/source/telegram", "docs/build", "docs/source/api/methods", "docs/source/api/types",
|
||||
"docs/source/api/bound-methods"
|
||||
]
|
||||
|
||||
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
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
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 or not paths:
|
||||
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:
|
||||
print("skipping {}".format(path))
|
||||
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:
|
||||
errors_compiler.start()
|
||||
api_compiler.start()
|
||||
|
||||
if self.docs:
|
||||
docs_compiler.start()
|
||||
|
||||
|
||||
if len(argv) > 1 and argv[1] in ["bdist_wheel", "install", "develop"]:
|
||||
api_compiler.start()
|
||||
errors_compiler.start()
|
||||
@@ -172,14 +79,10 @@ setup(
|
||||
"Documentation": "https://docs.pyrogram.org",
|
||||
},
|
||||
python_requires="~=3.6",
|
||||
package_data = {
|
||||
package_data={
|
||||
"pyrogram": ["py.typed"],
|
||||
},
|
||||
packages=find_packages(exclude=["compiler*", "tests*"]),
|
||||
zip_safe=False,
|
||||
install_requires=requires,
|
||||
cmdclass={
|
||||
"clean": Clean,
|
||||
"generate": Generate
|
||||
}
|
||||
install_requires=requires
|
||||
)
|
||||
|
Reference in New Issue
Block a user