Skip to content

Commit 45d76f2

Browse files
committed
Aggiornamento .po files
1 parent b201506 commit 45d76f2

File tree

1 file changed

+139
-51
lines changed

1 file changed

+139
-51
lines changed

Makefile

+139-51
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,173 @@
1-
# Makefile for {{cookiecutter.language}} Python Documentation
1+
# Makefile for italian Python Documentation
22
#
33
# Here is what you can do:
44
#
5-
# - make # Automatically build an html local version
5+
# - make # Automatically build an HTML local version
66
# - 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
710
# - make merge # To merge pot from upstream
811
# - make fuzzy # To find fuzzy strings
912
# - make progress # To compute current progression
10-
# - make upgrade_venv # To upgrade the venv that compiles the doc
1113
#
1214
# Modes are: autobuild-stable, autobuild-dev, and autobuild-html,
1315
# documented in gen/src/3.6/Doc/Makefile as we're only delegating the
1416
# real work to the Python Doc Makefile.
1517

16-
CPYTHON_CLONE := ../cpython/
17-
SPHINX_CONF := $(CPYTHON_CLONE)/Doc/conf.py
18-
LANGUAGE := it_IT
19-
VENV := ~/.venvs/python-docs-i18n/
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 := 7a9534f595ccd9f2bdea5ceeecb837a82e44c620
25+
26+
CPYTHON_PATH := ../cpython/
27+
28+
LANGUAGE := it
29+
BRANCH := 3.13
30+
31+
EXCLUDED := whatsnew/ c-api/
32+
33+
# Internal variables
34+
35+
UPSTREAM := https://github.com/python/cpython
36+
2037
PYTHON := $(shell which python3)
2138
MODE := html
22-
BRANCH = 3.11
23-
COMMIT =
24-
JOBS = auto
39+
POSPELL_TMP_DIR := .pospell/
40+
JOBS := auto
2541

42+
# Detect OS
2643

27-
.PHONY: all
28-
all: $(SPHINX_CONF) $(VENV)/bin/activate
29-
ifneq "$(shell cd $(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD)" "$(BRANCH)"
30-
$(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)")
44+
ifeq '$(findstring ;,$(PATH))' ';'
45+
detected_OS := Windows
46+
else
47+
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
48+
detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS))
49+
detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS))
50+
detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS))
3151
endif
32-
mkdir -p $(CPYTHON_CLONE)/locales/$(LANGUAGE)/
33-
ln -nfs $(shell $(PYTHON) -c 'import os; print(os.path.realpath("."))') $(CPYTHON_CLONE)/locales/$(LANGUAGE)/LC_MESSAGES
34-
$(MAKE) -C $(CPYTHON_CLONE)/Doc/ VENVDIR=$(VENV) PYTHON=$(PYTHON) 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=' $(MODE)
35-
3652

37-
$(SPHINX_CONF):
38-
git clone --depth 1 --branch $(BRANCH) https://github.com/python/cpython.git $(CPYTHON_CLONE)
39-
[ -n "$(COMMIT)" ] && (i=1; while ! $$(git -C $(CPYTHON_CLONE) checkout $(COMMIT)); do i=$$((i * 2)); git -C $(CPYTHON_CLONE) fetch --depth $$i; done) || true
53+
ifeq ($(detected_OS),Darwin) # Mac OS X
54+
CP_CMD := gcp # accessible with `brew install coreutils` or `brew upgrade coreutils`
55+
else
56+
CP_CMD := cp
57+
endif
4058

59+
.PHONY: all
60+
all: ensure_prerequisites
61+
git -C $(CPYTHON_PATH) checkout $(CPYTHON_CURRENT_COMMIT)
62+
mkdir -p locales/$(LANGUAGE)/LC_MESSAGES/
63+
$(CP_CMD) -u --parents *.po */*.po locales/$(LANGUAGE)/LC_MESSAGES/
64+
$(MAKE) -C $(CPYTHON_PATH)/Doc/ \
65+
SPHINXOPTS='-qW -j$(JOBS) \
66+
-D locale_dirs=$(abspath locales) \
67+
-D language=$(LANGUAGE) \
68+
-D gettext_compact=0 \
69+
-D latex_engine=xelatex \
70+
-D latex_elements.inputenc= \
71+
-D latex_elements.fontenc=' \
72+
$(MODE)
73+
git -C $(CPYTHON_PATH) checkout -
74+
@echo "Build success, open file://$(abspath $(CPYTHON_PATH))/Doc/build/html/index.html or run 'make serve' to see them."
4175

42-
.PHONY: upgrade_venv
43-
upgrade_venv:
44-
$(MAKE) -C $(CPYTHON_CLONE)/Doc/ VENVDIR=$(VENV) PYTHON=$(PYTHON) venv
4576

77+
.PHONY: ensure_prerequisites
78+
ensure_prerequisites:
79+
@if [ -z $(CPYTHON_PATH) ]; then \
80+
echo "Your CPYTHON_PATH is empty, please provide one."; \
81+
exit 1; \
82+
fi
83+
@if ! [ -d $(CPYTHON_PATH) ]; then \
84+
echo "Building the translation requires a cpython clone."; \
85+
echo "Please provide the path to a clone using the CPYTHON_PATH variable."; \
86+
echo "(Currently CPYTHON_PATH is $(CPYTHON_PATH)."; \
87+
echo "So you may want to run:"; \
88+
echo ""; \
89+
echo " git clone $(UPSTREAM) $(CPYTHON_PATH)"; \
90+
exit 1; \
91+
fi
92+
@if [ -n "$$(git -C $(CPYTHON_PATH) status --porcelain)" ]; then \
93+
echo "Your cpython clone at $(CPYTHON_PATH) is not clean."; \
94+
echo "In order to avoid breaking things, please clean it first."; \
95+
exit 1; \
96+
fi
97+
@if ! (blurb help >/dev/null 2>&1 && sphinx-build --version >/dev/null 2>&1); then \
98+
git -C $(CPYTHON_PATH) checkout $(BRANCH); \
99+
echo "You're missing dependencies, please enable a venv and install:"; \
100+
echo ""; \
101+
echo " python -m pip install -r requirements.txt -r $(CPYTHON_PATH)/Doc/requirements.txt"; \
102+
exit 1; \
103+
fi
46104

47-
$(VENV)/bin/activate:
48-
$(MAKE) -C $(CPYTHON_CLONE)/Doc/ VENVDIR=$(VENV) PYTHON=$(PYTHON) venv
105+
.PHONY: serve
106+
serve:
107+
$(MAKE) -C $(CPYTHON_PATH)/Doc/ serve
49108

50109

51110
.PHONY: progress
52111
progress:
53-
@python3 -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
112+
@$(PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
54113
$(shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid') \
55114
$(shell msgcat *.po */*.po | grep -c '^msgid')
56115

