From 428ad418ab234027f7493ca14a6b4b1a5807c48f Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Mon, 24 Apr 2023 09:45:56 -0600 Subject: [PATCH] Initial Top Level make.py Supporting lint/test (#1718) --- CONTRIBUTING.md | 47 ++++++++++++++++++++++---------------- doc/make.py => make.py | 52 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 26 deletions(-) rename doc/make.py => make.py (92%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08f137714..89bdf1f53 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,7 @@ Discussion can happen in a GitHub issue's comments or on [Arcade's Discord serve ## After Making Changes After you finish your changes, you should do the following: -1. Test your changes with Arcade's test suite as well as with `mypy arcade` & `ruff arcade` +1. Test your changes according to the [Testing](#testing) section below 2. Submit a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests) from your fork to Arcade's development branch. @@ -74,13 +74,30 @@ in this repo for current tests. ### Testing Code Changes -First, run `mypy arcade` and then `ruff arcade` from inside the arcade folder. You should fix -any issues they report. +First, run the below command to run our linting tools automatically. This will run Mypy +and Ruff against Arcade. The first run of this may take some as MyPy will not have any +caches built up. Sub-sequent runs will be much faster. -Then run the framework's unit tests with the following command: +```shell +python make.py lint +``` + +If you want to run either of these tools invidually, you can do ```shell -pytest tests/unit +python make.py ruff +``` + +or + +```shell +python make.py mypy +``` + +Now you run the framework's unit tests with the following command: + +```shell +python make.py test ``` ### Building & Testing Documentation @@ -89,19 +106,14 @@ pytest tests/unit You can build & preview documentation locally using the following steps. -Change into the doc directory: -```commandline -cd doc -``` - Run the doc build to build the web page files, and host a webserver to preview: ```commandline -python ./make.py serve +python make.py serve ``` You can now open [http://localhost:8000](http://localhost:8000) in your browser to preview the docs. -The `build/html` directory will contain the generated website files. When you change source files, +The `doc/build/html` directory will contain the generated website files. When you change source files, it will automatically regenerate, and browser tabs will automatically refresh to show your updates. If you suspect the automatic rebuilds are failing to detect changes, you can @@ -109,20 +121,15 @@ run a simpler one-time build using the following instructions. #### One-time build -Change into the doc directory: -```commandline -cd doc -``` - Run the doc build to build the web page files: ```commandline -python ./make.py html +python make.py html ``` -The `build/html` directory will contain the generated website files. +The `doc/build/html` directory will contain the generated website files. Start a local web server to preview the doc: ```commandline -python -m http.server -d build/html +python -m http.server -d doc/build/html ``` You can now open [http://localhost:8000](http://localhost:8000) in your browser to preview the doc. diff --git a/doc/make.py b/make.py similarity index 92% rename from doc/make.py rename to make.py index 26bd1654e..a2b3003ea 100644 --- a/doc/make.py +++ b/make.py @@ -13,26 +13,35 @@ SPHINXBUILD = "sphinx-build" SPHINXAUTOBUILD = "sphinx-autobuild" PAPER_SIZE = None -BUILDDIR = "build" +DOCDIR = "doc" +BUILDDIR = DOCDIR + "/build" +# Linting +RUFF = "ruff" +RUFFOPTS = ["arcade"] +MYPY = "mypy" +MYPYOPTS = ["arcade"] + + +# Testing +PYTEST = "pytest" +TESTDIR = "tests" +UNITTESTS = TESTDIR + "/unit" + # Internal variables. PAPER_SIZE_OPTS = {} PAPER_SIZE_OPTS[None] = [] PAPER_SIZE_OPTS['a4'] = ['-D', 'latex_paper_size=a4'] PAPER_SIZE_OPTS['letter'] = ['-D', 'latex_paper_size=letter'] ALLSPHINXOPTS = ['-d', f'{BUILDDIR}/doctrees', *PAPER_SIZE_OPTS[PAPER_SIZE], *SPHINXOPTS, '.'] -SPHINXAUTOBUILDOPTS = ['--watch', '../arcade'] +SPHINXAUTOBUILDOPTS = ['--watch', './arcade'] # Important: the i18n builder cannot share the environment and doctrees with the others # This allows for internationalization / localization of doc. I18NSPHINXOPTS = [*PAPER_SIZE_OPTS[PAPER_SIZE], *SPHINXOPTS, '.'] -# Change dirs into root arcade project folder -os.chdir(Path(__file__).parent.resolve()) - - # User-friendly check for dependencies and binaries binaries = ['sphinx-build', 'sphinx-autobuild'] libraries = ['typer'] @@ -336,5 +345,36 @@ def pseudoxml(): print("Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml.") +@app.command() +def lint(): + run([RUFF, *RUFFOPTS]) + print("Ruff Finished.") + run([MYPY, *MYPYOPTS]) + print("Mypy Finished.") + print("Linting Complete.") + + +@app.command() +def ruff(): + run([RUFF, *RUFFOPTS]) + print("Ruff Finished.") + + +@app.command() +def mypy(): + run([MYPY, *MYPYOPTS]) + print("MyPy Finished.") + + +@app.command() +def test_full(): + run([PYTEST, TESTDIR]) + + +@app.command() +def test(): + run([PYTEST, UNITTESTS]) + + if __name__ == "__main__": app()