Makefile: organize pylint/flake8 flags
[git-cola.git] / Makefile
blob06b99926a292287098cd03eeaac2faf565076d30
1 # The default target of this Makefile is...
2 all::
4 # Development
5 # -----------
6 # make test # unit tests
7 # make doc # build docs
8 # make flake8 # style check
9 # make pyint3k # python2/3 compatibility checks
10 # make pylint # full pylint check
11 # # TODO pylint config, tox, yapf, others?
12 # Release Prep
13 # ------------
14 # make pot # update main translation template
15 # make po # merge translations
17 # Installation
18 # ------------
19 # make prefix=<path> install
20 # DESTDIR is also supported.
22 # To disable distutil's replacement of "#!/usr/bin/env python" with
23 # the path to the build environment's python, pass USE_ENV_PYTHON=1
24 # when invoking make.
26 # The external commands used by this Makefile are...
27 CTAGS = ctags
28 CP = cp
29 FIND = find
30 FLAKE8 = flake8
31 GIT = git
32 GZIP = gzip
33 LN = ln
34 LN_S = $(LN) -s -f
35 MARKDOWN = markdown
36 MKDIR_P = mkdir -p
37 PIP = pip
38 PYLINT = pylint
39 PYTHON = python
40 PYTEST ?= $(PYTHON) -m pytest
41 RM = rm -f
42 RM_R = rm -fr
43 RMDIR = rmdir
44 TAR = tar
45 YAPF = yapf
47 # Flags
48 # -----
49 # "make V=1" increases verbosity
50 # "make test V=2" increases test verbosity
51 # "make pylint color=1" enables colorized pylint output
52 # "make test flags={-x,--exitfirst}" exits on the first test failure
53 ifdef V
54 VERBOSE = --verbose
55 ifeq ($(V),2)
56 TEST_VERBOSE = --verbose
57 endif
58 else
59 QUIET = --quiet
60 endif
62 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
63 PYTEST_FLAGS += --doctest-modules
65 FLAKE8_FLAGS = $(VERBOSE)
66 FLAKE8_FLAGS += --max-line-length=80
67 FLAKE8_FLAGS += --format=pylint
68 FLAKE8_FLAGS += --doctests
69 FLAKE8_FLAGS += --statistics
71 PYLINT_FLAGS = --rcfile=.pylintrc
72 ifdef color
73 PYLINT_FLAGS += --output-format=colorized
74 endif
76 # These values can be overridden on the command-line or via config.mak
77 prefix = $(HOME)
78 bindir = $(prefix)/bin
79 datadir = $(prefix)/share/git-cola
80 coladir = $(datadir)/lib
81 hicolordir = $(prefix)/share/icons/hicolor/scalable/apps
82 # DESTDIR =
84 cola_base := git-cola
85 cola_app_base= $(cola_base).app
86 cola_app = $(CURDIR)/$(cola_app_base)
87 cola_version = $(shell $(PYTHON) bin/git-cola version --brief)
88 cola_dist := $(cola_base)-$(cola_version)
90 SETUP ?= $(PYTHON) setup.py
92 build_args += build
93 ifdef USE_ENV_PYTHON
94 build_args += --use-env-python
95 endif
97 install_args += install
98 install_args += --prefix="$(prefix)"
99 install_args += --force
100 install_args += --install-scripts="$(bindir)"
101 install_args += --record=build/MANIFEST
102 install_args += --install-lib="$(coladir)"
103 ifdef DESTDIR
104 install_args += --root="$(DESTDIR)"
105 export DESTDIR
106 endif
107 export prefix
109 # If NO_VENDOR_LIBS is specified on the command line then pass it to setup.py
110 ifdef NO_VENDOR_LIBS
111 install_args += --no-vendor-libs
112 endif
114 PYTHON_DIRS = cola
115 PYTHON_DIRS += test
117 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
118 ALL_PYTHON_DIRS += extras
120 PYTHON_SOURCES = bin/git-cola
121 PYTHON_SOURCES += bin/git-dag
122 PYTHON_SOURCES += share/git-cola/bin/git-xbase
123 PYTHON_SOURCES += setup.py
125 # User customizations
126 -include config.mak
128 all:: build
129 .PHONY: all
131 build_version:
132 @GIT=$(GIT) ./extras/generate-build-version.sh 2>/dev/null || true
133 .PHONY: build_version
135 build: build_version
136 $(SETUP) $(QUIET) $(VERBOSE) $(build_args)
137 .PHONY: build
139 install: all
140 $(SETUP) $(QUIET) $(VERBOSE) $(install_args)
141 $(MKDIR_P) "$(DESTDIR)$(hicolordir)"
142 $(LN_S) "$(datadir)/icons/git-cola.svg" \
143 "$(DESTDIR)$(hicolordir)/git-cola.svg"
144 $(LN_S) git-cola "$(DESTDIR)$(bindir)/cola"
145 $(RM_R) "$(DESTDIR)$(coladir)/git_cola"*
146 $(RM_R) git_cola.egg-info
148 # Maintainer's dist target
149 dist:
150 $(GIT) archive --format=tar --prefix=$(cola_dist)/ HEAD^{tree} | \
151 $(GZIP) -f -9 - >$(cola_dist).tar.gz
153 doc:
154 $(MAKE) -C share/doc/git-cola all
156 html:
157 $(MAKE) -C share/doc/git-cola html
159 man:
160 $(MAKE) -C share/doc/git-cola man
162 install-doc:
163 $(MAKE) -C share/doc/git-cola install
165 install-html:
166 $(MAKE) -C share/doc/git-cola install-html
168 install-man:
169 $(MAKE) -C share/doc/git-cola install-man
171 uninstall:
172 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
173 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
174 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
175 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
176 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
177 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
178 $(RM) "$(DESTDIR)$(prefix)"/share/appdata/git-dag.appdata.xml
179 $(RM) "$(DESTDIR)$(prefix)"/share/appdata/git-cola.appdata.xml
180 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
181 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
182 $(RM_R) "$(DESTDIR)$(prefix)"/share/git-cola
183 $(RM) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES/git-cola.mo
184 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null
185 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/appdata 2>/dev/null
186 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null
187 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES 2>/dev/null
188 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/* 2>/dev/null
189 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/locale 2>/dev/null
190 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null
191 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null
192 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null
193 -$(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null
194 -$(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null
195 -$(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null
196 -$(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null
198 test: all
199 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
201 coverage:
202 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
204 clean:
205 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | xargs -0 rm -f
206 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | xargs -0 rm -rf
207 $(RM_R) build dist tags git-cola.app
208 $(RM_R) share/locale
209 $(MAKE) -C share/doc/git-cola clean
211 tags:
212 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py' -print0 | xargs -0 $(CTAGS) -f tags
214 # Update i18n files
215 i18n:: pot
216 i18n:: po
217 i18n:: mo
219 pot:
220 $(SETUP) build_pot --build-dir=po --no-lang
221 .PHONY: pot
224 $(SETUP) build_pot --build-dir=po
225 .PHONY: po
228 $(SETUP) build_mo --force
229 .PHONY: mo
231 git-cola.app:
232 $(MKDIR_P) $(cola_app)/Contents/MacOS
233 $(MKDIR_P) $(cola_app)/Contents/Resources
234 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo \
235 $(cola_app)/Contents
236 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
237 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
238 $(MAKE) prefix=$(cola_app)/Contents/Resources install install-doc
239 .PHONY: git-cola.app
241 app-tarball: git-cola.app
242 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
244 # Preview the markdown using "make README.html"
245 %.html: %.md
246 $(MARKDOWN) $< >$@
248 flake8:
249 $(FLAKE8) $(FLAKE8_FLAGS) $(PYTHON_SOURCES) $(PYTHON_DIRS)
251 pylint3k:
252 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) \
253 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
255 pylint:
256 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
257 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
259 check:
260 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) $(file)
261 $(PYLINT) $(PYLINT_FLAGS) $(flags) $(file)
262 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) $(file)
264 format:
265 $(YAPF) --in-place $(flags) $(file)
267 requirements:
268 $(PIP) install --requirement requirements/requirements.txt
270 requirements-dev:
271 $(PIP) install --requirement requirements/requirements-dev.txt