-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtasks.py
More file actions
108 lines (88 loc) · 3.02 KB
/
tasks.py
File metadata and controls
108 lines (88 loc) · 3.02 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""Configures all tasks to run with invoke."""
from invoke import task
import glob
import os
import fnmatch
@task(
help={
'args': 'Additional arguments to pass to template file.'
' Multiple arguments should each be specified with a new --args flag, ie. `invoke build --args foo --args bar`.',
},
iterable=['args'],
)
def build(ctx, args=None):
"""Build all custom resources."""
command = ["python", "build.py"]
if args:
command.extend(args)
ctx.run(" ".join(command))
@task
def integration_test(ctx):
"""Build all custom resources."""
command = ["pytest", "integration_tests"]
ctx.run(" ".join(command))
@task(help={
'verbose': "Show which files are being removed.",
'compiled': 'Also clean up compiled python files.',
})
def clean(ctx, verbose=False, compiled=False):
"""Clean up all output files."""
command = "rm -rvf {files}" if verbose else "rm -rf {files}"
patterns = []
patterns.append('output/*')
if compiled is True:
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.pyc'):
patterns.append(os.path.join(root, filename))
for pattern in patterns:
ctx.run(command.format(files=pattern))
@task(
aliases=["flake8", "pep8"],
help={
'filename': 'File(s) to lint. Supports globbing.',
'noglob': 'Disable globbing of filenames. Can give issues in virtual environments',
},
)
def lint(ctx, filename=None, noglob=False):
"""Run flake8 python linter."""
command = 'flake8 --jobs=1'
if filename is not None:
if noglob:
templates = [filename]
else:
templates = [x for x in glob.glob(filename)]
if len(templates) == 0:
print("File `{0}` not found".format(filename))
exit(1)
command += ' ' + " ".join(templates)
print("Running command: '" + command + "'")
ctx.run(command)
@task(
help={
'filename': 'File(s) to lint. Supports globbing.',
},
)
def validate(ctx, filename=None):
"""Validate the output file(s)."""
exclude = ['bcm_mapping', 'ec2_profile']
command = 'aws-cfn-validate '
if filename is not None:
command += '{filename} '.format(filename=filename)
else:
command += 'output/*/*.json '
command += ' '.join(['--exclude {0}'.format(x) for x in exclude])
ctx.run(command)
@task(
default=True,
help={
'filename': 'Path to template(s) to process. Supports globbing.',
'noglob': 'Disable globbing of filenames. Can give issues in virtual environments',
'args': 'Additional arguments to pass to template file.'
' Multiple arguments should each be specified with a new --args flag, ie. `invoke process --args foo --args bar`.',
},
iterable=['args'],
)
def process(ctx, filename=None, noglob=False, args=None):
"""Run lint and build commands for specified template(s)."""
# lint(ctx, filename, noglob)
build(ctx, args)