diff --git a/tools/check.py b/tools/check.py index cef5d738..80906ecb 100644 --- a/tools/check.py +++ b/tools/check.py @@ -1,8 +1,11 @@ """ -Sort imports, format code, type-check and run offline tests. +Check formatting, type-check and run offline tests. """ import subprocess import sys +import tempfile + +BLACK_IGNORE = r"tl/(abcs|functions|types)/\w+.py" def run(*args: str) -> int: @@ -10,12 +13,14 @@ def run(*args: str) -> int: 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") - ) + with tempfile.TemporaryDirectory() as tmp_dir: + exit( + run("isort", ".", "-c", "--profile", "black", "--gitignore") + or run("black", ".", "--check", "--extend-exclude", BLACK_IGNORE) + or run("mypy", "--strict", ".") + or run("sphinx", "-nW", "client/doc", tmp_dir) + or run("pytest", ".", "-m", "not net") + ) if __name__ == "__main__": diff --git a/tools/fmt.py b/tools/fmt.py new file mode 100644 index 00000000..fde86123 --- /dev/null +++ b/tools/fmt.py @@ -0,0 +1,22 @@ +""" +Sort imports and format code. +""" +import subprocess +import sys + +BLACK_IGNORE = r"tl/(abcs|functions|types)/\w+.py" + + +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", BLACK_IGNORE) + ) + + +if __name__ == "__main__": + main()