Skip to content

Commit

Permalink
Initial Top Level make.py Supporting lint/test (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleptomania committed Apr 24, 2023
1 parent c54100c commit 428ad41
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 26 deletions.
47 changes: 27 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -89,40 +106,30 @@ 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
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.
Expand Down
52 changes: 46 additions & 6 deletions doc/make.py → make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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()

0 comments on commit 428ad41

Please sign in to comment.