Skip to content

Commit acf16bd

Browse files
committed
Backporting Makefile and merge.py.
1 parent 581fa8e commit acf16bd

File tree

2 files changed

+269
-115
lines changed

2 files changed

+269
-115
lines changed

Makefile

Lines changed: 119 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#
33
# Here is what you can do:
44
#
5-
# - make # Automatically build an html local version
6-
# - make todo # To list remaining tasks
5+
# - make # Automatically build an HTML local version
6+
# - make todo # To list remaining tasks and show current progression
77
# - make verifs # To check for correctness: wrapping, spelling
8-
# - make wrap # To check for wrapping
8+
# - make wrap # To rewrap modified files
99
# - make spell # To check for spelling
10-
# - make merge # To merge pot from upstream
10+
# - make clean # To remove build artifacts
1111
# - make fuzzy # To find fuzzy strings
12-
# - make progress # To compute current progression
1312
#
1413
# Modes are: autobuild-stable, autobuild-dev, and autobuild-html,
1514
# documented in gen/src/3.6/Doc/Makefile as we're only delegating the
@@ -22,24 +21,51 @@
2221
# test build, we're building with the .rst files that generated our
2322
# .po files.
2423
CPYTHON_CURRENT_COMMIT := dc3239177ff26cb6a12e437a1f507be730fe8ba7
25-
26-
CPYTHON_PATH := ../cpython/
27-
2824
LANGUAGE := fr
29-
BRANCH := 3.8
30-
31-
.SILENT:
25+
BRANCH := 3.9
26+
27+
EXCLUDED := \
28+
whatsnew/2.?.po \
29+
whatsnew/3.[0-8].po \
30+
c-api/ \
31+
distutils/ \
32+
install/ \
33+
library/2to3.po \
34+
library/distutils.po \
35+
library/imp.po \
36+
library/tkinter.tix.po \
37+
library/test.po \
38+
library/aifc.po \
39+
library/asynchat.po \
40+
library/asyncore.po \
41+
library/audioop.po \
42+
library/cgi.po \
43+
library/cgitb.po \
44+
library/chunk.po \
45+
library/crypt.po \
46+
library/imghdr.po \
47+
library/msilib.po \
48+
library/nntplib.po \
49+
library/nis.po \
50+
library/ossaudiodev.po \
51+
library/pipes.po \
52+
library/smtpd.po \
53+
library/sndhdr.po \
54+
library/spwd.po \
55+
library/sunau.po \
56+
library/telnetlib.po \
57+
library/uu.po \
58+
library/xdrlib.po
3259

3360
# Internal variables
3461

3562
UPSTREAM := https://github.com/python/cpython
36-
VENV := $(shell pwd)/venv/
63+
3764
PYTHON := $(shell which python3)
3865
MODE := html
3966
POSPELL_TMP_DIR := .pospell/
40-
WORKTREES := $(VENV)/worktrees/
41-
WORKTREE := $(WORKTREES)/$(CPYTHON_CURRENT_COMMIT)/
4267
JOBS := auto
68+
SPHINXERRORHANDLING = -W
4369

4470
# Detect OS
4571

@@ -59,126 +85,104 @@ else
5985
endif
6086

6187
.PHONY: all
62-
all: setup
63-
mkdir -p $(WORKTREE)/locales/$(LANGUAGE)/LC_MESSAGES/
64-
$(CP_CMD) -uv --parents *.po */*.po $(WORKTREE)/locales/$(LANGUAGE)/LC_MESSAGES/ | cut -d"'" -f2
65-
$(MAKE) -C $(WORKTREE)/Doc/ VENVDIR=$(WORKTREE)/Doc/venv/ PYTHON=$(PYTHON) \
66-
SPHINXOPTS='-qW -j$(JOBS) \
67-
-D locale_dirs=../locales \
68-
-D language=$(LANGUAGE) \
69-
-D gettext_compact=0 \
70-
-D latex_engine=xelatex \
71-
-D latex_elements.inputenc= \
72-
-D latex_elements.fontenc=' \
73-
$(MODE) && echo "Build success, open file://$(WORKTREE)/Doc/build/html/index.html or run 'make serve' to see them."
74-
75-
76-
.PHONY: setup
77-
setup: venv
78-
# Setup the main clone
79-
if ! [ -d $(CPYTHON_PATH) ]; then \
80-
git clone --depth 16 --branch $(BRANCH) $(UPSTREAM) $(CPYTHON_PATH); \
88+
all: ensure_prerequisites
89+
git -C venv/cpython checkout $(CPYTHON_CURRENT_COMMIT) || (git -C venv/cpython fetch && git -C venv/cpython checkout $(CPYTHON_CURRENT_COMMIT))
90+
mkdir -p locales/$(LANGUAGE)/LC_MESSAGES/
91+
$(CP_CMD) -u --parents *.po */*.po locales/$(LANGUAGE)/LC_MESSAGES/
92+
$(MAKE) -C venv/cpython/Doc/ \
93+
JOBS='$(JOBS)' \
94+
SPHINXOPTS='-D locale_dirs=$(abspath locales) \
95+
-D language=$(LANGUAGE) \
96+
-D gettext_compact=0 \
97+
-D latex_engine=xelatex \
98+
-D latex_elements.inputenc= \
99+
-D latex_elements.fontenc=' \
100+
SPHINXERRORHANDLING=$(SPHINXERRORHANDLING) \
101+
$(MODE)
102+
@echo "Build success, open file://$(abspath venv/cpython/)/Doc/build/html/index.html or run 'make htmlview' to see them."
103+
104+
105+
# We clone cpython/ inside venv/ because venv/ is the only directory
106+
# excluded by cpython' Sphinx configuration.
107+
venv/cpython/.git/HEAD:
108+
git clone https://github.com/python/cpython venv/cpython
109+
110+
111+
.PHONY: ensure_prerequisites
112+
ensure_prerequisites: venv/cpython/.git/HEAD
113+
@if ! (blurb help >/dev/null 2>&1 && sphinx-build --version >/dev/null 2>&1); then \
114+
git -C venv/cpython/ checkout $(BRANCH); \
115+
echo "You're missing dependencies please install:"; \
116+
echo ""; \
117+
echo " python -m pip install -r requirements.txt -r venv/cpython/Doc/requirements.txt"; \
118+
exit 1; \
81119
fi
82120

