-
Notifications
You must be signed in to change notification settings - Fork 111
/
nox.py
86 lines (70 loc) · 2.57 KB
/
nox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import fnmatch
import os
import nox
def _list_files(folder, pattern):
"""Lists all files below the given folder that match the pattern."""
for root, folders, files in os.walk(folder):
for filename in files:
if fnmatch.fnmatch(filename, pattern):
yield os.path.join(root, filename)
@nox.session
def check_requirements(session):
"""Checks for out of date requirements and optionally updates them."""
session.install('gcp-devrel-py-tools')
if 'update' in session.posargs:
command = 'update-requirements'
else:
command = 'check-requirements'
reqfiles = list(_list_files('.', 'requirements*.txt'))
for reqfile in reqfiles:
session.run('gcp-devrel-py-tools', command, reqfile)
@nox.session
def lint(session):
session.interpreter = 'python3' # So it understands Python3 syntax
session.install('flake8', 'flake8-import-order')
session.run(
'flake8',
'--import-order-style', 'google',
'--application-import-names',
'gen_dockerfile,local_cloudbuild,validation_utils',
'scripts',
'nox.py',
)
@nox.session
@nox.parametrize('version', ['3.4', '3.5', '3.6', '3.7'])
def tests(session, version):
session.interpreter = 'python' + version
session.install('-r', 'scripts/requirements-test.txt')
session.run(
'py.test',
'--ignore=scripts/testdata',
'--cov=scripts',
'--cov-append',
'--cov-config=.coveragerc',
'--cov-report=', # Report generated below
'scripts',
env={'PYTHONPATH': ''}
)
@nox.session
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
test runs (not system test runs), and then erases coverage data.
"""
session.interpreter = 'python3.6'
session.install('coverage', 'pytest-cov')
session.run('coverage', 'report', '--show-missing', '--fail-under=97')
session.run('coverage', 'erase')