4
4
#
5
5
# - make # Automatically build an html local version
6
6
# - make todo # To list remaining tasks
7
- # - make verifs # To check for correctness: wrapping, spelling
8
- # - make wrap # To check for wrapping
9
- # - make spell # To check for spelling
7
+ # - make verifs # To check for correctness: wrapping, spelling
8
+ # - make wrap # To check for wrapping
9
+ # - make spell # To check for spelling
10
10
# - make merge # To merge pot from upstream
11
11
# - make fuzzy # To find fuzzy strings
12
12
# - make progress # To compute current progression
13
- # - make upgrade_venv # To upgrade the venv that compiles the doc
14
13
#
15
14
# Modes are: autobuild-stable, autobuild-dev, and autobuild-html,
16
15
# documented in gen/src/3.6/Doc/Makefile as we're only delegating the
17
16
# real work to the Python Doc Makefile.
18
17
19
- CPYTHON_CLONE := $(realpath ../cpython/)
20
- SPHINX_CONF := $(CPYTHON_CLONE ) /Doc/conf.py
18
+ # Configuration
19
+
20
+ # The CPYTHON_CURRENT_COMMIT is the commit, in the cpython repository,
21
+ # from which we generated our po files. We use it here so when we
22
+ # test build, we're building with the .rst files that generated our
23
+ # .po files.
24
+ CPYTHON_CURRENT_COMMIT := 83d3202b92fb4c2fc6df5b035d57f3a1cf715f20
25
+
26
+ CPYTHON_PATH := ../cpython/
27
+
21
28
LANGUAGE := fr
29
+ BRANCH := 3.8
30
+
31
+
32
+ # Internal variables
33
+
34
+ UPSTREAM := https://github.com/python/cpython
22
35
VENV := $(shell pwd) /venv/
23
36
PYTHON := $(shell which python3)
24
37
MODE := html
25
- BRANCH = 3.8
26
- COMMIT =
27
- JOBS = auto
28
-
38
+ POSPELL_TMP_DIR := .pospell/
39
+ WORKTREES := $( VENV ) /worktrees/
40
+ WORKTREE := $( WORKTREES ) / $( CPYTHON_CURRENT_COMMIT ) /
41
+ JOBS := auto
29
42
30
43
.PHONY : all
31
- all : $(SPHINX_CONF ) $(VENV ) /bin/activate
32
- ifneq "$(shell cd $(CPYTHON_CLONE ) 2>/dev/null && git describe --contains --all HEAD) " "$(BRANCH ) "
33
- $(warning "Your ../cpython checkout may be on the wrong branch, got $(shell cd $(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD) expected $(BRANCH)")
34
- endif
35
- mkdir -p $(CPYTHON_CLONE)/locales/$(LANGUAGE)/
36
- ln -nfs $(shell $(PYTHON) -c 'import os; print(os.path.realpath("."))') $(CPYTHON_CLONE)/locales/$(LANGUAGE)/LC_MESSAGES
37
- $(MAKE) -C $(CPYTHON_CLONE)/Doc/ VENVDIR=$(VENV) PYTHON=$(PYTHON) \
38
- SPHINXOPTS='-qW -j$(JOBS) -D locale_dirs=../locales -D language=$(LANGUAGE) -D gettext_compact=0 -D latex_engine=xelatex -D latex_elements.inputenc= -D latex_elements.fontenc=' \
39
- $(MODE) && echo "Build success, open file://$(CPYTHON_CLONE)/Doc/build/html/index.html or run 'make serve' to see them."
44
+ all : setup
45
+ mkdir -p $(WORKTREE ) /locales/$(LANGUAGE ) /LC_MESSAGES/
46
+ cp --parents * .po * /* .po $(WORKTREE ) /locales/$(LANGUAGE ) /LC_MESSAGES/
47
+ $(MAKE ) -C $(WORKTREE ) /Doc/ VENVDIR=$(WORKTREE ) /Doc/venv/ PYTHON=$(PYTHON ) \
48
+ SPHINXOPTS=' -qW -j$(JOBS) \
49
+ -D locale_dirs=../locales \
50
+ -D language=$(LANGUAGE ) \
51
+ -D gettext_compact=0 \
52
+ -D latex_engine=xelatex \
53
+ -D latex_elements.inputenc= \
54
+ -D latex_elements.fontenc=' \
55
+ $(MODE ) && echo " Build success, open file://$( WORKTREE) /Doc/build/html/index.html or run 'make serve' to see them."
56
+
57
+
58
+ .PHONY : setup
59
+ setup : venv
60
+ # Setup the main clone
61
+ if ! [ -d $( CPYTHON_PATH) ]; then \
62
+ git clone --depth 16 --branch $(BRANCH ) $(UPSTREAM ) $(CPYTHON_PATH ) ; \
63
+ fi
64
+
65
+ # Setup the current worktree
66
+ if ! [ -d $(WORKTREE) ]; then \
67
+ rm -fr $(WORKTREES); \
68
+ git -C $(CPYTHON_PATH) worktree prune; \
69
+ mkdir -p $(WORKTREES); \
70
+ if [ -n "$(CPYTHON_CURRENT_COMMIT)" ]; \
71
+ then \
72
+ depth=32; \
73
+ while ! git -C $(CPYTHON_PATH) cat-file -e $(CPYTHON_CURRENT_COMMIT); \
74
+ do \
75
+ depth=$$((depth * 2)); \
76
+ git -C $(CPYTHON_PATH) fetch --depth $$depth $(UPSTREAM) $(BRANCH); \
77
+ done \
78
+ else \
79
+ git -C $(CPYTHON_PATH) fetch --depth 1 $(UPSTREAM); \
80
+ fi; \
81
+ git -C $(CPYTHON_PATH) worktree add $(WORKTREE)/ $(CPYTHON_CURRENT_COMMIT); \
82
+ $(MAKE) -C $(WORKTREE)/Doc/ VENVDIR=$(WORKTREE)/Doc/venv/ PYTHON=$(PYTHON) venv; \
83
+ fi
84
+
85
+
86
+ .PHONY : venv
87
+ venv :
88
+ @if [ ! -d $( VENV) ]; then $(PYTHON ) -m venv --prompt python-docs-fr $(VENV ) ; fi
89
+ @$(VENV ) /bin/python -m pip install -q -r requirements.txt 2> $(VENV ) /pip-install.log
90
+ @if grep -q ' pip install --upgrade pip' $(VENV ) /pip-install.log; then \
91
+ $(VENV ) /bin/pip install -q --upgrade pip; \
92
+ fi
40
93
41
94
42
95
.PHONY : serve
43
96
serve :
44
- $(MAKE ) -C $(CPYTHON_CLONE ) /Doc/ serve
45
-
46
-
47
- $(SPHINX_CONF ) :
48
- git clone --depth 1 --branch $(BRANCH ) https://github.com/python/cpython.git $(CPYTHON_CLONE )
49
- [ -n " $( COMMIT) " ] && (i=1; while ! $$ (git -C $( CPYTHON_CLONE) checkout $( COMMIT) ); do i=$$ (( i * 2 )) ; git -C $( CPYTHON_CLONE) fetch --depth $$ i; done) || true
50
-
51
-
52
- .PHONY : upgrade_venv
53
- upgrade_venv :
54
- $(MAKE ) -C $(CPYTHON_CLONE ) /Doc/ VENVDIR=$(VENV ) PYTHON=$(PYTHON ) venv
55
- $(VENV ) /bin/pip install -U pip potodo powrap pospell
56
-
57
-
58
- $(VENV ) /bin/activate : $(SPHINX_CONF )
59
- $(MAKE ) -C $(CPYTHON_CLONE ) /Doc/ VENVDIR=$(VENV ) PYTHON=$(PYTHON ) venv
97
+ $(MAKE ) -C $(WORKTREE ) /Doc/ serve
60
98
61
99
62
100
.PHONY : progress
63
101
progress :
64
- @python3 -c ' import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
102
+ @$( PYTHON ) -c ' import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
65
103
$(shell msgcat * .po * /* .po | msgattrib --translated | grep -c '^msgid') \
66
104
$(shell msgcat * .po * /* .po | grep -c '^msgid')
67
105
68
106
69
- $(VENV ) /bin/potodo : $(VENV ) /bin/activate
70
- $(VENV ) /bin/pip install potodo
71
-
72
- $(VENV ) /bin/powrap : $(VENV ) /bin/activate
73
- $(VENV ) /bin/pip install powrap
74
-
75
- $(VENV ) /bin/pospell : $(VENV ) /bin/activate
76
- $(VENV ) /bin/pip install pospell
77
-
78
107
.PHONY : todo
79
- todo : $( VENV ) /bin/potodo
108
+ todo : venv
80
109
$(VENV ) /bin/potodo
81
110
82
- .PHONY : verifs
83
- verifs : wrap spell
84
-
85
111
.PHONY : wrap
86
- wrap : $( VENV ) /bin/powrap
112
+ wrap : venv
87
113
$(VENV ) /bin/powrap --check --quiet * .po ** /* .po
88
114
115
+ SRCS = $(shell git diff --name-only $(BRANCH ) | grep '.po$$')
116
+ # foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out
117
+ DESTS = $(addprefix $(POSPELL_TMP_DIR ) /,$(addsuffix .out,$(SRCS ) ) )
118
+
89
119
.PHONY : spell
90
- spell : $(VENV ) /bin/pospell
91
- $(VENV ) /bin/pospell -p dict -l fr_FR * .po ** /* .po
120
+ spell : venv $(DESTS )
121
+
122
+ $(POSPELL_TMP_DIR ) /% .po.out : % .po dict
123
+ @echo " Checking $<..."
124
+ @mkdir -p $(@D )
125
+ @$(VENV ) /bin/pospell -p dict -l fr_FR $< && touch $@
126
+
127
+ .PHONY : fuzzy
128
+ fuzzy : venv
129
+ $(VENV ) /bin/potodo -f
130
+
131
+ .PHONY : verifs
132
+ verifs : wrap spell
92
133
93
134
.PHONY : merge
94
- merge : upgrade_venv
95
- ifneq "$(shell cd $(CPYTHON_CLONE ) 2>/dev/null && git describe --contains --all HEAD) " "$(BRANCH ) "
96
- $(error "You're merging from a different branch:" "$(shell cd $(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD)" vs "$(BRANCH)")
97
- endif
98
- (cd $(CPYTHON_CLONE)/Doc; rm -f build/NEWS)
99
- (cd $(CPYTHON_CLONE); $(VENV)/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/)
100
- find $(CPYTHON_CLONE)/pot/ -name '*.pot' |\
135
+ merge : setup
136
+ git -C $(CPYTHON_PATH ) fetch $(UPSTREAM )
137
+ rm -fr $(WORKTREES ) /$(BRANCH )
138
+ git -C $(CPYTHON_PATH ) worktree prune
139
+ git -C $(CPYTHON_PATH ) worktree add $(WORKTREES ) /$(BRANCH ) $(word 1,$(shell git -C $(CPYTHON_PATH ) remote -v | grep python/cpython) ) /$(BRANCH )
140
+ $(MAKE ) -C $(WORKTREES ) /$(BRANCH ) /Doc/ VENVDIR=$(WORKTREES ) /$(BRANCH ) /Doc/venv/ PYTHON=$(PYTHON ) venv;
141
+ (cd $( WORKTREES) /$( BRANCH) ; $( WORKTREES) /$( BRANCH) /Doc/venv/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/)
142
+ find $(WORKTREES ) /$(BRANCH ) -name ' *.pot' | \
101
143
while read -r POT; \
102
144
do\
103
- PO="./$$(echo "$$POT" | sed "s# $(CPYTHON_CLONE )/pot/##; s#\.pot\$$#.po#")";\
145
+ PO=" ./$$ (echo " $$ POT" | sed " s#$(WORKTREES ) / $( BRANCH ) /pot/# #; s#\.pot\$$#.po#")";\
104
146
mkdir -p " $$ (dirname " $$ PO" )" ; \
105
147
if [ -f " $$ PO" ]; \
106
148
then\
@@ -112,8 +154,12 @@ endif
112
154
msgcat -o " $$ PO" " $$ POT" ; \
113
155
fi\
114
156
done
115
-
116
-
117
- .PHONY : fuzzy
118
- fuzzy : $(VENV ) /bin/potodo
119
- $(VENV ) /bin/potodo -f
157
+ sed -i ' s/^CPYTHON_CURRENT_COMMIT :=.*/CPYTHON_CURRENT_COMMIT := $(shell git -C $(WORKTREES)/$(BRANCH) rev-parse HEAD)/' Makefile
158
+ rm -fr $(WORKTREES ) /$(BRANCH )
159
+ git -C $(CPYTHON_PATH ) worktree prune
160
+ 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'
161
+
162
+ .PHONY : clean
163
+ clean :
164
+ rm -fr venv $(POSPELL_TMP_DIR )
165
+ find -name ' *.mo' -delete
0 commit comments