83-
# Setup the current worktree
84-
if ! [ -d $(WORKTREE) ]; then \
85-
rm -fr $(WORKTREES); \
86-
git -C $(CPYTHON_PATH) worktree prune; \
87-
mkdir -p $(WORKTREES); \
88-
if [ -n "$(CPYTHON_CURRENT_COMMIT)" ]; \
89-
then \
90-
depth=32; \
91-
while ! git -C $(CPYTHON_PATH) cat-file -e $(CPYTHON_CURRENT_COMMIT); \
92-
do \
93-
depth=$$((depth * 2)); \
94-
git -C $(CPYTHON_PATH) fetch --depth $$depth $(UPSTREAM) $(BRANCH); \
95-
done \
96-
else \
97-
git -C $(CPYTHON_PATH) fetch --depth 1 $(UPSTREAM); \
98-
fi; \
99-
git -C $(CPYTHON_PATH) worktree add $(WORKTREE)/ $(CPYTHON_CURRENT_COMMIT); \
100-
$(MAKE) -C $(WORKTREE)/Doc/ VENVDIR=$(WORKTREE)/Doc/venv/ PYTHON=$(PYTHON) venv; \
101-
$(WORKTREE)/Doc/venv/bin/python -m pip install Sphinx==2.2.2 docutils==0.15; \
102-
fi
103-
104-
105-
.PHONY: venv
106-
venv:
107-
if [ ! -d $(VENV) ]; then $(PYTHON) -m venv --prompt python-docs-fr $(VENV); fi
108-
$(VENV)/bin/python -m pip install -q -r requirements.txt 2> $(VENV)/pip-install.log
109-
if grep -q 'pip install --upgrade pip' $(VENV)/pip-install.log; then \
110-
$(VENV)/bin/pip install -q --upgrade pip; \
111-
fi
112-
113-
114-
.PHONY: serve
115-
serve:
116-
$(MAKE) -C $(WORKTREE)/Doc/ serve
117-
118-
119-
.PHONY: progress
120-
progress:
121-
$(PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
122-
$(shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid') \
123-
$(shell msgcat *.po */*.po | grep -c '^msgid')
124-
121+
.PHONY: htmlview
122+
htmlview: MODE=htmlview
123+
htmlview: all
125124

126125
.PHONY: todo
127-
todo: venv
128-
$(VENV)/bin/potodo
126+
todo: ensure_prerequisites
127+
potodo --api-url 'https://git.afpy.org/api/v1/repos/AFPy/python-docs-fr/issues?state=open&type=issues' --exclude venv .venv $(EXCLUDED)
129128

130129
.PHONY: wrap
131-
wrap: venv
132-
$(VENV)/bin/powrap --check --quiet *.po **/*.po
130+
wrap: ensure_prerequisites
131+
@echo "Re wrapping modified files"
132+
powrap -m
133133

134134
SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$')
135135
# foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out
136136
DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS)))
137137

138138
.PHONY: spell
139-
spell: venv $(DESTS)
139+
spell: ensure_prerequisites $(DESTS)
140+
141+
.PHONY: line-length
142+
line-length:
143+
@echo "Searching for long lines..."
144+
@awk '{if (length(gensub(/శ్రీనివాస్/, ".", "g", $$0)) > 80 && length(gensub(/[^ ]/, "", "g")) > 1) {print FILENAME ":" FNR, "line too long:", $$0; ERRORS+=1}} END {if (ERRORS>0) {exit 1}}' *.po */*.po
145+
146+
.PHONY: sphinx-lint
147+
sphinx-lint:
148+
@echo "Checking all files using sphinx-lint..."
149+
@sphinx-lint --enable all --disable line-too-long *.po */*.po
140150

