diff --git a/.gitignore b/.gitignore index b308310a..56f842e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__/ .pytest_cache/ .mypy_cache/ dist/ +dist-doc/ build/ **/tl/__init__.py **/tl/layer.py diff --git a/DEVELOPING.md b/DEVELOPING.md index b248bea0..5e7d7799 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -2,12 +2,19 @@ Code generation: ```sh pip install -e generator/ -python -m telethon_generator.codegen api.tl client/src/telethon/_impl/tl -python -m telethon_generator.codegen mtproto.tl client/src/telethon/_impl/tl/mtproto +python tools/codegen.py ``` Formatting, type-checking and testing: +```sh +pip install isort black mypy pytest pytest-asyncio +python tools/check.py ``` -./check.sh + +Documentation: + +```sh +pip install sphinx_rtd_theme +python tools/docgen.py ``` diff --git a/check.sh b/check.sh deleted file mode 100644 index 180cf92c..00000000 --- a/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -isort . --profile black --gitignore -black . --extend-exclude "tl/(abcs|functions|types)/\w+.py" -mypy --strict . -pytest . -m "not net" diff --git a/tools/check.py b/tools/check.py new file mode 100644 index 00000000..cef5d738 --- /dev/null +++ b/tools/check.py @@ -0,0 +1,22 @@ +""" +Sort imports, format code, type-check and run offline tests. +""" +import subprocess +import sys + + +def run(*args: str) -> int: + return subprocess.run((sys.executable, "-m", *args)).returncode + + +def main() -> None: + exit( + run("isort", ".", "--profile", "black", "--gitignore") + or run("black", ".", "--extend-exclude", r"tl/(abcs|functions|types)/\w+.py") + or run("mypy", "--strict", ".") + or run("pytest", ".", "-m", "not net") + ) + + +if __name__ == "__main__": + main() diff --git a/tools/codegen.py b/tools/codegen.py new file mode 100644 index 00000000..ebec85d9 --- /dev/null +++ b/tools/codegen.py @@ -0,0 +1,24 @@ +""" +Run `telethon_generator.codegen` on both `api.tl` and `mtproto.tl` to output +corresponding Python code in the default directories under the `client/`. +""" +import subprocess +import sys + +GENERATOR = "telethon_generator.codegen" +ROOT = "client/src/telethon/_impl" + + +def run(*args: str) -> int: + return subprocess.run((sys.executable, "-m", *args)).returncode + + +def main() -> None: + exit( + run(GENERATOR, "api.tl", f"{ROOT}/tl") + or run(GENERATOR, "mtproto.tl", f"{ROOT}/tl/mtproto") + ) + + +if __name__ == "__main__": + main() diff --git a/tools/docgen.py b/tools/docgen.py new file mode 100644 index 00000000..9a5960ea --- /dev/null +++ b/tools/docgen.py @@ -0,0 +1,17 @@ +""" +Run `sphinx-build` to create HTML documentation and detect errors. +""" +import subprocess +import sys + + +def run(*args: str) -> int: + return subprocess.run((sys.executable, "-m", *args)).returncode + + +def main() -> None: + exit(run("sphinx", "-nW", "client/doc", "dist-doc")) + + +if __name__ == "__main__": + main()