|
| 1 | +# Makefile for French 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 merge # To merge pot from upstream |
| 8 | +# - make fuzzy # To find fuzzy strings |
| 9 | +# - make progress # To compute current progression |
| 10 | +# - make upgrade_venv # To upgrade the venv that compiles the doc |
| 11 | +# |
| 12 | +# Modes are: autobuild-stable, autobuild-dev, and autobuild-html, |
| 13 | +# documented in gen/src/3.6/Doc/Makefile as we're only delegating the |
| 14 | +# real work to the Python Doc Makefile. |
| 15 | + |
| 16 | +CPYTHON_CLONE := ../cpython/ |
| 17 | +SPHINX_CONF := $(CPYTHON_CLONE)/Doc/conf.py |
| 18 | +LANGUAGE := fr |
| 19 | +VENV := ~/.venvs/python-docs-i18n/ |
| 20 | +PYTHON := $(shell which python3) |
| 21 | +MODE := autobuild-dev-html |
| 22 | +BRANCH = $(shell git describe --contains --all HEAD) |
| 23 | +JOBS = 1 |
| 24 | + |
| 25 | + |
| 26 | +.PHONY: all |
| 27 | +all: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb $(SPHINX_CONF) |
| 28 | + mkdir -p $(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/ |
| 29 | + ln -nfs $(shell readlink -f .) $(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/LC_MESSAGES |
| 30 | + . $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D locale_dirs=locales -D language=$(LANGUAGE) -D gettext_compact=0' $(MODE) |
| 31 | + |
| 32 | + |
| 33 | +$(SPHINX_CONF): |
| 34 | + git clone --depth 1 --no-single-branch https://github.com/python/cpython.git $(CPYTHON_CLONE) |
| 35 | + |
| 36 | + |
| 37 | +$(VENV)/bin/activate: |
| 38 | + mkdir -p $(VENV) |
| 39 | + $(PYTHON) -m venv $(VENV) |
| 40 | + |
| 41 | + |
| 42 | +$(VENV)/bin/sphinx-build: $(VENV)/bin/activate |
| 43 | + . $(VENV)/bin/activate; python3 -m pip install sphinx |
| 44 | + |
| 45 | + |
| 46 | +$(VENV)/bin/blurb: $(VENV)/bin/activate |
| 47 | + . $(VENV)/bin/activate; python3 -m pip install blurb |
| 48 | + |
| 49 | + |
| 50 | +.PHONY: upgrade_venv |
| 51 | +upgrade_venv: $(VENV)/bin/activate |
| 52 | + . $(VENV)/bin/activate; python3 -m pip install --upgrade sphinx blurb |
| 53 | + |
| 54 | + |
| 55 | +.PHONY: progress |
| 56 | +progress: |
| 57 | + @python3 -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \ |
| 58 | + $(shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid') \ |
| 59 | + $(shell msgcat *.po */*.po | grep -c '^msgid') |
| 60 | + |
| 61 | + |
| 62 | +.PHONY: todo |
| 63 | +todo: |
| 64 | + for file in *.po */*.po; do echo $$(msgattrib --untranslated $$file | grep ^msgid | sed 1d | wc -l ) $$file; done | grep -v ^0 | sort -gr |
| 65 | + |
| 66 | + |
| 67 | +.PHONY: merge |
| 68 | +merge: upgrade_venv |
| 69 | +ifneq "$(shell cd $(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD)" "$(BRANCH)" |
| 70 | + $(error "You're merging from a different branch") |
| 71 | +endif |
| 72 | + (cd $(CPYTHON_CLONE)/Doc; rm -f build/NEWS) |
| 73 | + (cd $(CPYTHON_CLONE); $(VENV)/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/) |
| 74 | + find $(CPYTHON_CLONE)/pot/ -name '*.pot' |\ |
| 75 | + while read -r POT;\ |
| 76 | + do\ |
| 77 | + PO="./$$(echo "$$POT" | sed "s#$(CPYTHON_CLONE)/pot/##; s#\.pot\$$#.po#")";\ |
| 78 | + mkdir -p "$$(dirname "$$PO")";\ |
| 79 | + if [ -f "$$PO" ];\ |
| 80 | + then\ |
| 81 | + case "$$POT" in\ |
| 82 | + *whatsnew*) msgmerge --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\ |
| 83 | + *) msgmerge --backup=off --force-po -U "$$PO" "$$POT" ;;\ |
| 84 | + esac\ |
| 85 | + else\ |
| 86 | + msgcat -o "$$PO" "$$POT";\ |
| 87 | + fi\ |
| 88 | + done |
| 89 | + |
| 90 | + |
| 91 | +.PHONY: fuzzy |
| 92 | +fuzzy: |
| 93 | + for file in *.po */*.po; do echo $$(msgattrib --only-fuzzy --no-obsolete "$$file" | grep -c '#, fuzzy') $$file; done | grep -v ^0 | sort -gr |
0 commit comments