mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-23 15:27:45 +00:00
Migrate setup.py commands to a Makefile
This commit is contained in:
parent
1ebc704146
commit
109c9d4a0a
53
Makefile
Normal file
53
Makefile
Normal file
@ -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,3 +3,4 @@
|
||||
pytest
|
||||
pytest-asyncio
|
||||
pytest-cov
|
||||
twine
|
@ -1,24 +0,0 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS = -j $(shell nproc --all)
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXPROJ = Pyrogram
|
||||
SOURCEDIR = source
|
||||
BUILDDIR = build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
lhtml: # live html
|
||||
sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \
|
||||
--watch ../pyrogram --watch resources -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
|
@ -1,36 +0,0 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=source
|
||||
set BUILDDIR=build
|
||||
set SPHINXPROJ=Pyrogram
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
|
||||
:end
|
||||
popd
|
@ -1,6 +1,4 @@
|
||||
sphinx
|
||||
sphinx_rtd_theme==1.0.0
|
||||
sphinx_copybutton
|
||||
pypandoc
|
||||
requests
|
||||
sphinx-autobuild
|
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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user