/
tasks.py
135 lines (107 loc) · 2.78 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
##########################################################################
# Copyright (c) 2010-2020 Robert Bosch GmbH
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
##########################################################################
"""
Tasks for maintaining the project.
Execute 'invoke --list' for guidance on using Invoke
"""
import pathlib
import re
import shutil
import webbrowser
from pathlib import Path
from invoke import task
ROOT_DIR = Path(__file__).parent
TEST_DIR = ROOT_DIR / "tests"
COVERAGE_DIR = TEST_DIR / "coverage_report.html"
SOURCE_DIR = ROOT_DIR / "src"
DOCS_DIR = ROOT_DIR / "docs"
DOCS_BUILD_DIR = DOCS_DIR / "_build"
DOCS_INDEX = DOCS_BUILD_DIR / "index.html"
PYTHON_DIRS = [str(d) for d in [SOURCE_DIR, TEST_DIR]]
COPYRIGHT = """\
None
"""
def _delete_file(file):
try:
file.unlink(missing_ok=True)
except TypeError:
# missing_ok argument added in 3.8
try:
file.unlink()
except FileNotFoundError:
pass
@task
def test(c):
"""
Run tests
"""
c.run("investporto")
@task
def docs(c):
"""
Generate documentation
"""
c.run("sphinx-build -b html {} {}".format(DOCS_DIR, DOCS_BUILD_DIR))
webbrowser.open(DOCS_INDEX.as_uri())
@task
def clean_docs(c):
"""
Clean up files from documentation builds
"""
c.run("rm -fr {}".format(DOCS_BUILD_DIR))
@task
def clean_build(c):
"""
Clean up files from package building
"""
c.run("rm -fr build/")
c.run("rm -fr dist/")
c.run("rm -fr .eggs/")
c.run("find . -name '*.egg-info' -exec rm -fr {} +")
c.run("find . -name '*.egg' -exec rm -f {} +")
@task
def clean_python(c):
"""
Clean up python file artifacts
"""
c.run("find . -name '*.pyc' -exec rm -f {} +")
c.run("find . -name '*.pyo' -exec rm -f {} +")
c.run("find . -name '*~' -exec rm -f {} +")
c.run("find . -name '__pycache__' -exec rm -fr {} +")
@task
def clean_tests(c):
"""
Clean up files from testing
"""
# shutil.rmtree(TOX_DIR, ignore_errors=True)
shutil.rmtree(COVERAGE_DIR, ignore_errors=True)
@task(pre=[clean_build, clean_python, clean_tests, clean_docs])
def clean(c):
"""
Runs all clean sub-tasks
"""
pass
@task(clean)
def dist(c):
"""
Build source and wheel packages
"""
c.run("python setup.py sdist")
c.run("python setup.py bdist_wheel")
@task(pre=[clean, dist])
def release(c):
"""
Make a release of the python package to pypi
"""
c.run("twine upload dist/*")
@task
def run(c, level="INFO"):
"""run the tool"""
c.run("rm -f killme.log")
c.run(f"investporto")