build: use setup.cfg for all dependency tracking
[git-cola.git] / Makefile
blob43c61a67282bbab998c45ea99d8de337820f4a3f
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 test [flags=...] # run tests; flags=-x fails fast, --ff failed first
9 # make test V=2 # run tests; V=2 increases test verbosity
10 # make doc # build docs
11 # make pylint [color=1] # run pylint; color=1 colorizes output
12 # make fmt # run the code formatter
13 # make check [color=1] # run test, doc and pylint
14 # make check file=<filename> # run checks on <filename>
16 # Release Prep
17 # ------------
18 # make pot # update main translation template
19 # make po # merge translations
20 # make i18n # make pot + make po
22 # Installation
23 # ------------
24 # make prefix=<path> install
25 # DESTDIR is also supported.
27 # The external commands used by this Makefile are...
28 CERCIS = cercis
29 CP = cp
30 FIND = find
31 GREP = grep
32 GIT = git
33 MARKDOWN = markdown
34 MSGMERGE = msgmerge
35 MKDIR_P = mkdir -p
36 PIP = pip
37 PYTHON ?= python3
38 PYLINT = $(PYTHON) -B -m pylint
39 PYTEST = $(PYTHON) -B -m pytest
40 RM = rm -f
41 RM_R = rm -fr
42 RMDIR = rmdir
43 TAR = tar
44 TOX = tox
45 XARGS = xargs
46 XGETTEXT = xgettext
48 # Flags
49 # -----
50 ifdef V
51 VERBOSE = --verbose
52 ifeq ($(V),2)
53 TEST_VERBOSE = --verbose
54 VERBOSE_SHORT = -vv
55 else
56 VERBOSE_SHORT = -v
57 endif
58 else
59 QUIET = --quiet
60 endif
62 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
63 uname_S := $(shell uname -s)
64 ifneq ($(uname_S),Linux)
65 PYTEST_FLAGS += --ignore=cola/inotify.py
66 endif
68 PYLINT_SCORE_FLAG := $(shell $(PYLINT) --score=no --help >/dev/null 2>&1 && echo " --score=no" || true)
69 PYLINT_FLAGS = --rcfile=.pylintrc
70 ifdef color
71 PYLINT_FLAGS += --output-format=colorized
72 endif
73 ifneq ($(PYLINT_SCORE_FLAGSCORE),)
74 PYLINT_FLAGS += $(PYLINT_SCORE_FLAG)
75 endif
77 TOX_FLAGS = $(VERBOSE_SHORT)
79 # These values can be overridden on the command-line or via config.mak
80 prefix = $(HOME)
81 python_version := $(shell $(PYTHON) -c 'import sys; print("%s.%s" % sys.version_info[:2])')
82 python_lib = python$(python_version)/site-packages
83 pythondir = $(prefix)/lib/$(python_lib)
84 # DESTDIR =
86 cola_base := git-cola
87 cola_app_base= $(cola_base).app
88 cola_app = $(CURDIR)/$(cola_app_base)
89 cola_app_resources = $(cola_app)/Contents/Resources
91 # Read $(VERSION) from cola/_version.py and strip quotes.
92 include cola/_version.py
93 cola_version := $(subst ',,$(VERSION))
94 cola_dist := $(cola_base)-$(cola_version)
96 install_args =
97 ifdef DESTDIR
98 install_args += --root="$(DESTDIR)"
99 export DESTDIR
100 endif
101 install_args += --prefix="$(prefix)"
102 install_args += --disable-pip-version-check
103 export prefix
105 PYTHON_DIRS = cola
106 PYTHON_DIRS += test
108 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
110 # User customizations
111 -include config.mak
113 all::
115 .PHONY: install
116 install:: all
117 $(PIP) $(QUIET) $(VERBOSE) install $(install_args) .
119 .PHONY: doc
120 doc::
121 $(MAKE) -C docs all
123 .PHONY: html
124 html::
125 $(MAKE) -C docs html
127 .PHONY: man
128 man::
129 $(MAKE) -C docs man
131 .PHONY: install-doc
132 install-doc::
133 $(MAKE) -C docs install
135 .PHONY: install-html
136 install-html::
137 $(MAKE) -C docs install-html
139 .PHONY: install-man
140 install-man::
141 $(MAKE) -C docs install-man
143 .PHONY: uninstall
144 uninstall::
145 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
146 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
147 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
148 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
149 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
150 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
151 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
152 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
153 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
154 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
155 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
156 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
157 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
158 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
159 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
160 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
161 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
162 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
163 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
164 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
165 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
166 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
167 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
168 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
170 .PHONY: test
171 test::
172 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
174 .PHONY: coverage
175 coverage::
176 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
178 .PHONY: clean
179 clean::
180 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
181 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
182 $(RM_R) build dist git-cola.app
183 $(MAKE) -C docs clean
185 # Update i18n files
186 .PHONY: i18n
187 i18n:: pot
188 i18n:: po
190 # Regenerate git-cola.pot with new translations
191 .PHONY: pot
192 pot::
193 $(XGETTEXT) \
194 --language=Python \
195 --keyword=N_ \
196 --no-wrap \
197 --omit-header \
198 --sort-output \
199 --output-dir cola/i18n \
200 --output git-cola.pot \
201 cola/*.py \
202 cola/*/*.py
204 # Update .po files with new translations from git-cola.pot
205 .PHONY: po
206 po::
207 for po in cola/i18n/*.po; \
208 do \
209 $(MSGMERGE) \
210 --no-wrap \
211 --no-fuzzy-matching \
212 --sort-output \
213 --output-file $$po.new \
214 $$po \
215 cola/i18n/git-cola.pot \
216 && \
217 mv $$po.new $$po; \
219 done
221 # Build a git-cola.app bundle.
222 .PHONY: git-cola.app
223 git-cola.app::
224 cola_full_version := $(shell ./bin/git-cola version --brief)
226 git-cola.app::
227 $(MKDIR_P) $(cola_app)/Contents/MacOS
228 $(MKDIR_P) $(cola_app_resources)
229 $(PYTHON) -m venv $(cola_app_resources)
230 $(cola_app_resources)/bin/pip install '.[docs,extras,pyqt6]'
231 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo $(cola_app)/Contents
232 ifneq ($(cola_full_version),)
233 sed -i -e s/0.0.0.0/$(cola_full_version)/ $(cola_app)/Contents/Info.plist
234 endif
235 sed -i -e s/0.0.0/$(cola_version)/ $(cola_app)/Contents/Info.plist
236 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
237 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
238 $(MAKE) PIP=$(cola_app_resources)/bin/pip \
239 prefix=$(cola_app_resources) install
240 $(MAKE) SPHINXBUILD=$(cola_app_resources)/bin/sphinx-build \
241 prefix=$(cola_app_resources) install-doc
243 .PHONY: app-tarball
244 app-tarball:: git-cola.app
245 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
247 # Preview the markdown using "make README.html"
248 %.html: %.md
249 $(MARKDOWN) $< >$@
251 .PHONY: pylint
252 pylint::
253 $(PYLINT) --version
254 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
255 $(ALL_PYTHON_DIRS)
257 # Pre-commit checks
258 .PHONY: check
259 ifdef file
260 check::
261 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized $(flags) $(file)
262 else
263 check:: all
264 check:: test
265 check:: doc
266 check:: pylint
267 endif
269 .PHONY: fmt
270 fmt::
271 $(GIT) ls-files -- '*.py' | \
272 $(GREP) -v ^qtpy | \
273 $(XARGS) $(CERCIS)
275 .PHONY: requirements-dev
276 requirements-dev::
277 $(PIP) install --editable '.[build,dev]'
279 .PHONY: requirements-extras
280 requirements-extras::
281 $(PIP) install --editable '.[extras]'
283 .PHONY: tox
284 tox::
285 $(TOX) run $(TOX_FLAGS) $(flags)
287 .PHONY: tox-check
288 tox-check::
289 $(TOX) run -e check $(TOX_FLAGS) $(flags)