Skip to content

Commit

Permalink
Migrate setup.py commands to a Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
delivrance committed Apr 24, 2022
1 parent 1ebc704 commit 109c9d4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 164 deletions.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
VENV := venv
PYTHON := $(VENV)/bin/python

RM := rm -rf

.PHONY: venv build docs

venv:
$(RM) $(VENV)
python3 -m venv $(VENV)
$(PYTHON) -m pip install -U pip wheel setuptools
$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt -r docs/requirements.txt
@echo "Created venv with $$($(PYTHON) --version)"

clean-build:
$(RM) *.egg-info build dist

clean-docs:
$(RM) docs/build
$(RM) docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram

clean-api:
$(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types

clean:
make clean-build
make clean-docs
make clean-api

api:
cd compiler/api && ../../$(PYTHON) compiler.py
cd compiler/errors && ../../$(PYTHON) compiler.py

docs-live:
make clean-docs
cd compiler/docs && ../../$(PYTHON) compiler.py
$(RM) docs/source/telegram
$(VENV)/bin/sphinx-autobuild \
--host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \
--watch pyrogram --watch docs/resources \
-b html "docs/source" "docs/build/html" -j auto

docs:
make clean-docs
cd compiler/docs && ../../$(PYTHON) compiler.py
$(VENV)/bin/sphinx-build \
-b html "docs/source" "docs/build/html" -j auto

build:
make clean-build
make clean-api
$(PYTHON) setup.py sdist
$(PYTHON) setup.py bdist_wheel
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

pytest
pytest-asyncio
pytest-cov
pytest-cov
twine
24 changes: 0 additions & 24 deletions docs/Makefile

This file was deleted.

36 changes: 0 additions & 36 deletions docs/make.bat

This file was deleted.

4 changes: 1 addition & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
sphinx
sphinx_rtd_theme==1.0.0
sphinx_copybutton
pypandoc
requests
sphinx-autobuild
sphinx-autobuild
103 changes: 3 additions & 100 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,96 +33,6 @@
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()
Expand Down Expand Up @@ -172,14 +79,10 @@ def run(self):
"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
)

0 comments on commit 109c9d4

Please sign in to comment.