forked from static-frame/static-frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
195 lines (155 loc) · 4.69 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import sys
import typing_extensions as tp
from invoke import task # pyright: ignore
#-------------------------------------------------------------------------------
@task
def clean(context):
'''Clean doc and build artifacts
'''
context.run('rm -rf coverage.xml')
context.run('rm -rf htmlcov')
context.run('rm -rf doc/build')
context.run('rm -rf build')
context.run('rm -rf dist')
context.run('rm -rf *.egg-info')
context.run('rm -rf .coverage')
context.run('rm -rf .mypy_cache')
context.run('rm -rf .pytest_cache')
context.run('rm -rf .hypothesis')
context.run('rm -rf .ipynb_checkpoints')
context.run('rm -rf .ruff_cache')
@task()
def doc(context):
'''Build docs
'''
context.run(f'{sys.executable} doc/doc_build.py')
@task
def performance(context):
'''Run performance tests.
'''
# NOTE: we do not get to see incremental output when running this
cmd = 'python static_frame/performance/main.py --performance "*"'
context.run(cmd)
@task
def interface(context, container=None, doc=False):
'''
Optionally select a container type to discover what API endpoints have examples.
'''
import static_frame as sf
from static_frame.core.container import ContainerBase
def subclasses(cls) -> tp.Iterator[tp.Type]:
if cls.__name__ not in ('IndexBase', 'IndexDatetime'):
yield cls
for sub in cls.__subclasses__():
yield from subclasses(sub)
if not container:
def frames():
for cls in sorted(subclasses(ContainerBase),
key=lambda cls: cls.__name__):
yield cls.interface.unset_index()
f = sf.Frame.from_concat(frames(), axis=0, index=sf.IndexAutoFactory)
else:
f = getattr(sf, container).interface
if not doc:
f = f.drop['doc']
dc = sf.DisplayConfig(cell_max_width_leftmost=99, cell_max_width=60, display_rows=99999, display_columns=99)
print(f.display(dc))
#-------------------------------------------------------------------------------
@task
def test(context,
unit=False,
cov=False,
pty=False,
warnings=False,
):
'''Run tests.
Args:
backward: If True, we exclude unit_forward tests.
'''
fps = []
fps.append('static_frame/test/unit')
fps.append('static_frame/test/typing')
if sys.version_info[:2] >= (3, 11):
fps.append('static_frame/test/unit_forward')
if not unit:
fps.append('static_frame/test/integration')
fps.append('static_frame/test/property')
w_flag = '--disable-pytest-warnings'
cmd = f'pytest -s --tb=native {"" if warnings else w_flag} {" ".join(fps)}'
if cov:
cmd += ' --cov=static_frame --cov-report=xml'
print(cmd)
context.run(cmd, pty=pty)
@task
def testex(context,
cov=False,
pty=False,
):
'''Test example generation
'''
cmd = 'pytest -s --tb=native doc/test_example_gen.py'
if cov:
cmd += ' --cov=static_frame --cov-report=xml'
print(cmd)
context.run(cmd, pty=pty)
@task
def testtyping(context,
pty=False,
):
'''Run mypy on targetted typing tests
'''
context.run('pytest -s --tb=native static_frame/test/typing')
context.run('pyright static_frame/test/typing', pty=pty)
context.run('mypy --strict static_frame/test/typing', pty=pty)
@task
def coverage(context):
'''
Perform code coverage, and open report HTML.
'''
cmd = 'pytest -s --cov=static_frame/core --cov-report html'
print(cmd)
context.run(cmd)
import webbrowser
webbrowser.open('htmlcov/index.html')
@task
def mypy(context,
pty=False,
):
'''Run mypy static analysis.
'''
context.run('mypy --strict', pty=pty)
@task
def pyright(context,
pty=False,
):
'''Run pyright static analysis.
'''
context.run('pyright', pty=pty)
@task
def isort(context):
'''Run isort as a check.
'''
context.run('isort static_frame doc --check')
@task
def lint(context):
'''Run pylint static analysis.
'''
context.run('pylint -f colorized static_frame')
@task(pre=(mypy, pyright, lint, isort)) # pyright: ignore
def quality(context):
'''Perform all quality checks.
'''
@task
def format(context):
'''Run mypy static analysis.
'''
context.run('isort static_frame doc')
#-------------------------------------------------------------------------------
@task(pre=(clean,)) # pyright: ignore
def build(context):
'''Build packages
'''
context.run(f'{sys.executable} setup.py sdist bdist_wheel')
@task(pre=(build,), post=(clean,)) # pyright: ignore
def release(context):
context.run('twine upload dist/*')