diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0d198329 --- /dev/null +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/dev-requirements.txt b/dev-requirements.txt index 17f8c034..d8968085 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,4 +2,5 @@ pytest pytest-asyncio -pytest-cov \ No newline at end of file +pytest-cov +twine \ No newline at end of file diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 066560f8..00000000 --- a/docs/Makefile +++ /dev/null @@ -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) diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index fea543e2..00000000 --- a/docs/make.bat +++ /dev/null @@ -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 diff --git a/docs/requirements.txt b/docs/requirements.txt index f83e673d..7283c8ba 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,4 @@ sphinx sphinx_rtd_theme==1.0.0 sphinx_copybutton -pypandoc -requests -sphinx-autobuild +sphinx-autobuild \ No newline at end of file diff --git a/setup.py b/setup.py index 160c0fda..d1bd9c90 100644 --- a/setup.py +++ b/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 . -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 )