-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
65 lines (50 loc) · 1.4 KB
/
manage.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
import contextlib
import os
from pathlib import Path
from bdc_wtss import app
from flask_script import Manager
manager = Manager(app)
@contextlib.contextmanager
def working_directory(path):
"""Changes working directory and returns to previous on exit."""
owd = os.getcwd()
print(path)
try:
os.chdir(path)
yield path
finally:
os.chdir(owd)
@manager.command
def run():
host = os.environ.get('SERVER_HOST', '0.0.0.0')
try:
port = int(os.environ.get('PORT', '5000'))
except ValueError:
port = 5000
app.run(host, port)
@manager.command
def docs(serve=False, port=5001):
import subprocess
from http.server import test, CGIHTTPRequestHandler
from pathlib import Path
docs_directory = Path(os.path.abspath(os.path.dirname(__file__))) / 'docs'
with working_directory(str(docs_directory)):
# Generate Documentation through Makefile
subprocess.call('make html', shell=True)
if serve:
with working_directory(str(docs_directory / 'build/html')):
test(HandlerClass=CGIHTTPRequestHandler, port=int(port), bind='')
@manager.command
def test():
"""Run the unit tests."""
import pytest
pytest.main(["-v",
"--cov-report",
"html",
"--cov-report",
"annotate",
"--cov=bdc_wtss",
"-s",
"tests/"])
if __name__ == '__main__':
manager.run()