feat: add a "Diff Mode" for diffing against arbitrary commits
[git-cola.git] / Makefile
blobc0f5a0239e0d9db60508a56a92b07e56387feca4
1 # The default target of this Makefile is...
2 .PHONY: all
3 all::
5 # Development
6 # -----------
7 # make V=1 # V=1 increases verbosity
8 # make develop # pip install --editable .
9 # make test [flags=...] # run tests; flags=-x fails fast, --ff failed first
10 # make test V=2 # run tests; V=2 increases test verbosity
11 # make doc # build docs
12 # make flake8 # python style checks
13 # make pylint [color=1] # run pylint; color=1 colorizes output
14 # make format # run the black python formatter
15 # make check [color=1] # run test, doc, flake8 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 i18n # make pot + make po
24 # Installation
25 # ------------
26 # make prefix=<path> install
27 # DESTDIR is also supported.
29 # The external commands used by this Makefile are...
30 BLACK = black
31 CP = cp
32 FIND = find
33 FLAKE8 = flake8
34 GREP = grep
35 GIT = git
36 MARKDOWN = markdown
37 MSGMERGE = msgmerge
38 MKDIR_P = mkdir -p
39 PIP = pip
40 PYTHON ?= python
41 PYTHON3 ?= python3
42 PYLINT = $(PYTHON) -B -m pylint
43 PYTEST = $(PYTHON) -B -m pytest
44 RM = rm -f
45 RM_R = rm -fr
46 RMDIR = rmdir
47 TAR = tar
48 TOX = tox
49 XARGS = xargs
50 XGETTEXT = xgettext
52 # Flags
53 # -----
54 ifdef V
55 VERBOSE = --verbose
56 ifeq ($(V),2)
57 TEST_VERBOSE = --verbose
58 VERBOSE_SHORT = -vv
59 else
60 VERBOSE_SHORT = -v
61 endif
62 else
63 QUIET = --quiet
64 endif
66 FLAKE8_FLAGS = $(VERBOSE)
68 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
69 uname_S := $(shell uname -s)
70 ifneq ($(uname_S),Linux)
71 PYTEST_FLAGS += --ignore=cola/inotify.py
72 endif
74 TOX_FLAGS = $(VERBOSE_SHORT) --develop --skip-missing-interpreters
75 TOX_ENVS ?= py{36,37,38,39,310,311}
77 PYLINT_SCORE_FLAG := $(shell $(PYLINT) --score=no --help >/dev/null 2>&1 && echo " --score=no" || true)
78 PYLINT_FLAGS = --rcfile=.pylintrc
79 ifdef color
80 PYLINT_FLAGS += --output-format=colorized
81 endif
82 ifneq ($(PYLINT_SCORE_FLAGSCORE),)
83 PYLINT_FLAGS += $(PYLINT_SCORE_FLAG)
84 endif
86 # These values can be overridden on the command-line or via config.mak
87 prefix = $(HOME)
88 python_version := $(shell $(PYTHON) -c 'import sys; print("%s.%s" % sys.version_info[:2])')
89 python_lib = python$(python_version)/site-packages
90 pythondir = $(prefix)/lib/$(python_lib)
91 # DESTDIR =
93 cola_base := git-cola
94 cola_app_base= $(cola_base).app
95 cola_app = $(CURDIR)/$(cola_app_base)
96 cola_app_resources = $(cola_app)/Contents/Resources
98 # Read $(VERSION) from cola/_version.py and strip quotes.
99 include cola/_version.py
100 cola_version := $(subst ',,$(VERSION))
101 cola_dist := $(cola_base)-$(cola_version)
103 install_args =
104 ifdef DESTDIR
105 install_args += --root="$(DESTDIR)"
106 export DESTDIR
107 endif
108 install_args += --prefix="$(prefix)"
109 install_args += --disable-pip-version-check
110 export prefix
112 PYTHON_DIRS = cola
113 PYTHON_DIRS += test
115 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
117 # User customizations
118 -include config.mak
120 all::
122 .PHONY: install
123 install:: all
124 $(PIP) $(QUIET) $(VERBOSE) install $(install_args) .
126 .PHONY: doc
127 doc::
128 $(MAKE) -C docs all
130 .PHONY: html
131 html::
132 $(MAKE) -C docs html
134 .PHONY: man
135 man::
136 $(MAKE) -C docs man
138 .PHONY: install-doc
139 install-doc::
140 $(MAKE) -C docs install
142 .PHONY: install-html
143 install-html::
144 $(MAKE) -C docs install-html
146 .PHONY: install-man
147 install-man::
148 $(MAKE) -C docs install-man
150 .PHONY: uninstall
151 uninstall::
152 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
153 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
154 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
155 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
156 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
157 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
158 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
159 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
160 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
161 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
162 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
163 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
164 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
165 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
166 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
167 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
168 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
169 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
170 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
171 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
172 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
173 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
174 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
175 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
177 .PHONY: test
178 test::
179 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
181 .PHONY: coverage
182 coverage::
183 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
185 .PHONY: clean
186 clean::
187 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
188 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
189 $(RM_R) build dist tags git-cola.app
190 $(MAKE) -C docs clean
192 # Update i18n files
193 .PHONY: i18n
194 i18n:: pot
195 i18n:: po
197 # Regenerate git-cola.pot with new translations
198 .PHONY: pot
199 pot::
200 $(XGETTEXT) \
201 --language=Python \
202 --keyword=N_ \
203 --no-wrap \
204 --omit-header \
205 --sort-output \
206 --output-dir cola/i18n \
207 --output git-cola.pot \
208 cola/*.py \
209 cola/*/*.py
211 # Update .po files with new translations from git-cola.pot
212 .PHONY: po
213 po::
214 for po in cola/i18n/*.po; \
215 do \
216 $(MSGMERGE) \
217 --no-wrap \
218 --no-fuzzy-matching \
219 --sort-output \
220 --output-file $$po.new \
221 $$po \
222 cola/i18n/git-cola.pot \
223 && \
224 mv $$po.new $$po; \
226 done
228 # Build a git-cola.app bundle.
229 .PHONY: git-cola.app
230 git-cola.app::
231 cola_full_version := $(shell ./bin/git-cola version --brief)
233 git-cola.app::
234 $(MKDIR_P) $(cola_app)/Contents/MacOS
235 $(MKDIR_P) $(cola_app_resources)
236 $(PYTHON3) -m venv --copies $(cola_app_resources)
237 $(cola_app_resources)/bin/pip install --requirement requirements/requirements.txt
238 $(cola_app_resources)/bin/pip install --requirement requirements/requirements-optional.txt
239 $(cola_app_resources)/bin/pip install --requirement requirements/requirements-dev.txt
241 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo $(cola_app)/Contents
242 ifneq ($(cola_full_version),)
243 sed -i -e s/0.0.0.0/$(cola_full_version)/ $(cola_app)/Contents/Info.plist
244 endif
245 sed -i -e s/0.0.0/$(cola_version)/ $(cola_app)/Contents/Info.plist
246 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
247 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
248 $(MAKE) PIP=$(cola_app_resources)/bin/pip \
249 prefix=$(cola_app_resources) install
250 $(MAKE) SPHINXBUILD=$(cola_app_resources)/bin/sphinx-build \
251 prefix=$(cola_app_resources) install-doc
253 .PHONY: app-tarball
254 app-tarball:: git-cola.app
255 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
257 # Preview the markdown using "make README.html"
258 %.html: %.md
259 $(MARKDOWN) $< >$@
261 .PHONY: flake8
262 flake8::
263 $(FLAKE8) --version
264 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) \
265 $(ALL_PYTHON_DIRS) contrib
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 else
280 # NOTE: flake8 is not part of "make check" because the pytest-flake8 plugin runs flake8
281 # checks during "make test" via pytest.
282 check:: all
283 check:: test
284 check:: doc
285 check:: pylint
286 endif
288 .PHONY: format
289 format::
290 $(GIT) ls-files -- '*.py' | \
291 $(GREP) -v ^qtpy | \
292 $(XARGS) $(BLACK) --skip-string-normalization
294 # Run "make develop" from inside a newly created virtualenv to create an
295 # editable installation.
296 .PHONY: develop
297 develop::
298 $(PIP) install --editable .
300 .PHONY: requirements
301 requirements::
302 $(PIP) install --requirement requirements/requirements.txt
304 .PHONY: requirements-dev
305 requirements-dev::
306 $(PIP) install --requirement requirements/requirements-dev.txt
308 .PHONY: requirements-optional
309 requirements-optional::
310 $(PIP) install --requirement requirements/requirements-optional.txt
312 .PHONY: tox
313 tox::
314 $(TOX) $(TOX_FLAGS) --parallel auto -e "${TOX_ENVS}" $(flags)
316 .PHONY: tox-check
317 tox-check::
318 $(TOX) $(TOX_FLAGS) --parallel auto -e check $(flags)