-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtasks.py
More file actions
220 lines (161 loc) · 5.64 KB
/
Copy pathtasks.py
File metadata and controls
220 lines (161 loc) · 5.64 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# -*- coding: utf-8 -*-
"""
Goal: store shortcuts to common tasks
@authors:
Andrei Sura <sura.andrei@gmail.com>
"""
# import sys
from invoke import task
from onefl.partner_name import PartnerName # noqa
from onefl.partner_name import VALID_PARTNERS
STATUS_PASS = '✔'
STATUS_FAIL = '✗'
@task
def list(ctx):
""" Show available tasks """
ctx.run('inv -l')
@task
def prep_develop(ctx):
""" Install the requirements """
ctx.run('pip install -U -r requirements.txt')
print("==> Pip packages installed:")
ctx.run('pip freeze')
@task
def show_libs(ctx):
# helper for showing installed libs
ctx.run("pip freeze | grep -E 'dill|pandas|pyodbc|setuptools-scm|SQLAlchemy'") # noqa
ctx.run("pip freeze | grep -E 'invoke|mock|pylint|pytest-cov|tox|PyInstaller'") # noqa
@task
def extract_linked(ctx):
ctx.run("python scripts/extract_existing_linkage_data.py -lnk")
@task(aliases=['hash'])
def hasher(ctx, ask=True):
""" Generate hashes from PHI """
inputfolder = 'data'
outputfolder = 'data'
opt_ask = '--ask' if ask else ''
ctx.run('PYTHONPATH=. python run/hasher.py -i {} -o {} {}'
.format(inputfolder, outputfolder, opt_ask))
@task
def demo(ctx, ask=True):
""" Generate hashes from PHI """
inputfolder = '.'
outputfolder = '.'
opt_ask = '--ask' if ask else ''
ctx.run('PYTHONPATH=. python run/hasher.py -i {} -o {} {}'
.format(inputfolder, outputfolder, opt_ask))
@task(aliases=['link'],
help={'partner': 'The partner name: {}'.format(VALID_PARTNERS)})
def linker(ctx, partner, ask=True):
""" Generate OneFlorida Ids from hashes """
inputfolder = 'data'
outputfolder = 'data'
opt_ask = '--ask' if ask else ''
if partner:
ctx.run('PYTHONPATH=. python run/linker.py -i {} -o {} -p {} {}'
.format(inputfolder, outputfolder, partner, opt_ask))
else:
print("""
Usage:
inv link --inputdir=dir --outputdir=dir -p=partner --ask
""")
print("[{}] Please specify a valid partner name"
" and input directories.\n"
"Available partners: {}"
.format(STATUS_FAIL, VALID_PARTNERS))
@task
def link_flm(ctx):
linker(ctx, partner=PartnerName.FLM.value)
@task
def link_ufh(ctx):
linker(ctx, partner=PartnerName.UFH.value)
@task
def link_orh(ctx):
linker(ctx, partner=PartnerName.ORH.value)
@task
def link_umi(ctx):
linker(ctx, partner=PartnerName.UMI.value)
@task
def link_chp(ctx):
linker(ctx, partner=PartnerName.CHP.value)
@task
def lint(ctx):
""" Show the lint score """
ctx.run("which pylint || pip install pylint")
ctx.run("pylint -f parseable onefl")
@task
def test(ctx):
""" Run tests
-s: shows details
"""
ctx.run('PYTHONPATH="." py.test -v -s --tb=short tests/ --color=yes')
@task(aliases=['cov'])
def coverage(ctx):
""" Create coverage report """
ctx.run('PYTHONPATH="." py.test -v -s --tb=short tests/ --color=yes'
' --cov onefl ') # --cov-config tests/.coveragerc')
@task(aliases=['cov_html'])
def coverage_html(ctx):
""" Create coverage report and open it in the browser"""
ctx.run('PYTHONPATH="." py.test --tb=short -s --cov onefl '
' --cov-report term-missing --cov-report html tests/')
ctx.run('open htmlcov/index.html')
@task
def devel_install(ctx):
ctx.run('python setup.py develop')
@task
def devel_uninstall(ctx):
ctx.run('python setup.py develop -u')
@task
def sdist(ctx):
""" Create a `source` distribution """
ctx.run("python setup.py sdist")
@task
def pypi_check_config(ctx):
ctx.run("echo 'Check the presence of the ~/.pypirc config file'")
ctx.run("test -f ~/.pypirc || echo 'Please create the ~/.pypirc file. "
"Here is a template: \n'", echo=False)
ctx.run("(test -f ~/.pypirc && echo "")|| (cat config/pypirc && exit 1)",
echo=False)
@task(pre=[pypi_check_config])
def pypi_register(ctx):
""" Use the ~/.pypirc config to register the package """
ctx.run("python setup.py register -r deduper")
@task(pre=[pypi_check_config])
def pypi_upload(ctx):
""" Use the ~/.pypirc config to upload the package """
ctx.run("which twine || pip install twine")
ctx.run("python setup.py sdist --formats=zip bdist_wheel")
ctx.run("twine upload dist/* -r deduper")
print("Done. To test please run: "
"python -m virtualenv venv "
" && source ./venv/bin/activate "
" && pip install -U deduper && hasher -v")
@task
def pypi_wheel(ctx):
"""
Download all `wheel` packages
If the target machine has no access to internet we can build, ship, install
pip wheel -r requirements-to-freeze.txt -w BUILT_WHEELS
scp -r BUILT_WHEELS production_server:WHEE
pip install -r requirements-to-freeze.txt --no-index --find-links WHEE
"""
ctx.run('pip wheel deduper -r requirements-to-freeze.txt -w BUILT_WHEELS')
@task
def clean(ctx):
""" Remove all generated files """
ctx.run('find . -type f -name "*.pyc" -print | xargs rm -f')
ctx.run('rm -rf htmlcov/ .coverage pylint.out')
ctx.run('rm -rf .tox/* .ropeproject/')
ctx.run('rm -rf ./dist ./build ./.eggs ./*.egg-info ./BUILT_WHEELS')
# ctx.run('rm -f db.sqlite')
@task
def clean_log(ctx):
""" Remove log file """
ctx.run('rm -f logs/deduper.log')
@task
def package_hasher(ctx):
# ctx.run('pyinstaller --onefile --icon resources/lock_icon.ico --version-file=resources/version.txt run/hasher.py') # noqa
ctx.run('pyinstaller --onefile --icon resources/lock_icon.ico run/hasher.py') # noqa
ctx.run('echo "Test the exe: dist/hasher.exe -v"')
ctx.run('dist\hasher.exe -v')