-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
143 lines (109 loc) · 4.22 KB
/
Makefile
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
# Global constants for whole Makefile
PYTHON = python3.7
MAIN_MODULE = medtagger
SCRIPTS_DIRECTORY = scripts
# Tests configuration
ifdef TESTS
TESTS_TO_RUN = -k $(TESTS)
else
TESTS_TO_RUN =
endif
COVERAGE_LIMIT = 0
MAX_CYCLOMATIC_COMPLEXITY = 5
UNIT_TESTS_MODULE = tests/unit_tests
FUNCTIONAL_TESTS_MODULE = tests/functional_tests
FUNCTIONAL_TESTS_DOCKER_COMPOSE = ../.travis/backend_functional_tests_docker-compose.yml
PYTEST_SLOWEST_TESTS=30
# Third party configuration files
PYLINT_CONFIG_FILE = .pylintrc
PYLINT_UNIT_TESTS_CONFIG_FILE = .test.pylintrc
#
# Development setup
#
venv:
# Disable Cassandra Driver tweaks - not needed in development setup
export CASS_DRIVER_NO_CYTHON=1
export CASS_DRIVER_NO_EXTENSIONS=1
virtualenv -p $(PYTHON) venv
venv/bin/pip install -r requirements.txt
venv/bin/pip install -r requirements.dev.txt
install_packages:
$(PYTHON) -m pip install -r requirements.txt
install_dev_packages:
$(PYTHON) -m pip install -r requirements.dev.txt
#
# Running MedTagger
#
sync_configuration:
PYTHONPATH=`pwd` $(PYTHON) scripts/sync_configuration.py
run_rest:
PYTHONPATH=`pwd` $(PYTHON) medtagger/api/rest.py
run_rest_production:
PYTHONPATH=`pwd` uwsgi --http :51000 --gevent 1000 --master --wsgi-file medtagger/api/rest.py --plugin http --http-keepalive --limit-post 10485760 --callable app --processes 4
run_websocket:
PYTHONPATH=`pwd` $(PYTHON) medtagger/api/websocket.py
run_websocket_production:
PYTHONPATH=`pwd` uwsgi --http :51001 --gevent 1000 --http-websockets --master --wsgi-file medtagger/api/websocket.py --callable app
run_workers:
PYTHONPATH=`pwd` celery -A medtagger.workers worker --loglevel=info
run_database_migrations:
PYTHONPATH=`pwd` alembic upgrade head
#
# Dependencies
#
start_dependencies:
cd .. && docker-compose up -d cassandra postgres rabbitmq
make update_dependencies
stop_dependencies:
cd .. && docker-compose down
clear_dependencies: stop_dependencies
docker volume rm medtagger_postgres-data medtagger_cassandra-data medtagger_rabbitmq-data
update_dependencies:
./scripts/dev__prepare_backend.sh
#
# Testing
#
test: test_pylint test_flake8 test_mypy unit_tests
test_pylint:
pylint $(MAIN_MODULE) $(SCRIPTS_DIRECTORY) --rcfile=$(PYLINT_CONFIG_FILE)
pylint $(UNIT_TESTS_MODULE) $(FUNCTIONAL_TESTS_MODULE) --rcfile=$(PYLINT_UNIT_TESTS_CONFIG_FILE)
test_flake8:
flake8 $(MAIN_MODULE) $(UNIT_TESTS_MODULE) $(FUNCTIONAL_TESTS_MODULE) $(SCRIPTS_DIRECTORY) --max-complexity=$(MAX_CYCLOMATIC_COMPLEXITY)
test_mypy:
mypy --ignore-missing-imports $(MAIN_MODULE) $(UNIT_TESTS_MODULE) $(FUNCTIONAL_TESTS_MODULE) $(SCRIPTS_DIRECTORY)
unit_tests:
. $(UNIT_TESTS_MODULE)/configuration.sh && pytest --cov=$(MAIN_MODULE) --cov-fail-under=$(COVERAGE_LIMIT) --durations=$(PYTEST_SLOWEST_TESTS) $(UNIT_TESTS_MODULE) $(TESTS_TO_RUN)
functional_tests:
make functional_tests__prepare_environment
@if ! make functional_tests__run; then\
make functional_tests__clear_dependencies;\
echo "Functional tests failed!";\
exit 1;\
fi
echo "Functional tests passed!"
make functional_tests__delete_environment
functional_tests__prepare_environment:
docker-compose -f $(FUNCTIONAL_TESTS_DOCKER_COMPOSE) up -d cassandra postgres rabbitmq
. $(FUNCTIONAL_TESTS_MODULE)/configuration.sh && ./$(SCRIPTS_DIRECTORY)/wait_for_dependencies.sh
. $(FUNCTIONAL_TESTS_MODULE)/configuration.sh && alembic upgrade head
functional_tests__run:
. $(FUNCTIONAL_TESTS_MODULE)/configuration.sh && pytest --durations=$(PYTEST_SLOWEST_TESTS) $(FUNCTIONAL_TESTS_MODULE) $(TESTS_TO_RUN)
functional_tests__delete_environment:
. $(FUNCTIONAL_TESTS_MODULE)/configuration.sh && alembic downgrade base
make functional_tests__clear_dependencies
functional_tests__clear_dependencies:
docker-compose -f $(FUNCTIONAL_TESTS_DOCKER_COMPOSE) down
functional_tests_docker:
./$(SCRIPTS_DIRECTORY)/wait_for_dependencies.sh
alembic upgrade head
pytest --durations=$(PYTEST_SLOWEST_TESTS) $(FUNCTIONAL_TESTS_MODULE)
alembic downgrade base
#
# Utilities
#
clean:
rm -rf venv
find . -name '*.swp' -delete
find . -name '*.pyc' -delete
find . -name '*.log' -delete
.PHONY: venv install_packages sync_configuration run_api run_workers start_dependencies stop_dependencies update_dependencies clean test test_pylint test_flake8 test_mypy unit_tests functional_tests