Skip to content

Commit cd559e6

Browse files
committed
Initial commit
0 parents  commit cd559e6

File tree

2 files changed

+475
-0
lines changed

2 files changed

+475
-0
lines changed

Makefile

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Makefile for tr Python Documentation
2+
#
3+
# Here is what you can do:
4+
#
5+
# - make # Automatically build an HTML local version
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
10+
# - make merge # To merge pot from upstream
11+
# - make fuzzy # To find fuzzy strings
12+
# - make progress # To compute current progression
13+
#
14+
# Modes are: autobuild-stable, autobuild-dev, and autobuild-html,
15+
# documented in gen/src/3.6/Doc/Makefile as we're only delegating the
16+
# real work to the Python Doc Makefile.
17+
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 := eec8e61992fb654d4cf58de4d727c18622b8303e
25+
26+
CPYTHON_PATH := ../cpython/
27+
28+
LANGUAGE := tr
29+
BRANCH := 3.9
30+
31+
EXCLUDED := whatsnew/ c-api/
32+
33+
# Internal variables
34+
35+
UPSTREAM := https://github.com/python/cpython
36+
37+
PYTHON := $(shell which python3)
38+
MODE := html
39+
POSPELL_TMP_DIR := .pospell/
40+
JOBS := auto
41+
42+
# Detect OS
43+
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))
51+
endif
52+
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
58+
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."
75+
76+
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
104+
105+
.PHONY: serve
106+
serve:
107+
$(MAKE) -C $(CPYTHON_PATH)/Doc/ serve
108+
109+
110+
.PHONY: progress
111+
progress:
112+
@$(PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
113+
$(shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid') \
114+
$(shell msgcat *.po */*.po | grep -c '^msgid')
115+
116+
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+
145+
.PHONY: merge
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 \
162+
done
163+
rm -fr $(CPYTHON_PATH)/pot/
164+
sed -i 's|^#: .*Doc/|#: |' *.po */*.po
165+
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'
168+
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)