qtutils: simplify the BlockSignals implementation
[git-cola.git] / Makefile
blob5d2dc2ac75744e9be18098f250b4726779ab14f2
1 # The default target of this Makefile is...
2 all::
4 # Development
5 # -----------
6 # make V=1 # generate files; V=1 increases verbosity
7 # make test [flags=...] # run tests; flags=-x fails fast
8 # make test V=2 # V=2 increases test verbosity
9 # make doc # build docs
10 # make flake8 # python style checks
11 # make pylint [color=1] # run pylint; color=1 colorizes output
12 # make pylint3k [color=1] # run python2+3 compatibility checks
13 # make format # run the black python formatter
14 # make check [color=1] # run test, doc, flake8, pylint3k, and pylint
15 # make check file=<filename> # run checks on <filename>
17 # Release Prep
18 # ------------
19 # make pot # update main translation template
20 # make po # merge translations
21 # make mo # generate message files
22 # make i18n # all three of the above
24 # Installation
25 # ------------
26 # make prefix=<path> install
27 # DESTDIR is also supported.
29 # To disable distutil's replacement of "#!/usr/bin/env python" with
30 # the path to the build environment's python, pass USE_ENV_PYTHON=1
31 # when invoking make.
33 # The external commands used by this Makefile are...
34 BLACK = black
35 CTAGS = ctags
36 CP = cp
37 FIND = find
38 FLAKE8 = flake8
39 GREP = grep
40 GIT = git
41 GZIP = gzip
42 LN = ln
43 LN_S = $(LN) -s -f
44 MARKDOWN = markdown
45 MKDIR_P = mkdir -p
46 PIP = pip
47 PYLINT = pylint
48 PYTHON ?= python
49 PYTEST = $(PYTHON) -B -m pytest
50 RM = rm -f
51 RM_R = rm -fr
52 RMDIR = rmdir
53 TAR = tar
54 TOX = tox
55 XARGS = xargs
57 # Flags
58 # -----
59 ifdef V
60 VERBOSE = --verbose
61 ifeq ($(V),2)
62 TEST_VERBOSE = --verbose
63 VERBOSE_SHORT = -vv
64 else
65 VERBOSE_SHORT = -v
66 endif
67 else
68 QUIET = --quiet
69 endif
71 FLAKE8_FLAGS = $(VERBOSE)
73 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
74 uname_S := $(shell uname -s)
75 ifneq ($(uname_S),Linux)
76 PYTEST_FLAGS += --ignore=cola/inotify.py
77 endif
79 TOX_FLAGS = $(VERBOSE_SHORT) --develop --skip-missing-interpreters
80 TOX_ENVS ?= py{27,36,37,38,39,lint}
82 PYLINT_FLAGS = --rcfile=.pylintrc
83 PYLINT_FLAGS += --score=no
84 ifdef color
85 PYLINT_FLAGS += --output-format=colorized
86 endif
89 # These values can be overridden on the command-line or via config.mak
90 prefix = $(HOME)
91 bindir = $(prefix)/bin
92 datadir = $(prefix)/share/git-cola
93 python_lib := $(shell $(PYTHON) -c \
94 'import distutils.sysconfig as sc; print(sc.get_python_lib(prefix=""))')
95 pythondir = $(prefix)/$(python_lib)
96 hicolordir = $(prefix)/share/icons/hicolor/scalable/apps
97 # DESTDIR =
99 cola_base := git-cola
100 cola_app_base= $(cola_base).app
101 cola_app = $(CURDIR)/$(cola_app_base)
103 # Read $(VERSION) from cola/_version.py and strip quotes.
104 include cola/_version.py
105 cola_version := $(subst ',,$(VERSION))
106 cola_dist := $(cola_base)-$(cola_version)
108 SETUP ?= $(PYTHON) setup.py
110 build_args += build
111 ifdef USE_ENV_PYTHON
112 build_args += --use-env-python
113 endif
115 install_args += install
116 install_args += --prefix="$(prefix)"
117 install_args += --force
118 install_args += --install-scripts="$(bindir)"
119 install_args += --record=build/MANIFEST
120 ifdef DESTDIR
121 install_args += --root="$(DESTDIR)"
122 export DESTDIR
123 endif
124 export prefix
126 ifdef NO_PRIVATE_LIBS
127 install_args += --no-private-libs
128 endif
129 ifdef NO_VENDOR_LIBS
130 install_args += --no-vendor-libs
131 endif
133 PYTHON_DIRS = cola
134 PYTHON_DIRS += test
136 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
137 ALL_PYTHON_DIRS += extras
139 PYTHON_SOURCES = bin/git-cola
140 PYTHON_SOURCES += bin/git-cola-sequence-editor
141 PYTHON_SOURCES += bin/git-dag
142 PYTHON_SOURCES += setup.py
144 # User customizations
145 -include config.mak
147 .PHONY: all
148 all:: build
150 .PHONY: build_version
151 build_version:
152 @GIT=$(GIT) ./extras/generate-build-version.sh 2>/dev/null || true
154 .PHONY: build
155 build: build_version
156 $(SETUP) $(QUIET) $(VERBOSE) $(build_args)
158 .PHONY: install
159 install: all
160 $(SETUP) $(QUIET) $(VERBOSE) $(install_args)
161 $(MKDIR_P) "$(DESTDIR)$(hicolordir)"
162 $(LN_S) "$(datadir)/icons/git-cola.svg" \
163 "$(DESTDIR)$(hicolordir)/git-cola.svg"
164 $(LN_S) git-cola "$(DESTDIR)$(bindir)/cola"
166 .PHONY: doc
167 doc:
168 $(MAKE) -C share/doc/git-cola all
170 .PHONY: html
171 html:
172 $(MAKE) -C share/doc/git-cola html
174 .PHONY: man
175 man:
176 $(MAKE) -C share/doc/git-cola man
178 .PHONY: install-doc
179 install-doc:
180 $(MAKE) -C share/doc/git-cola install
182 .PHONY: install-html
183 install-html:
184 $(MAKE) -C share/doc/git-cola install-html
186 .PHONY: install-man
187 install-man:
188 $(MAKE) -C share/doc/git-cola install-man
190 .PHONY: uninstall
191 uninstall:
192 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
193 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
194 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
195 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
196 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
197 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
198 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
199 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
200 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
201 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
202 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
203 $(RM_R) "$(DESTDIR)$(prefix)"/share/git-cola
204 $(RM) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES/git-cola.mo
205 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
206 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
207 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
208 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
209 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
210 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
211 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES 2>/dev/null || true
212 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/* 2>/dev/null || true
213 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale 2>/dev/null || true
214 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
215 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
216 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
217 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
218 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
219 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
220 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
222 .PHONY: test
223 test: all
224 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
226 .PHONY: coverage
227 coverage:
228 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
230 .PHONY: clean
231 clean:
232 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
233 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
234 $(RM_R) build dist tags git-cola.app
235 $(RM_R) share/locale
236 $(MAKE) -C share/doc/git-cola clean
238 .PHONY: tags
239 tags:
240 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py' -print0 | $($XARGS) -0 $(CTAGS) -f tags
242 # Update i18n files
243 .PHONY: i18n
244 i18n:: pot
245 i18n:: po
246 i18n:: mo
248 .PHONY: pot
249 pot:
250 $(SETUP) build_pot --build-dir=po --no-lang
252 .PHONY: po
254 $(SETUP) build_pot --build-dir=po
256 .PHONY: mo
258 $(SETUP) build_mo --force
260 .PHONY: git-cola.app
261 git-cola.app:
262 $(MKDIR_P) $(cola_app)/Contents/MacOS
263 $(MKDIR_P) $(cola_app)/Contents/Resources
264 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo \
265 $(cola_app)/Contents
266 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
267 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
268 $(MAKE) prefix=$(cola_app)/Contents/Resources install install-doc
270 .PHONY: app-tarball
271 app-tarball: git-cola.app
272 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
274 # Preview the markdown using "make README.html"
275 %.html: %.md
276 $(MARKDOWN) $< >$@
278 .PHONY: flake8
279 flake8:
280 $(FLAKE8) --version
281 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) \
282 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS) contrib
284 .PHONY: pylint3k
285 pylint3k:
286 $(PYLINT) --version
287 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) \
288 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
290 .PHONY: pylint
291 pylint:
292 $(PYLINT) --version
293 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
294 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
296 # Pre-commit checks
297 .PHONY: check
298 ifdef file
299 check:
300 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) $(file)
301 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized $(flags) $(file)
302 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized --py3k $(flags) $(file)
303 else
304 check:: all
305 check:: test
306 check:: doc
307 check:: flake8
308 check:: pylint3k
309 check:: pylint
310 endif
312 .PHONY: format
313 format:
314 $(GIT) ls-files -- '*.py' | \
315 $(GREP) -v ^qtpy | \
316 $(XARGS) $(BLACK) --skip-string-normalization --target-version=py27
317 $(BLACK) --skip-string-normalization --target-version=py27 $(PYTHON_SOURCES)
319 .PHONY: requirements
320 requirements:
321 $(PIP) install --requirement requirements/requirements.txt
323 .PHONY: requirements-dev
324 requirements-dev:
325 $(PIP) install --requirement requirements/requirements-dev.txt
327 .PHONY: tox
328 tox:
329 $(TOX) $(TOX_FLAGS) $(flags)
331 .PHONY: tox-check
332 tox-check:
333 $(TOX) $(TOX_FLAGS) --parallel auto -e "$(TOX_ENVS)" $(flags)