-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
186 lines (148 loc) · 5.56 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
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
# (C) Copyright Digital Catapult Limited 2015-2016
.PHONY: clean requirements test pylint html docs
SHELL = /bin/bash
# You should not set these variables from the command line.
# Directory that this Makfile is in
SERVICEDIR = $(shell pwd)
# Directory containing the source code
SOURCE_DIR = repository
# Directory to output the test reports
TEST_REPORTS_DIR = tests/unit/reports
# You can set these variables from the command line.
# App to build docs from python sphinx commented code
SPHINXAPIDOC = sphinx-apidoc
# Directory to build docs in
BUILDDIR = $(SERVICEDIR)/_build
# Service version (required for $(SPHINXAPIDOC))
SERVICE_VERSION = 0.4.0
# Service release (required for $(SPHINXAPIDOC))
SERVICE_RELEASE = 0.4.0
# Directory to output python in source sphinx documentation
BUILD_SOURCE_DOC_DIR = $(BUILDDIR)/in_source
# Directory to output markdown converted docs to
BUILD_SERVICE_DOC_DIR = $(BUILDDIR)/service/html
# Directory to output markdown converted docs to
BUILD_API_DOC_DIR = $(BUILDDIR)/api/html
# Directory to find markdown docs
DOC_DIR = $(SERVICEDIR)/documents
# Directory to find markdown docs
MD_DOC_DIR = $(DOC_DIR)/markdown
# Directory to find markdown docs
API_DOC_DIR = $(DOC_DIR)/apiary
# Requirement variant to build, can be dev or prod
REQUIREMENT = prod
ENVS = prod dev
# Branch/tag start point from which change logs are created
CHANGELOG_START = tags/0.9.7
# Branch/tag end point from which change logs are created
CHANGELOG_END = tags/0.9.8
# Create list of target .html file names to be created based on all .md files found in the 'doc markdown directory'
md_docs := $(patsubst $(MD_DOC_DIR)/%.md,$(BUILD_SERVICE_DOC_DIR)/%.html,$(wildcard $(MD_DOC_DIR)/*.md)) \
$(BUILD_SERVICE_DOC_DIR)/README.html
# Create list of target .html file names to be created based on all .md files found in the 'doc apiary directory'
api_docs := $(patsubst $(API_DOC_DIR)/%.md,$(BUILD_API_DOC_DIR)/%.html,$(wildcard $(API_DOC_DIR)/*.md))
clean:
rm -fr $(TEST_REPORTS_DIR)
# Install requirements
requirements:
pip install -r $(SERVICEDIR)/requirements/$(REQUIREMENT).txt
if [ "$(REQUIREMENT)" = "dev" ]; then \
npm install; \
fi
# Run tests
test:
mkdir -p $(TEST_REPORTS_DIR)
py.test \
-s \
--cov $(SOURCE_DIR) tests \
--cov-report html \
--cov-report xml \
--junitxml=$(TEST_REPORTS_DIR)/unit-tests-report.xml
cloverpy $(TEST_REPORTS_DIR)/coverage.xml > $(TEST_REPORTS_DIR)/clover.xml
# Run pylint
pylint:
mkdir -p $(TEST_REPORTS_DIR)
@pylint $(SOURCE_DIR)/ --output-format=html > $(TEST_REPORTS_DIR)/pylint-report.html || {\
echo "\npylint found some problems."\
echo "Please refer to the report: $(TEST_REPORTS_DIR)/pylint-report.html\n";\
}
# Create .html docs from source code comments in python sphinx format
html:
$(SPHINXAPIDOC) \
-s rst \
--full \
-f \
-V $(SERVICE_VERSION) \
-R $(SERVICE_RELEASE) \
-H $(SOURCE_DIR) \
-A "Connected Digital Economy Catapult Limited" \
-o $(BUILDDIR)/rst $(SOURCE_DIR)
cd $(BUILDDIR)/rst && PYTHONPATH=$(SERVICEDIR) make html BUILDDIR=$(BUILD_SOURCE_DOC_DIR)
# Dependencies of .html document files created from files in the 'doc directory'
$(BUILD_SERVICE_DOC_DIR)/%.html : $(MD_DOC_DIR)/%.md
mkdir -p $(dir $@)
grip $< --export $@
file_translate -c $(DOC_DIR)/translate.json -i $@ -o $@
# Dependenciy of .html document files created from README.md
$(BUILD_SERVICE_DOC_DIR)/README.html : $(SERVICEDIR)/README.md
mkdir -p $(dir $@)
grip $< --export $@
file_translate -c $(DOC_DIR)/translate.json -i $@ -o $@
# Create .html docs from all markdown files
md_docs: $(md_docs)
ifneq ($(wildcard $(MD_DOC_DIR)),)
# Copy dependent files required to render the views, e.g. images
rsync \
--exclude '*.md' \
--exclude 'eap' \
--exclude 'drawio' \
-r \
$(MD_DOC_DIR)/ $(BUILD_SERVICE_DOC_DIR)
endif
# Dependencies of .html document files created from files in the 'doc directory'
$(BUILD_API_DOC_DIR)/%.html : $(API_DOC_DIR)/%.md
mkdir -p $(dir $@)
`npm bin`/aglio -i $< -o $@
# Create .html docs from all apiary files
api_docs: $(api_docs)
ifneq ($(wildcard $(API_DOC_DIR)),)
# Copy dependent files required to render the views, e.g. images
rsync \
--exclude '*.md' \
--exclude 'eap' \
--exclude 'drawio' \
-r \
$(API_DOC_DIR)/ $(BUILD_API_DOC_DIR)
endif
# Create all docs
docs: html md_docs api_docs
changelog:
mkdir -p $(BUILDDIR)
git log --no-merges --pretty=format:" * %s" $(CHANGELOG_START)..$(CHANGELOG_END) > $(BUILDDIR)/CHANGELOG.md
# Create egg_locks
egg_locks:
for env_type in $$(echo "$(ENVS)"); do \
top_level="$(SERVICEDIR)/requirements/"$$env_type"_top_level.txt" ; \
if [ -e $$top_level ]; then \
venv_path="$(SERVICEDIR)/_"$$env_type"_" ; \
req_file="$(SERVICEDIR)/requirements/"$$env_type".txt" ; \
rm -rf $$venv_path ; \
virtualenv $$venv_path ; \
source $$venv_path"/bin/activate" ; \
pip install -r $$top_level ; \
echo "################################################" > $$req_file ; \
echo "## DO NOT EDIT - AUTOMATICALLY GENERATED FILE ##" >> $$req_file ; \
echo "################################################" >> $$req_file ; \
pip freeze >> $$req_file ; \
deactivate ; \
rm -rf $$venv_path ; \
fi; \
done
dev_install:
python setup.py develop
dev_register:
python repository register_service [email protected] password developerco
dev_setup: dev_install dev_register
test_register:
python repository register_service [email protected] password toppco
test_setup: dev_install test_register