Merge pull request #1212 from davvid/dev
[git-cola.git] / Makefile
blobfd705dc30b0cf75862a6834eabde0d63e01b2fa8
1 # The default target of this Makefile is...
2 all::
4 # Development
5 # -----------
6 # make develop # python setup.py develop ~ one-time virtualenv development setup
7 # make V=1 # generate files; V=1 increases verbosity
8 # make test [flags=...] # run tests; flags=-x fails fast, --ff failed first
9 # make test V=2 # V=2 increases test verbosity
10 # make doc # build docs
11 # make flake8 # python style checks
12 # make pylint [color=1] # run pylint; color=1 colorizes output
13 # make pylint3k [color=1] # run python2+3 compatibility checks
14 # make format # run the black python formatter
15 # make check [color=1] # run test, doc, flake8, pylint3k, and pylint
16 # make check file=<filename> # run checks on <filename>
18 # Release Prep
19 # ------------
20 # make pot # update main translation template
21 # make po # merge translations
22 # make mo # generate message files
23 # make i18n # all three of the above
25 # Installation
26 # ------------
27 # make prefix=<path> install
28 # DESTDIR is also supported.
30 # To disable distutil's replacement of "#!/usr/bin/env python" with
31 # the path to the build environment's python, pass USE_ENV_PYTHON=1
32 # when invoking make.
34 # The external commands used by this Makefile are...
35 BLACK = black
36 CTAGS = ctags
37 CP = cp
38 FIND = find
39 FLAKE8 = flake8
40 GREP = grep
41 GIT = git
42 GZIP = gzip
43 LN = ln
44 LN_S = $(LN) -s -f
45 MARKDOWN = markdown
46 MKDIR_P = mkdir -p
47 PIP = pip
48 PYTHON ?= python
49 PYLINT = $(PYTHON) -B -m pylint
50 PYTEST = $(PYTHON) -B -m pytest
51 RM = rm -f
52 RM_R = rm -fr
53 RMDIR = rmdir
54 TAR = tar
55 TOX = tox
56 XARGS = xargs
58 # Flags
59 # -----
60 ifdef V
61 VERBOSE = --verbose
62 ifeq ($(V),2)
63 TEST_VERBOSE = --verbose
64 VERBOSE_SHORT = -vv
65 else
66 VERBOSE_SHORT = -v
67 endif
68 else
69 QUIET = --quiet
70 endif
72 FLAKE8_FLAGS = $(VERBOSE)
74 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
75 uname_S := $(shell uname -s)
76 ifneq ($(uname_S),Linux)
77 PYTEST_FLAGS += --ignore=cola/inotify.py
78 endif
80 TOX_FLAGS = $(VERBOSE_SHORT) --develop --skip-missing-interpreters
81 TOX_ENVS ?= py{27,36,37,38,39,lint}
83 PYLINT_SCORE_FLAG := $(shell $(PYLINT) --score=no --help >/dev/null 2>&1 && echo " --score=no" || true)
84 PYLINT_FLAGS = --rcfile=.pylintrc
85 ifdef color
86 PYLINT_FLAGS += --output-format=colorized
87 endif
88 ifneq ($(PYLINT_SCORE_FLAGSCORE),)
89 PYLINT_FLAGS += $(PYLINT_SCORE_FLAG)
90 endif
92 # These values can be overridden on the command-line or via config.mak
93 prefix = $(HOME)
94 bindir = $(prefix)/bin
95 python_version := $(shell $(PYTHON) -c 'import sys; print("%s.%s" % sys.version_info[:2])')
96 python_lib = python$(python_version)/site-packages
97 pythondir = $(prefix)/lib/$(python_lib)
98 # DESTDIR =
100 cola_base := git-cola
101 cola_app_base= $(cola_base).app
102 cola_app = $(CURDIR)/$(cola_app_base)
104 # Read $(VERSION) from cola/_version.py and strip quotes.
105 include cola/_version.py
106 cola_version := $(subst ',,$(VERSION))
107 cola_dist := $(cola_base)-$(cola_version)
109 SETUP ?= $(PYTHON) setup.py
111 build_args += build
113 install_args += install
114 ifdef DESTDIR
115 install_args += --root="$(DESTDIR)"
116 export DESTDIR
117 endif
118 install_args += --prefix="$(prefix)"
119 install_args += --install-scripts="$(bindir)"
120 install_args += --single-version-externally-managed
121 install_args += --record=build/MANIFEST
122 export prefix
124 PYTHON_DIRS = cola
125 PYTHON_DIRS += test
127 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
128 ALL_PYTHON_DIRS += extras
130 # User customizations
131 -include config.mak
133 .PHONY: all
134 all:: build
136 .PHONY: build
137 build::
138 $(SETUP) $(QUIET) $(VERBOSE) $(build_args)
140 .PHONY: install
141 install:: all
142 $(SETUP) $(QUIET) $(VERBOSE) $(install_args)
144 .PHONY: doc
145 doc::
146 $(MAKE) -C share/doc/git-cola all
148 .PHONY: html
149 html::
150 $(MAKE) -C share/doc/git-cola html
152 .PHONY: man
153 man::
154 $(MAKE) -C share/doc/git-cola man
156 .PHONY: install-doc
157 install-doc::
158 $(MAKE) -C share/doc/git-cola install
160 .PHONY: install-html
161 install-html::
162 $(MAKE) -C share/doc/git-cola install-html
164 .PHONY: install-man
165 install-man::
166 $(MAKE) -C share/doc/git-cola install-man
168 .PHONY: uninstall
169 uninstall::
170 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
171 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
172 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
173 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
174 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
175 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
176 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
177 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
178 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
179 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
180 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
181 $(RM_R) "$(DESTDIR)$(prefix)"/share/git-cola
182 $(RM) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES/git-cola.mo
183 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
184 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
185 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
186 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
187 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
188 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
189 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES 2>/dev/null || true
190 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/* 2>/dev/null || true
191 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale 2>/dev/null || true
192 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
193 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
194 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
195 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
196 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
197 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
198 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
200 .PHONY: test
201 test:: all
202 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
204 .PHONY: coverage
205 coverage::
206 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
208 .PHONY: clean
209 clean::
210 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
211 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
212 $(RM_R) build dist tags git-cola.app
213 $(RM_R) share/locale
214 $(MAKE) -C share/doc/git-cola clean
216 # Update i18n files
217 .PHONY: i18n
218 i18n:: pot
219 i18n:: po
220 i18n:: mo
222 .PHONY: pot
223 pot::
224 $(SETUP) build_pot --build-dir=po --no-lang
226 .PHONY: po
227 po::
228 $(SETUP) build_pot --build-dir=po
230 .PHONY: mo
231 mo::
232 $(SETUP) build_mo --force
234 .PHONY: git-cola.app
235 git-cola.app::
236 $(MKDIR_P) $(cola_app)/Contents/MacOS
237 $(MKDIR_P) $(cola_app)/Contents/Resources
238 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo \
239 $(cola_app)/Contents
240 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
241 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
242 $(MAKE) prefix=$(cola_app)/Contents/Resources install install-doc
244 .PHONY: app-tarball
245 app-tarball:: git-cola.app
246 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
248 # Preview the markdown using "make README.html"
249 %.html: %.md
250 $(MARKDOWN) $< >$@
252 .PHONY: flake8
253 flake8::
254 $(FLAKE8) --version
255 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) \
256 $(ALL_PYTHON_DIRS) contrib
258 .PHONY: pylint3k
259 pylint3k::
260 $(PYLINT) --version
261 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) \
262 $(ALL_PYTHON_DIRS)
264 .PHONY: pylint
265 pylint::
266 $(PYLINT) --version
267 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
268 $(ALL_PYTHON_DIRS)
270 # Pre-commit checks
271 .PHONY: check
272 ifdef file
273 check::
274 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) $(file)
275 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized $(flags) $(file)
276 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized --py3k $(flags) $(file)
277 else
278 # NOTE: flake8 is not part of "make check" because the pytest-flake8 plugin runs flake8
279 # checks during "make test" via pytest.
280 check:: all
281 check:: test
282 check:: doc
283 check:: pylint3k
284 check:: pylint
285 endif
287 .PHONY: format
288 format::
289 $(GIT) ls-files -- '*.py' | \
290 $(GREP) -v ^qtpy | \
291 $(XARGS) $(BLACK) --skip-string-normalization
293 # Run "make develop" from inside a newly created virtualenv to setup the build system
294 # using "python setup.py develop".
295 .PHONY: develop
296 develop::
297 $(SETUP) develop
299 .PHONY: requirements
300 requirements::
301 $(PIP) install --requirement requirements/requirements.txt
303 .PHONY: requirements-dev
304 requirements-dev::
305 $(PIP) install --requirement requirements/requirements-dev.txt
307 .PHONY: requirements-optional
308 requirements-optional::
309 $(PIP) install --requirement requirements/requirements-optional.txt
311 .PHONY: tox
312 tox::
313 $(TOX) $(TOX_FLAGS) $(flags)
315 .PHONY: tox-check
316 tox-check::
317 $(TOX) $(TOX_FLAGS) --parallel auto -e "$(TOX_ENVS)" $(flags)