-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathMakefile
More file actions
260 lines (220 loc) · 10.2 KB
/
Makefile
File metadata and controls
260 lines (220 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#
# Makefile for Brazilian Portuguese Python Documentation
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# based on: https://github.com/python/python-docs-fr/blob/3.8/Makefile
#
#################
# Configuration
# Read environment variables from file to keep this clean move version
# changes elsewhere
include .env
# Force the use of Bash
SHELL=/bin/bash
# Time of starting this run
NOW := $(shell date +'%Y%m%-d-%H%M%Z')
# Force realpath, not relative one
override CPYTHON_DIR := $(shell realpath $(CPYTHON_DIR))
override LOGS_DIR := $(shell realpath $(LOGS_DIR))
override VENV_DIR := $(shell realpath $(VENV_DIR))
#
#################
.PHONY: build clean help htmlview lint merge pot pull push setup spell tx-config tx-install venv
help:
@echo "Please use 'make <target>' where <target> is one of:"
@echo " build Build an local version in html; deps: 'setup'"
@echo " push Commit and push translations; no deps"
@echo " pull Download translations from Transifex; deps: 'tx-config'"
@echo " tx-config Regenerate Transifex config; deps: 'pot' and 'tx-install'"
@echo " tx-install Install Transifex CLI client; deps: no deps"
@echo " pot Regenerate POT files from sources; deps: 'setup'"
@echo " htmlview View docs in a web browser; deps: build"
@echo " spell Check spelling, storing output in $(POSPELL_TMP_DIR)"
@echo " lint Do some linting in PO file's Sphinx syntax. deps: 'venv'"
@echo " merge Merge $(BRANCH) branch's .po files into older branches"
@echo " Defaults overwrite in: $(BUGFIXBRANCH)"
@echo " and NOT overwrite in: $(OLDERBRANCHES)"
@echo " clean Do some house cleaning"
@echo ""
# build: build the documentation using the translation files currently available
# at the moment. For most up-to-date docs, run "tx-config" and "pull"
# before this. If passing SPHINXERRORHANDLING='', warnings will not be
# treated as errors, which is good to skip simple Sphinx syntax mistakes.
build: setup
@mkdir -p "$(CPYTHON_DIR)/$(LOCALE_DIR)/$(LANGUAGE)/LC_MESSAGES/"
@cp --parents *.po **/*.po "$(CPYTHON_DIR)/$(LOCALE_DIR)/$(LANGUAGE)/LC_MESSAGES/"
@echo "Building Python $(BRANCH) Documentation in $(LANGUAGE) ..."
@mkdir -p "$(LOGS_DIR)/build"
@$(MAKE) -C $(CPYTHON_DIR)/Doc/ \
PYTHON=$(PYTHON) \
SPHINXERRORHANDLING=$(SPHINXERRORHANDLING) \
SPHINXOPTS="--keep-going \
-D gettext_compact=0 \
-D language=$(LANGUAGE) \
-D latex_engine=xelatex \
-D latex_elements.inputenc= \
-D latex_elements.fontenc=" \
html \
2> >(tee -a $(LOGS_DIR)/build/err-$(NOW).txt >&2)
# push: Commit and push translation files and Transifex config file to repo.
# First it git-adds tracked file that doesn't exclusively match changes
# in POT-Creation-Date header field. Then it git-adds untracked PO files
# that might have been created in the update process, and the Transifex
# configuration. Finally, only commit and push only if any file was
# git-added (staged); otherwise, it does nothing.
# The MSG variable has a default commit message, but one can override it
# e.g. make push MSG='my message'
push:
@git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3 | xargs -r git add
@git add $(shell git ls-files -o *.po **/*.po) .tx/config
@git diff-index --cached --quiet HEAD || \
{ git commit -m "Update translations from Transifex" && git push; }
# pull: Download translations files from Transifex, and apply line wrapping.
# For downloading new translation files, first run "tx-config" target
# to update the translation file mapping.
pull: tx-config
@"$(TX_CLI_DIR)/tx" pull -l $(LANGUAGE) -t -f --use-git-timestamps
@"$(VENV_DIR)/bin/powrap" --quiet *.po **/*.po
# tx-config: Generate a new Transifex configuration file by reading
# the pot files generated by 'pot' target. The file is
# created in $(LOCALE_DIR)/.tx/config, and then is tweaked
# to fit the language's needs and then placed in .tx/config
# at the project's root directory.
tx-config: TRANSIFEX_PROJECT := python-newest
tx-config: pot tx-install
@cd $(CPYTHON_DIR)/$(LOCALE_DIR); \
rm -rf .tx; \
"$(VENV_DIR)/bin/sphinx-intl" create-txconfig; \
"$(VENV_DIR)/bin/sphinx-intl" update-txconfig-resources \
--transifex-organization-name python-doc \
--transifex-project-name=$(TRANSIFEX_PROJECT) \
--locale-dir . \
--pot-dir pot
@mkdir -p .tx
@sed $(CPYTHON_DIR)/$(LOCALE_DIR)/.tx/config \
-e "s|^file_filter = .*|&\nx&|;" \
-e "s|^source_file = pot/|source_file = $(LOCALE_RELATIVE)/pot/|" \
> .tx/config
@sed -i .tx/config \
-e "s|^xfile_filter = ./<lang>/LC_MESSAGES/|trans.$(LANGUAGE) = |;"
# tx-install: Install Transifex CLI client if not installed yet. Installs
# the TX_CLI_VERSION version into TX_CLI_DIR directory. If
# TX_CLI_VERSION not provided, uses the latest one.
tx-install: URL := https://raw.githubusercontent.com/transifex/cli/master/install.sh
tx-install:
@if [ ! -x "$(TX_CLI_DIR)/tx" ]; then \
echo "Transifex TX Client not found, installing ..."; \
cd "$(TX_CLI_DIR)"; \
if [ -n "v$(TX_CLI_VERSION)" ]; then \
curl -s -o- $(URL) | bash -s -- v$(TX_CLI_VERSION); \
else \
curl -s -o- $(URL) | bash; \
fi; \
fi
# pot: After running "setup" target, run sphinx-build's gettext target
# to generate .pot files under $(CPYTHON_DIR)/Doc/locales/pot.
pot: setup
@$(MAKE) -C $(CPYTHON_DIR)/Doc/ \
VENVDIR=./venv \
PYTHON=$(PYTHON) \
ALLSPHINXOPTS='-E \
-b gettext \
-D gettext_compact=0 \
-d build/.doctrees \
. $(CPYTHON_DIR)/$(LOCALE_DIR)/pot' \
build
# setup: After running "venv" target, prepare that virtual environment with
# a local clone of cpython repository and the translation files.
# If the directories exists, only update the cpython repository and
# the translation files copy which could have new/updated files.
setup: CPYTHON_URL := https://github.com/python/cpython
setup: venv
@if [ -z "$(BRANCH)" ]; then \
echo "BRANCH is empty, should have git-branch. Unable to continue."; \
exit 1; \
fi
@if ! [ -d "$(CPYTHON_DIR)" ]; then \
echo "CPython repo not found; cloning ..."; \
git clone --depth 1 --no-single-branch $(CPYTHON_URL) $(CPYTHON_DIR); \
git -C "$(CPYTHON_DIR)" checkout $(BRANCH); \
else \
echo "CPython repo found; updating ..."; \
git -C "$(CPYTHON_DIR)" checkout $(BRANCH); \
git -C "$(CPYTHON_DIR)" pull --rebase; \
fi
@echo "Creating CPython's documentation virtual environment ..."
@if [ ! -d "$(CPYTHON_DIR)/Doc/venv" ]; then \
$(MAKE) -C "$(CPYTHON_DIR)/Doc" PYTHON=$(PYTHON) venv; \
fi
# venv: create a virtual environment which will be used by almost every
# other target of this script. CPython specific packages are installed
# in there specific venv (see 'setup' target).
venv:
@if [ ! -d "$(VENV_DIR)" ]; then \
echo "Setting up language team's virtual environment ..."; \
"$(PYTHON)" -m venv "$(VENV_DIR)"; \
"$(VENV_DIR)/bin/python" -m pip install --upgrade pip; \
mkdir -p "$(LOGS_DIR)"; \
"$(VENV_DIR)/bin/pip" install --requirement requirements.txt \
--log "$(LOGS_DIR)/venv-$(NOW).txt"; \
fi
# htmlview: View the documentation locally, using Makefile's "htmlview" target.
# Run "build" before using this target.
htmlview: build
@INDEX="$(CPYTHON_DIR)/Doc/build/html/index.html"; \
"$(PYTHON)" -c "import os, webbrowser; \
webbrowser.open('file://' + os.path.realpath('$$INDEX'))"
# spell: run spell checking tool in all po files listed in SRCS variable,
# storing the output in text files DESTS for proofreading. The
# DESTS target run the spellchecking, while the typos.txt target
# gather all reported issues in one file, sorted without redundancy.
SRCS := $(wildcard *.po **/*.po)
DESTS := $(addprefix $(LOGS_DIR)/pospell-$(NOW)/out/,$(patsubst %.po,%.txt,$(SRCS)))
spell: venv $(DESTS) $(LOGS_DIR)/pospell-$(NOW)/all.txt
$(LOGS_DIR)/pospell-$(NOW)/out/%.txt: %.po dict
@echo "Checking $< ..."
@mkdir -p $(@D)
@$(VENV_DIR)/bin/pospell -l "$(LANGUAGE)" -p dict $< > $@ || true
$(LOGS_DIR)/pospell-$(NOW)/all.txt:
@echo "Gathering all typos in $(LOGS_DIR)/pospell-$(NOW)/all.txt ..."
@cut -d: -f3- $(DESTS) | sort -u > $@
# merge: Merge translations from BRANCH (Python version currently aim of
# translation) into each branch listed by BUGFIXBRANCH and
# OLDERBRANCHES (branches of older Python versions) so that older
# versions of the Python Docs try make at least some use of the latest
# translations. OLDERBRANCHES has '--no-overwrite' flag so it does not
# overwrite translated strings, preserving history.
# After merging, only commit and push only if any file was git-added
# (staged) to the target branch; otherwise, it does nothing.
merge: venv $(BUGFIXBRANCH) $(OLDERBRANCHES)
$(OLDERBRANCHES): OVERWRITEFLAG = --no-overwrite
$(BUGFIXBRANCH) $(OLDERBRANCHES):
@if [[ $@ == $(BRANCH) ]]; then \
echo "Ignoring attempt to pomerge '$(BRANCH)' into itself."; \
else \
echo "Merging translations from $(BRANCH) branch into $@ ..."; \
$(VENV_DIR)/bin/pomerge --from-files *.po **/*.po; \
git checkout $@; \
$(VENV_DIR)/bin/pomerge $(OVERWRITEFLAG) --to-files *.po **/*.po; \
$(VENV_DIR)/bin/powrap --modified *.po **/*.po; \
git add -u; \
if [ -n "$(git diff --name-only --cached)" ]; then \
git commit -m $(MSG); \
git push; \
else \
echo 'Nothing to commit'; \
fi; \
git checkout $(BRANCH); \
fi
# lint: Report reStructuredText syntax errors in the translation files
lint: venv
@mkdir -p "$(LOGS_DIR)"
@$(VENV_DIR)/bin/sphinx-lint *.po **/*.po |& \
tee -a $(LOGS_DIR)/lint-$(NOW).txt || true
@echo "Lint output stored in $(LOGS_DIR)/lint-$(NOW).txt"
# clean: remove all .mo files and the venv directory that may exist and could
# have been created by the actions in other targets of this script.
clean:
rm -rf "$(VENV_DIR)"
rm -rf "$(CPYTHON_DIR)/$(LOCALE_DIR)"
[ -d "$(CPYTHON_DIR)" ] && $(MAKE) -C "$(CPYTHON_DIR)/Doc" clean-venv