141151
$(POSPELL_TMP_DIR)/%.po.out: %.po dict
142-
echo "Checking $<..."
143-
mkdir -p $(@D)
144-
$(VENV)/bin/pospell -p dict -l fr_FR $< && touch $@
152+
@echo "Pospell checking $<..."
153+
@mkdir -p $(@D)
154+
pospell -p dict -l fr_FR $< && touch $@
145155

146156
.PHONY: fuzzy
147-
fuzzy: venv
148-
$(VENV)/bin/potodo -f
157+
fuzzy: ensure_prerequisites
158+
potodo --only-fuzzy --api-url 'https://git.afpy.org/api/v1/repos/AFPy/python-docs-fr/issues?state=open&type=issues' --exclude venv .venv $(EXCLUDED)
159+
160+
.PHONY: check-headers
161+
check-headers:
162+
@grep -L '^# Copyright (C) [0-9-]*, Python Software Foundation' *.po */*.po | while read -r file;\
163+
do \
164+
echo "Please update the po comment in $$file"; \
165+
done
166+
@grep -L '^"Project-Id-Version: Python 3\\n"$$' *.po */*.po | while read -r file;\
167+
do \
168+
echo "Please update the 'Project-Id-Version' header in $$file"; \
169+
done
170+
@grep -L '^"Language: fr\\n"$$' *.po */*.po | while read -r file;\
171+
do \
172+
echo "Please update the 'Language' header in $$file"; \
173+
done
174+
@grep -L '^"Language-Team: FRENCH <[email protected]>\\n"' *.po */*.po | while read -r file;\
175+
do \
176+
echo "Please update the 'Language-Team' header in $$file"; \
177+
done
149178

150179
.PHONY: verifs
151-
verifs: wrap spell
152-
153-
.PHONY: merge
154-
merge: setup
155-
git -C $(CPYTHON_PATH) fetch $(UPSTREAM)
156-
rm -fr $(WORKTREES)/$(BRANCH)
157-
git -C $(CPYTHON_PATH) worktree prune
158-
git -C $(CPYTHON_PATH) worktree add $(WORKTREES)/$(BRANCH) $(word 1,$(shell git -C $(CPYTHON_PATH) remote -v | grep python/cpython))/$(BRANCH)
159-
$(MAKE) -C $(WORKTREES)/$(BRANCH)/Doc/ VENVDIR=$(WORKTREES)/$(BRANCH)/Doc/venv/ PYTHON=$(PYTHON) venv;
160-
(cd $(WORKTREES)/$(BRANCH); $(WORKTREES)/$(BRANCH)/Doc/venv/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/)
161-
find $(WORKTREES)/$(BRANCH) -name '*.pot' |\
162-
while read -r POT;\
163-
do\
164-
PO="./$$(echo "$$POT" | sed "s#$(WORKTREES)/$(BRANCH)/pot/##; s#\.pot\$$#.po#")";\
165-
mkdir -p "$$(dirname "$$PO")";\
166-
if [ -f "$$PO" ];\
167-
then\
168-
case "$$POT" in\
169-
*whatsnew*) msgmerge --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
170-
*) msgmerge --backup=off --force-po -U "$$PO" "$$POT" ;;\
171-
esac\
172-
else\
173-
msgcat -o "$$PO" "$$POT";\
174-
fi\
175-
done
176-
sed -i 's/^CPYTHON_CURRENT_COMMIT :=.*/CPYTHON_CURRENT_COMMIT := $(shell git -C $(WORKTREES)/$(BRANCH) rev-parse HEAD)/' Makefile
177-
rm -fr $(WORKTREES)/$(BRANCH)
178-
git -C $(CPYTHON_PATH) worktree prune
179-
echo 'To add, you can use git status -s | grep "^ M .*\.po" | cut -d" " -f3 | while read -r file; do if [ $$(git diff "$$file" | wc -l) -gt 13 ]; then git add "$$file"; fi ; done'
180+
verifs: spell line-length sphinx-lint check-headers
180181

181182
.PHONY: clean
182183
clean:
183-
rm -fr $(VENV) $(POSPELL_TMP_DIR)
184+
@echo "Cleaning *.mo and $(POSPELL_TMP_DIR)"
185+
rm -fr $(POSPELL_TMP_DIR) locales/$(LANGUAGE)/LC_MESSAGES/
184186
find -name '*.mo' -delete
187+
@echo "Cleaning build directory"
188+
$(MAKE) -C venv/cpython/Doc/ clean

0 commit comments

Comments
 (0)