github/workflows: update dependencies and enable python-is-python3
[git-cola.git] / Makefile
blobcd5380c5169aa8dc387b34fcaa77ef466c66e1c2
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, --ff failed first
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 PYTHON ?= python
48 PYLINT = $(PYTHON) -B -m pylint
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_SCORE_FLAG := $(shell $(PYLINT) --score=no --help >/dev/null 2>&1 && echo " --score=no" || true)
83 PYLINT_FLAGS = --rcfile=.pylintrc
84 ifdef color
85 PYLINT_FLAGS += --output-format=colorized
86 endif
87 ifneq ($(PYLINT_SCORE_FLAGSCORE),)
88 PYLINT_FLAGS += $(PYLINT_SCORE_FLAG)
89 endif
91 # These values can be overridden on the command-line or via config.mak
92 prefix = $(HOME)
93 bindir = $(prefix)/bin
94 python_code := "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
95 python_version := $(shell $(PYTHON) -c $(python_code))
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
112 ifdef USE_ENV_PYTHON
113 build_args += --use-env-python
114 endif
116 install_args += install
117 ifdef DESTDIR
118 install_args += --root="$(DESTDIR)"
119 export DESTDIR
120 endif
121 install_args += --prefix="$(prefix)"
122 install_args += --install-scripts="$(bindir)"
123 install_args += --single-version-externally-managed
124 install_args += --record=build/MANIFEST
125 export prefix
127 PYTHON_DIRS = cola
128 PYTHON_DIRS += test
130 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
131 ALL_PYTHON_DIRS += extras
133 # User customizations
134 -include config.mak
136 .PHONY: all
137 all:: build
139 .PHONY: build
140 build::
141 $(SETUP) $(QUIET) $(VERBOSE) $(build_args)
143 .PHONY: install
144 install:: all
145 $(SETUP) $(QUIET) $(VERBOSE) $(install_args)
147 .PHONY: doc
148 doc::
149 $(MAKE) -C share/doc/git-cola all
151 .PHONY: html
152 html::
153 $(MAKE) -C share/doc/git-cola html
155 .PHONY: man
156 man::
157 $(MAKE) -C share/doc/git-cola man
159 .PHONY: install-doc
160 install-doc::
161 $(MAKE) -C share/doc/git-cola install
163 .PHONY: install-html
164 install-html::
165 $(MAKE) -C share/doc/git-cola install-html
167 .PHONY: install-man
168 install-man::
169 $(MAKE) -C share/doc/git-cola install-man
171 .PHONY: uninstall
172 uninstall::
173 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
174 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
175 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
176 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
177 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
178 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
179 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
180 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
181 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
182 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
183 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
184 $(RM_R) "$(DESTDIR)$(prefix)"/share/git-cola
185 $(RM) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES/git-cola.mo
186 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
187 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
188 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
189 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
190 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
191 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
192 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES 2>/dev/null || true
193 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/* 2>/dev/null || true
194 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale 2>/dev/null || true
195 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
196 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
197 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
198 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
199 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
200 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
201 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
203 .PHONY: test
204 test:: all
205 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
207 .PHONY: coverage
208 coverage::
209 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
211 .PHONY: clean
212 clean::
213 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
214 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
215 $(RM_R) build dist tags git-cola.app
216 $(RM_R) share/locale
217 $(MAKE) -C share/doc/git-cola clean
219 # Update i18n files
220 .PHONY: i18n
221 i18n:: pot
222 i18n:: po
223 i18n:: mo
225 .PHONY: pot
226 pot::
227 $(SETUP) build_pot --build-dir=po --no-lang
229 .PHONY: po
230 po::
231 $(SETUP) build_pot --build-dir=po
233 .PHONY: mo
234 mo::
235 $(SETUP) build_mo --force
237 .PHONY: git-cola.app
238 git-cola.app::
239 $(MKDIR_P) $(cola_app)/Contents/MacOS
240 $(MKDIR_P) $(cola_app)/Contents/Resources
241 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo \
242 $(cola_app)/Contents
243 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
244 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
245 $(MAKE) prefix=$(cola_app)/Contents/Resources install install-doc
247 .PHONY: app-tarball
248 app-tarball:: git-cola.app
249 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
251 # Preview the markdown using "make README.html"
252 %.html: %.md
253 $(MARKDOWN) $< >$@
255 .PHONY: flake8
256 flake8::
257 $(FLAKE8) --version
258 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) \
259 $(ALL_PYTHON_DIRS) contrib
261 .PHONY: pylint3k
262 pylint3k::
263 $(PYLINT) --version
264 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) \
265 $(ALL_PYTHON_DIRS)
267 .PHONY: pylint
268 pylint::
269 $(PYLINT) --version
270 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
271 $(ALL_PYTHON_DIRS)
273 # Pre-commit checks
274 .PHONY: check
275 ifdef file
276 check::
277 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) $(file)
278 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized $(flags) $(file)
279 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized --py3k $(flags) $(file)
280 else
281 # NOTE: flake8 is not part of "make check" because the pytest-flake8 plugin runs flake8
282 # checks during "make test" via pytest.
283 check:: all
284 check:: test
285 check:: doc
286 check:: pylint3k
287 check:: pylint
288 endif
290 .PHONY: format
291 format::
292 $(GIT) ls-files -- '*.py' | \
293 $(GREP) -v ^qtpy | \
294 $(XARGS) $(BLACK) --skip-string-normalization
296 .PHONY: requirements-dev
297 requirements-dev::
298 $(PIP) install --requirement requirements/requirements-dev.txt
300 .PHONY: requirements-optional
301 requirements-optional::
302 $(PIP) install --requirement requirements/requirements-optional.txt
304 .PHONY: tox
305 tox::
306 $(TOX) $(TOX_FLAGS) $(flags)
308 .PHONY: tox-check
309 tox-check::
310 $(TOX) $(TOX_FLAGS) --parallel auto -e "$(TOX_ENVS)" $(flags)