/
makefile
357 lines (305 loc) · 12.4 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# ------------------------------------------------------------------------------
# Makefile for pywbem
#
# Supported platforms for this makefile:
# Linux
# OS-X
# Windows (with CygWin, MinGW, etc.)
#
# Prerequisite commands for this makefile:
# make
# bash, sh, rm, mv, mkdir, echo
# find, xargs, grep, sed, tar
# python (Some active Python version, virtualenv is supported)
# pip (in the active Python environment)
# ------------------------------------------------------------------------------
# Determine OS platform make runs on
ifeq ($(OS),Windows_NT)
PLATFORM := Windows
else
# Values: Linux, Darwin
PLATFORM := $(shell uname -s)
endif
# Name of this Python package
package_name := pywbem
# Package version as specified in pywbem/_version.py
package_specified_version := $(shell sh -c "grep -E '^ *__version__ *= ' pywbem/_version.py |sed -r 's/__version__ *= *\x27(.*)\x27.*/\1/'")
# Normalized package version (as normalized by setup.py during building)
package_version := $(shell sh -c "echo $(package_specified_version) |sed 's/[.-]\?\(rc[0-9]\+\)$$/\1/' |sed 's/[.]\?dev[0-9]\*$$/\.dev0/'")
# Final version of this package (M.N.U)
package_final_version := $(shell sh -c "echo $(package_version) |sed 's/rc[0-9]\+$$//' |sed 's/\.dev0$$//'")
# Python versions
python_version := $(shell python -c "import sys; sys.stdout.write('%s.%s.%s'%sys.version_info[0:3])")
python_mn_version := $(shell python -c "import sys; sys.stdout.write('%s%s'%sys.version_info[0:2])")
# Directory for the generated distribution files
dist_dir := dist
# Distribution archives
bdist_file := $(dist_dir)/$(package_name)-$(package_version)-py2.py3-none-any.whl
sdist_file := $(dist_dir)/$(package_name)-$(package_version).tar.gz
dist_files := $(bdist_file) $(sdist_file)
# Lex/Yacc table files, generated from and by mof_compiler.py
moftab_files := $(package_name)/mofparsetab.py $(package_name)/moflextab.py
# Dependents for Lex/Yacc table files
moftab_dependent_files := \
$(package_name)/mof_compiler.py \
# Directory for generated API documentation
doc_build_dir := build_doc
# Directory where Sphinx conf.py is located
doc_conf_dir := docs
# Paper format for the Sphinx LaTex/PDF builder.
# Valid values: a4, letter
doc_paper_format := a4
# Documentation generator command
doc_cmd := sphinx-build
doc_opts := -v -d $(doc_build_dir)/doctrees -c $(doc_conf_dir) -D latex_paper_size=$(doc_paper_format) .
# File names of automatically generated utility help message text output
doc_utility_help_files := \
$(doc_conf_dir)/wbemcli.help.txt \
$(doc_conf_dir)/mof_compiler.help.txt \
# Dependents for Sphinx documentation build
doc_dependent_files := \
$(doc_conf_dir)/conf.py \
$(wildcard $(doc_conf_dir)/*.rst) \
$(wildcard $(doc_conf_dir)/notebooks/*.ipynb) \
$(package_name)/__init__.py \
$(package_name)/cim_constants.py \
$(package_name)/cim_obj.py \
$(package_name)/cim_operations.py \
$(package_name)/cim_types.py \
$(package_name)/cim_http.py \
$(package_name)/mof_compiler.py \
$(package_name)/exceptions.py \
$(package_name)/_listener.py \
$(package_name)/_subscription_manager.py \
$(package_name)/_recorder.py \
$(package_name)/_server.py \
$(package_name)/config.py \
wbemcli.py \
# PyLint config file
pylint_rc_file := pylintrc
# Flake8 config file
flake8_rc_file := .flake8
# Python source files to be checked by PyLint and Flake8
py_src_files := \
setup.py \
os_setup.py \
$(filter-out $(moftab_files), $(wildcard $(package_name)/*.py)) \
$(wildcard testsuite/*.py) \
wbemcli \
wbemcli.py \
mof_compiler \
# Test log
test_log_file := test_$(python_mn_version).log
test_tmp_file := test_$(python_mn_version).tmp.log
# Files to be put into distribution archive.
# Keep in sync with dist_dependent_files.
# This is used for 'include' statements in MANIFEST.in. The wildcards are used
# as specified, without being expanded.
dist_manifest_in_files := \
$(package_name)/LICENSE.txt \
README.md \
INSTALL.md \
*.py \
$(package_name)/*.py \
# Files that are dependents of the distribution archive.
# Keep in sync with dist_manifest_in_files.
dist_dependent_files := \
$(package_name)/LICENSE.txt \
README.md \
INSTALL.md \
$(wildcard *.py) \
$(wildcard $(package_name)/*.py) \
# No built-in rules needed:
.SUFFIXES:
.PHONY: help
help:
@echo 'makefile for $(package_name)'
@echo 'Package version will be: $(package_version)'
@echo 'Uses the currently active Python environment: Python $(python_version)'
@echo 'Valid targets are (they do just what is stated, i.e. no automatic prereq targets):'
@echo ' develop - Prepare the development environment by installing prerequisites'
@echo ' build - Build the distribution files in: $(dist_dir)'
@echo ' builddoc - Build documentation in: $(doc_build_dir)'
@echo ' check - Run PyLint&Flake8 on sources and save results in: pylint.log&flake8.log'
@echo ' test - Run unit tests and save results in: $(test_log_file)'
@echo ' all - Do all of the above'
@echo ' install - Install distribution archive to active Python environment'
@echo ' upload - build + upload the distribution files to PyPI'
@echo ' clean - Remove any temporary files'
@echo ' clobber - Remove everything; ensure clean start like a fresh clone'
.PHONY: develop
develop:
python setup.py develop_os
python setup.py develop
@echo '$@ done.'
.PHONY: build
build: $(bdist_file) $(sdist_file)
@echo '$@ done.'
.PHONY: builddoc
builddoc: html
@echo '$@ done.'
.PHONY: html
html: $(doc_build_dir)/html/docs/index.html
@echo '$@ done.'
$(doc_build_dir)/html/docs/index.html: makefile $(doc_utility_help_files) $(doc_dependent_files)
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
rm -f $@
PYTHONPATH=. $(doc_cmd) -b html $(doc_opts) $(doc_build_dir)/html
@echo "Done: Created the HTML pages with top level file: $@"
endif
.PHONY: pdf
pdf: makefile $(doc_utility_help_files) $(doc_dependent_files)
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
rm -f $@
$(doc_cmd) -b latex $(doc_opts) $(doc_build_dir)/pdf
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(doc_build_dir)/pdf all-pdf
@echo "Done: Created the PDF files in: $(doc_build_dir)/pdf/"
@echo '$@ done.'
endif
.PHONY: man
man: makefile $(doc_utility_help_files) $(doc_dependent_files)
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
rm -f $@
$(doc_cmd) -b man $(doc_opts) $(doc_build_dir)/man
@echo "Done: Created the manual pages in: $(doc_build_dir)/man/"
@echo '$@ done.'
endif
.PHONY: docchanges
docchanges:
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
$(doc_cmd) -b changes $(doc_opts) $(doc_build_dir)/changes
@echo
@echo "Done: Created the doc changes overview file in: $(doc_build_dir)/changes/"
@echo '$@ done.'
endif
.PHONY: doclinkcheck
doclinkcheck:
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
$(doc_cmd) -b linkcheck $(doc_opts) $(doc_build_dir)/linkcheck
@echo
@echo "Done: Look for any errors in the above output or in: $(doc_build_dir)/linkcheck/output.txt"
@echo '$@ done.'
endif
.PHONY: doccoverage
doccoverage:
ifeq ($(python_mn_version),26)
@echo 'Info: Sphinx requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
$(doc_cmd) -b coverage $(doc_opts) $(doc_build_dir)/coverage
@echo "Done: Created the doc coverage results in: $(doc_build_dir)/coverage/python.txt"
@echo '$@ done.'
endif
.PHONY: check
check: pylint.log flake8.log
@echo '$@ done.'
.PHONY: flake8
flake8: flake8.log
@echo '$@ done.'
.PHONY: install
install: $(sdist_file)
mkdir tmp_install
tar -x -C tmp_install -f $(sdist_file)
sh -c "cd tmp_install/$(package_name)-$(package_version) && python setup.py install_os && python setup.py install"
rm -Rf tmp_install
@echo 'Done: Installed pywbem into current Python environment.'
@echo '$@ done.'
.PHONY: test
test: $(test_log_file)
@echo '$@ done.'
.PHONY: clobber
clobber: clean
rm -f pylint.log flake8.log epydoc.log test_*.log $(moftab_files) $(dist_files)
rm -Rf $(doc_build_dir) .tox
@echo 'Done: Removed everything to get to a fresh state.'
@echo '$@ done.'
# Also remove any build products that are dependent on the Python version
.PHONY: clean
clean:
find . -name "*.pyc" -delete
sh -c "find . -name \"__pycache__\" |xargs -r rm -Rf"
sh -c "ls -d tmp_* |xargs -r rm -Rf"
rm -f MANIFEST parser.out .coverage $(package_name)/parser.out $(test_tmp_file)
rm -Rf build tmp_install testtmp testsuite/testtmp .cache $(package_name).egg-info .eggs
@echo 'Done: Cleaned out all temporary files.'
@echo '$@ done.'
.PHONY: all
all: develop check build builddoc test
@echo '$@ done.'
.PHONY: upload
upload: $(dist_files)
twine upload $(dist_files)
@echo 'Done: Uploaded pywbem version to PyPI: $(package_version)'
@echo '$@ done.'
# Note: distutils depends on the right files specified in MANIFEST.in, even when
# they are already specified e.g. in 'package_data' in setup.py.
# We generate the MANIFEST.in file automatically, to have a single point of
# control (this makefile) for what gets into the distribution archive.
MANIFEST.in: makefile
echo '# file GENERATED by makefile, do NOT edit' >$@
echo '$(dist_manifest_in_files)' | xargs -r -n 1 echo include >>$@
@echo 'Done: Created manifest input file: $@'
# Distribution archives.
# Note: Deleting MANIFEST causes distutils (setup.py) to read MANIFEST.in and to
# regenerate MANIFEST. Otherwise, changes in MANIFEST.in will not be used.
$(bdist_file) $(sdist_file): setup.py MANIFEST.in $(dist_dependent_files) $(moftab_files)
rm -rf MANIFEST $(package_name).egg-info .eggs
python setup.py sdist -d $(dist_dir) bdist_wheel -d $(dist_dir) --universal
@echo 'Done: Created distribution files: $@'
# Note: The mof*tab files need to be removed in order to rebuild them (make rules vs. ply rules)
$(moftab_files): $(moftab_dependent_files) build_moftab.py
rm -f $(package_name)/mofparsetab.py* $(package_name)/moflextab.py*
python -c "from pywbem import mof_compiler; mof_compiler._build(verbose=True)"
@echo 'Done: Created LEX/YACC table modules: $@'
# TODO: Once pylint has no more errors, remove the dash "-"
# PyLint status codes:
# * 0 if everything went fine
# * 1 if fatal messages issued
# * 2 if error messages issued
# * 4 if warning messages issued
# * 8 if refactor messages issued
# * 16 if convention messages issued
# * 32 on usage error
# Status 1 to 16 will be bit-ORed.
# The make command checks for statuses: 1,2,32
pylint.log: makefile $(pylint_rc_file) $(py_src_files)
ifeq ($(python_mn_version),27)
rm -f pylint.log
pylint --version
-bash -c 'set -o pipefail; PYTHONPATH=. pylint --rcfile=$(pylint_rc_file) --output-format=text $(py_src_files) 2>&1 |tee pylint.tmp.log; rc=$$?; if (($$rc >= 32 || $$rc & 0x03)); then exit $$rc; fi'
mv -f pylint.tmp.log pylint.log
@echo 'Done: Created Pylint log file: $@'
else
@echo 'Info: Pylint requires Python 2.7; skipping this step on Python $(python_version)'
endif
flake8.log: makefile $(flake8_rc_file) $(py_src_files)
ifeq ($(python_mn_version),26)
@echo 'Info: Flake8 requires Python 2.7 or Python 3; skipping this step on Python $(python_version)'
else
rm -f flake8.log
flake8 --version
bash -c "set -o pipefail; PYTHONPATH=. flake8 --statistics --config=$(flake8_rc_file) --filename="*" $(py_src_files) 2>&1 |tee flake8.tmp.log"
mv -f flake8.tmp.log flake8.log
@echo 'Done: Created flake8 log file: $@'
endif
$(test_log_file): makefile $(package_name)/*.py testsuite/*.py coveragerc
rm -f $(test_log_file)
bash -c "set -o pipefail; PYTHONWARNINGS=default PYTHONPATH=. py.test --cov $(package_name) --cov-config coveragerc --ignore=attic --ignore=releases --ignore=testsuite/testclient -s 2>&1 |tee $(test_tmp_file)"
mv -f $(test_tmp_file) $(test_log_file)
@echo 'Done: Created test log file: $@'
$(doc_conf_dir)/wbemcli.help.txt: wbemcli
./wbemcli --help >$@
@echo 'Done: Created wbemcli script help message file: $@'
$(doc_conf_dir)/mof_compiler.help.txt: mof_compiler $(package_name)/mof_compiler.py
./mof_compiler --help >$@
@echo 'Done: Created mof_compiler script help message file: $@'