-
Notifications
You must be signed in to change notification settings - Fork 38
/
tasks.py
90 lines (67 loc) · 1.82 KB
/
tasks.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
87
88
89
90
# flake8: noqa
from pathlib import Path
from invoke import task
from pathlib import Path
import os
import shutil
QUOTE = '"' if os.name == "nt" else "'"
CHANGELOG = "CHANGELOG"
filters = ["poc", "new release", "wip", "cleanup", "!nocl"]
def filter_entries(filename):
buffer = []
with open(filename) as old_file:
buffer = old_file.read().split("\n")
with open(filename, "w") as new_file:
for line in buffer:
if not any(bad_word in line.lower() for bad_word in filters):
new_file.write(line + "\n")
assert Path.cwd() == Path(__file__).parent
@task()
def build(ctx):
"""Generates dist tar ball"""
ctx.run("python setup.py sdist")
@task
def flake(ctx):
"""Runs flake8 against whole project"""
ctx.run("flake8")
@task
def mypy(ctx):
"""Runs mypy against the codebase"""
ctx.run("mypy --config mypy.ini")
@task
def black(ctx):
"""Reformat code with black"""
ctx.run("black -l130 -tpy37 src")
@task
def clean(ctx):
to_be_removed = [
"report",
"dist/",
".coverage*",
"output*",
]
for item in to_be_removed:
fs_entry = Path(item)
if fs_entry.is_dir:
shutil.rmtree(item)
elif fs_entry.is_file():
fs_entry.unlink()
else:
for fs_entry in Path().glob(item):
fs_entry.unlink()
@task
def changelog(ctx, version=None):
if version is not None:
version = f"-c {version}"
else:
version = ""
ctx.run(f"gcg -x -o {CHANGELOG} -O rpm {version}")
filter_entries(CHANGELOG)
@task
def release(ctx, version=None):
assert version != None
changelog(ctx, version)
ctx.run(f"git add {CHANGELOG}")
ctx.run(f"git commit -m {QUOTE}New Release {version}{QUOTE}")
ctx.run(f"git tag {version}")
build(ctx)