summaryrefslogtreecommitdiff
path: root/plugins/tasks.py
blob: 4aac4f773b88f891c98fbf85b5cb682b748ecf0a (plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#
# coding=utf-8
# flake8: noqa E302
"""Development related tasks to be run with 'invoke'.

Make sure you satisfy the following Python module requirements if you are trying to publish a release to PyPI:
    - twine >= 1.11.0
    - wheel >= 0.31.0
    - setuptools >= 39.1.0
"""
import os
import re
import shutil
import sys

import invoke
from plugins.cmd2_ext_test import tasks as ext_test_tasks

# create namespaces
namespace = invoke.Collection()
namespace_clean = invoke.Collection('clean')
namespace.add_collection(namespace_clean, 'clean')

#####
#
# pytest, tox, pylint, and codecov
#
#####
@invoke.task(pre=[ext_test_tasks.pytest])
def pytest(_):
    """Run tests and code coverage using pytest"""
    pass


namespace.add_task(pytest)


@invoke.task(pre=[ext_test_tasks.pytest_junit])
def pytest_junit(_):
    """Run tests and code coverage using pytest"""
    pass


namespace.add_task(pytest_junit)


@invoke.task(pre=[ext_test_tasks.pytest_clean])
def pytest_clean(_):
    """Remove pytest cache and code coverage files and directories"""
    pass


namespace_clean.add_task(pytest_clean, 'pytest')


@invoke.task(pre=[ext_test_tasks.mypy])
def mypy(context):
    """Run mypy optional static type checker"""
    pass


namespace.add_task(mypy)

@invoke.task(pre=[ext_test_tasks.mypy_clean])
def mypy_clean(context):
    """Remove mypy cache directory"""
    #pylint: disable=unused-argument
    pass


namespace_clean.add_task(mypy_clean, 'mypy')


#####
#
# build and distribute
#
#####
BUILDDIR = 'build'
DISTDIR = 'dist'

@invoke.task(pre=[ext_test_tasks.build_clean])
def build_clean(_):
    """Remove the build directory"""


namespace_clean.add_task(build_clean, 'build')


@invoke.task(pre=[ext_test_tasks.dist_clean])
def dist_clean(_):
    """Remove the dist directory"""
    pass


namespace_clean.add_task(dist_clean, 'dist')


@invoke.task(pre=[ext_test_tasks.eggs_clean])
def eggs_clean(context):
    """Remove egg directories"""
    pass


namespace_clean.add_task(eggs_clean, 'eggs')


@invoke.task(pre=[ext_test_tasks.pycache_clean])
def pycache_clean(context):
    """Remove __pycache__ directories"""
    pass


namespace_clean.add_task(pycache_clean, 'pycache')


# make a dummy clean task which runs all the tasks in the clean namespace
clean_tasks = list(namespace_clean.tasks.values())


@invoke.task(pre=list(namespace_clean.tasks.values()), default=True)
def clean_all(context):
    """Run all clean tasks"""
    #pylint: disable=unused-argument
    pass


namespace_clean.add_task(clean_all, 'all')


@invoke.task(pre=[clean_all], post=[ext_test_tasks.sdist])
def sdist(context):
    "Create a source distribution"
    context.run('python setup.py sdist')


namespace.add_task(sdist)


@invoke.task(pre=[clean_all], post=[ext_test_tasks.wheel])
def wheel(context):
    "Build a wheel distribution"
    context.run('python setup.py bdist_wheel')
namespace.add_task(wheel)


@invoke.task(pre=[sdist, wheel])
def pypi(context):
    "Build and upload a distribution to pypi"
    context.run('twine upload dist/*')
namespace.add_task(pypi)


@invoke.task(pre=[sdist, wheel])
def pypi_test(context):
    "Build and upload a distribution to https://test.pypi.org"
    context.run('twine upload --repository-url https://test.pypi.org/legacy/ dist/*')
namespace.add_task(pypi_test)


# Flake8 - linter and tool for style guide enforcement and linting
@invoke.task(pre=[ext_test_tasks.flake8])
def flake8(context):
    "Run flake8 linter and tool for style guide enforcement"
    context.run("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics --exclude=.git,__pycache__,.tox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov")
namespace.add_task(flake8)