Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 1 | # Copyright 2021-2022 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """ |
| 16 | Invoke tasks |
| 17 | """ |
| 18 | import os |
| 19 | |
| 20 | from invoke import task, Collection |
| 21 | |
| 22 | ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 23 | |
| 24 | ns = Collection() |
| 25 | |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 26 | # Building |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 27 | build_tasks = Collection() |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 28 | ns.add_collection(build_tasks, name="build") |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 29 | |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 30 | @task |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 31 | def build(ctx, install=False): |
| 32 | if install: |
| 33 | ctx.run('python -m pip install .[build]') |
| 34 | |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 35 | ctx.run("python -m build") |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 36 | |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 37 | build_tasks.add_task(build, default=True) |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 38 | |
| 39 | @task |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 40 | def release_build(ctx): |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 41 | build(ctx, install=True) |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 42 | |
| 43 | build_tasks.add_task(release_build, name="release") |
| 44 | |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 45 | @task |
| 46 | def mkdocs(ctx): |
| 47 | ctx.run("mkdocs build -f docs/mkdocs/mkdocs.yml") |
| 48 | |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 49 | build_tasks.add_task(mkdocs, name="mkdocs") |
| 50 | |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 51 | # Testing |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 52 | test_tasks = Collection() |
| 53 | ns.add_collection(test_tasks, name="test") |
| 54 | |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 55 | @task |
Alan Rosenthal | a3e4674 | 2022-11-23 11:26:29 -0500 | [diff] [blame^] | 56 | def test(ctx, filter=None, junit=False, install=False, html=False): |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 57 | # Install the package before running the tests |
| 58 | if install: |
| 59 | ctx.run("python -m pip install .[test]") |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 60 | |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 61 | args = "" |
| 62 | if junit: |
| 63 | args += "--junit-xml test-results.xml" |
| 64 | if filter is not None: |
| 65 | args += " -k '{}'".format(filter) |
Alan Rosenthal | a3e4674 | 2022-11-23 11:26:29 -0500 | [diff] [blame^] | 66 | if html: |
| 67 | args += "--html results.html" |
Ray | 216ce2a | 2022-08-16 14:50:30 -0400 | [diff] [blame] | 68 | ctx.run("python -m pytest {} {}".format(os.path.join(ROOT_DIR, "tests"), args)) |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 69 | |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 70 | test_tasks.add_task(test, default=True) |
Gilles Boccon-Gibod | 6ac91f7 | 2022-05-16 19:42:31 -0700 | [diff] [blame] | 71 | |
Gilles Boccon-Gibod | 1f78243 | 2022-08-16 13:37:26 -0700 | [diff] [blame] | 72 | @task |
| 73 | def release_test(ctx): |
| 74 | test(ctx, install=True) |
| 75 | |
| 76 | test_tasks.add_task(release_test, name="release") |