blob: ddba8cd606d6dbc8d3b12789722e009a07a2c355 [file] [log] [blame]
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -07001# 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"""
16Invoke tasks
17"""
18import os
19
20from invoke import task, Collection
21
22ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
23
24ns = Collection()
25
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070026# Building
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070027build_tasks = Collection()
Ray216ce2a2022-08-16 14:50:30 -040028ns.add_collection(build_tasks, name="build")
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070029
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070030@task
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070031def build(ctx, install=False):
32 if install:
33 ctx.run('python -m pip install .[build]')
34
Ray216ce2a2022-08-16 14:50:30 -040035 ctx.run("python -m build")
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070036
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070037build_tasks.add_task(build, default=True)
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070038
39@task
Ray216ce2a2022-08-16 14:50:30 -040040def release_build(ctx):
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070041 build(ctx, install=True)
Ray216ce2a2022-08-16 14:50:30 -040042
43build_tasks.add_task(release_build, name="release")
44
Ray216ce2a2022-08-16 14:50:30 -040045@task
46def mkdocs(ctx):
47 ctx.run("mkdocs build -f docs/mkdocs/mkdocs.yml")
48
Ray216ce2a2022-08-16 14:50:30 -040049build_tasks.add_task(mkdocs, name="mkdocs")
50
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070051# Testing
Ray216ce2a2022-08-16 14:50:30 -040052test_tasks = Collection()
53ns.add_collection(test_tasks, name="test")
54
Ray216ce2a2022-08-16 14:50:30 -040055@task
Alan Rosenthala3e46742022-11-23 11:26:29 -050056def test(ctx, filter=None, junit=False, install=False, html=False):
Ray216ce2a2022-08-16 14:50:30 -040057 # Install the package before running the tests
58 if install:
59 ctx.run("python -m pip install .[test]")
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070060
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070061 args = ""
62 if junit:
63 args += "--junit-xml test-results.xml"
64 if filter is not None:
65 args += " -k '{}'".format(filter)
Alan Rosenthala3e46742022-11-23 11:26:29 -050066 if html:
67 args += "--html results.html"
Ray216ce2a2022-08-16 14:50:30 -040068 ctx.run("python -m pytest {} {}".format(os.path.join(ROOT_DIR, "tests"), args))
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070069
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070070test_tasks.add_task(test, default=True)
Gilles Boccon-Gibod6ac91f72022-05-16 19:42:31 -070071
Gilles Boccon-Gibod1f782432022-08-16 13:37:26 -070072@task
73def release_test(ctx):
74 test(ctx, install=True)
75
76test_tasks.add_task(release_test, name="release")