57116

117+
.PHONY: todo
118+
todo: ensure_prerequisites
119+
potodo --exclude venv .venv $(EXCLUDED)
120+
121+
.PHONY: wrap
122+
wrap: ensure_prerequisites
123+
@echo "Verify wrapping"
124+
powrap --check --quiet *.po **/*.po
125+
126+
SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$')
127+
# foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out
128+
DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS)))
129+
130+
.PHONY: spell
131+
spell: ensure_prerequisites $(DESTS)
132+
133+
$(POSPELL_TMP_DIR)/%.po.out: %.po dict
134+
@echo "Pospell checking $<..."
135+
mkdir -p $(@D)
136+
pospell -p dict -l fr_FR $< && touch $@
137+
138+
.PHONY: fuzzy
139+
fuzzy: ensure_prerequisites
140+
potodo -f --exclude venv .venv $(EXCLUDED)
141+
142+
.PHONY: verifs
143+
verifs: wrap spell
144+
58145
.PHONY: merge
59-
merge: upgrade_venv
60-
ifneq "$(shell cd $(CPYTHON_CLONE) 2>/dev/null && git branch --show-current)" "$(BRANCH)"
61-
$(error "You're merging from a different branch:" "$(shell cd $(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD)" vs "$(BRANCH)")
62-
endif
63-
(cd $(CPYTHON_CLONE)/Doc; rm -f build/NEWS)
64-
(cd $(CPYTHON_CLONE); $(VENV)/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/)
65-
find $(CPYTHON_CLONE)/pot/ -name '*.pot' |\
66-
while read -r POT;\
67-
do\
68-
PO="./$$(echo "$$POT" | sed "s#$(CPYTHON_CLONE)/pot/##; s#\.pot\$$#.po#")";\
69-
mkdir -p "$$(dirname "$$PO")";\
70-
if [ -f "$$PO" ];\
71-
then\
72-
case "$$POT" in\
73-
*whatsnew*) msgmerge --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
74-
*) msgmerge --backup=off --force-po -U "$$PO" "$$POT" ;;\
75-
esac\
76-
else\
77-
msgcat -o "$$PO" "$$POT";\
78-
fi\
146+
merge: ensure_prerequisites
147+
@echo "Merge from $(UPSTREAM)"
148+
git -C $(CPYTHON_PATH) checkout $(BRANCH)
149+
git -C $(CPYTHON_PATH) pull --ff-only
150+
(cd $(CPYTHON_PATH)/Doc; sphinx-build -Q -b gettext -D gettext_compact=0 . ../pot)
151+
find $(CPYTHON_PATH)/pot/ -name '*.pot' |\
152+
while read -r POT; \
153+
do \
154+
PO="./$$(echo "$$POT" | sed "s#$(CPYTHON_PATH)/pot/##; s#\.pot\$$#.po#")"; \
155+
mkdir -p "$$(dirname "$$PO")"; \
156+
if [ -f "$$PO" ]; \
157+
then \
158+
msgmerge --backup=off --force-po -U "$$PO" "$$POT"; \
159+
else \
160+
msgcat -o "$$PO" "$$POT"; \
161+
fi \
79162
done
163+
rm -fr $(CPYTHON_PATH)/pot/
164+
sed -i 's|^#: .*Doc/|#: |' *.po */*.po
80165
powrap -m
166+
@printf "\n%s %s\n" "Replace CPYTHON_CURRENT_COMMIT in Makefile by: " $(shell git -C $(CPYTHON_PATH) rev-parse HEAD)
167+
@printf 'To add, you can use:\n 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\n'
81168

82-
83-
.PHONY: fuzzy
84-
fuzzy:
85-
for file in *.po */*.po; do echo $$(msgattrib --only-fuzzy --no-obsolete "$$file" | grep -c '#, fuzzy') $$file; done | grep -v ^0 | sort -gr
169+
.PHONY: clean
170+
clean:
171+
@echo "Cleaning *.mo and $(POSPELL_TMP_DIR)"
172+
rm -fr $(POSPELL_TMP_DIR)
173+
find -name '*.mo' -delete

0 commit comments

Comments
 (0)