2017-10-13 20:39:17 +00:00
# Makefile for French Python Documentation
#
# Here is what you can do:
#
# - make # Automatically build an html local version
# - make todo # To list remaining tasks
2019-12-10 10:52:16 +00:00
# - make verifs # To check for correctness: wrapping, spelling
# - make wrap # To check for wrapping
# - make spell # To check for spelling
2017-10-13 20:39:17 +00:00
# - make merge # To merge pot from upstream
# - make fuzzy # To find fuzzy strings
# - make progress # To compute current progression
#
# Modes are: autobuild-stable, autobuild-dev, and autobuild-html,
# documented in gen/src/3.6/Doc/Makefile as we're only delegating the
# real work to the Python Doc Makefile.
2019-12-10 10:52:16 +00:00
# Configuration
# The CPYTHON_CURRENT_COMMIT is the commit, in the cpython repository,
# from which we generated our po files. We use it here so when we
# test build, we're building with the .rst files that generated our
# .po files.
2020-09-11 07:11:46 +00:00
CPYTHON_CURRENT_COMMIT := d7cd1164c18dbf78380ce4c95bf46c7bb0ac0bb7
2019-12-10 10:52:16 +00:00
2019-12-12 10:24:14 +00:00
CPYTHON_PATH := ../cpython/
2019-12-10 10:52:16 +00:00
2017-10-13 20:39:17 +00:00
LANGUAGE := fr
2020-06-05 07:32:47 +00:00
BRANCH := 3.9
2019-12-10 10:52:16 +00:00
2020-06-10 18:16:22 +00:00
EXCLUDED := whatsnew/ c-api/
2020-05-21 13:18:51 +00:00
.SILENT :
2019-12-10 10:52:16 +00:00
# Internal variables
UPSTREAM := https://github.com/python/cpython
2019-12-05 22:58:07 +00:00
VENV := $( shell pwd ) /venv/
2017-10-13 20:39:17 +00:00
PYTHON := $( shell which python3)
2018-11-14 20:47:36 +00:00
MODE := html
2019-12-10 12:57:17 +00:00
POSPELL_TMP_DIR := .pospell/
2019-12-10 10:52:16 +00:00
WORKTREES := $( VENV) /worktrees/
WORKTREE := $( WORKTREES) /$( CPYTHON_CURRENT_COMMIT) /
JOBS := auto
2017-10-13 20:39:17 +00:00
2020-05-30 09:36:13 +00:00
# Detect OS
i f e q '$(findstring ;,$(PATH))' ';'
detected_OS := Windows
e l s e
detected_OS := $( shell uname 2>/dev/null || echo Unknown)
detected_OS := $( patsubst CYGWIN%,Cygwin,$( detected_OS) )
detected_OS := $( patsubst MSYS%,MSYS,$( detected_OS) )
detected_OS := $( patsubst MINGW%,MSYS,$( detected_OS) )
e n d i f
i f e q ( $( detected_OS ) , D a r w i n ) # Mac OS X
CP_CMD := gcp # accessible with `brew install coreutils` or `brew upgrade coreutils`
e l s e
CP_CMD := cp
e n d i f
2017-10-13 20:39:17 +00:00
.PHONY : all
2019-12-10 10:52:16 +00:00
all : setup
mkdir -p $( WORKTREE) /locales/$( LANGUAGE) /LC_MESSAGES/
2020-05-30 09:36:13 +00:00
$( CP_CMD) -uv --parents *.po */*.po $( WORKTREE) /locales/$( LANGUAGE) /LC_MESSAGES/ | cut -d"'" -f2
2019-12-10 10:52:16 +00:00
$( MAKE) -C $( WORKTREE) /Doc/ VENVDIR = $( WORKTREE) /Doc/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) && echo " Build success, open file:// $( WORKTREE) /Doc/build/html/index.html or run 'make serve' to see them. "
.PHONY : setup
setup : venv
2020-07-09 20:17:57 +00:00
echo "Setup the main clone"
2019-12-10 10:52:16 +00:00
if ! [ -d $( CPYTHON_PATH) ] ; then \
git clone --depth 16 --branch $( BRANCH) $( UPSTREAM) $( CPYTHON_PATH) ; \
fi
2020-07-09 20:17:57 +00:00
echo "Setup the current worktree"
2019-12-10 10:52:16 +00:00
if ! [ -d $( WORKTREE) ] ; then \
rm -fr $( WORKTREES) ; \
git -C $( CPYTHON_PATH) worktree prune; \
mkdir -p $( WORKTREES) ; \
if [ -n " $( CPYTHON_CURRENT_COMMIT) " ] ; \
then \
depth = 32; \
2019-12-12 10:59:24 +00:00
while ! git -C $( CPYTHON_PATH) cat-file -e $( CPYTHON_CURRENT_COMMIT) ; \
2019-12-10 10:52:16 +00:00
do \
depth = $$ ( ( depth * 2) ) ; \
2019-12-12 10:59:24 +00:00
git -C $( CPYTHON_PATH) fetch --depth $$ depth $( UPSTREAM) $( BRANCH) ; \
2019-12-10 10:52:16 +00:00
done \
else \
git -C $( CPYTHON_PATH) fetch --depth 1 $( UPSTREAM) ; \
fi ; \
git -C $( CPYTHON_PATH) worktree add $( WORKTREE) / $( CPYTHON_CURRENT_COMMIT) ; \
$( MAKE) -C $( WORKTREE) /Doc/ VENVDIR = $( WORKTREE) /Doc/venv/ PYTHON = $( PYTHON) venv; \
fi
.PHONY : venv
venv :
2020-07-09 20:17:57 +00:00
echo " Setup venv in $( VENV) "
2020-05-21 13:18:51 +00:00
if [ ! -d $( VENV) ] ; then $( PYTHON) -m venv --prompt python-docs-fr $( VENV) ; fi
$( VENV) /bin/python -m pip install -q -r requirements.txt 2> $( VENV) /pip-install.log
if grep -q 'pip install --upgrade pip' $( VENV) /pip-install.log; then \
2019-12-12 08:30:09 +00:00
$( VENV) /bin/pip install -q --upgrade pip; \
fi
2019-11-15 14:09:14 +00:00
.PHONY : serve
serve :
2019-12-10 10:52:16 +00:00
$( MAKE) -C $( WORKTREE) /Doc/ serve
2018-08-01 12:57:26 +00:00
2017-10-13 20:39:17 +00:00
.PHONY : progress
progress :
2020-05-21 13:18:51 +00:00
$( PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
2017-10-26 15:34:21 +00:00
$( shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid' ) \
$( shell msgcat *.po */*.po | grep -c '^msgid' )
2017-10-13 20:39:17 +00:00
.PHONY : todo
2019-12-10 10:52:16 +00:00
todo : venv
2020-06-10 18:16:22 +00:00
$( VENV) /bin/potodo --exclude $( VENV) $( EXCLUDED)
2017-10-13 20:39:17 +00:00
2019-12-04 21:08:12 +00:00
.PHONY : wrap
2019-12-10 10:52:16 +00:00
wrap : venv
2020-07-09 20:17:57 +00:00
echo "Verify wrapping"
2019-11-02 09:26:49 +00:00
$( VENV) /bin/powrap --check --quiet *.po **/*.po
2019-03-30 08:30:23 +00:00
2019-12-10 12:57:17 +00:00
SRCS = $( shell git diff --name-only $( BRANCH) | grep '.po$$' )
# foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out
DESTS = $( addprefix $( POSPELL_TMP_DIR) /,$( addsuffix .out,$( SRCS) ) )
2019-12-04 21:08:12 +00:00
.PHONY : spell
2019-12-12 08:30:09 +00:00
spell : venv $( DESTS )
2019-12-10 12:57:17 +00:00
$(POSPELL_TMP_DIR)/%.po.out : %.po dict
2020-07-09 20:17:57 +00:00
echo " Pospell checking $<... "
2020-05-21 13:18:51 +00:00
mkdir -p $( @D)
$( VENV) /bin/pospell -p dict -l fr_FR $< && touch $@
2019-03-30 08:30:23 +00:00
2019-12-10 10:52:16 +00:00
.PHONY : fuzzy
fuzzy : venv
2020-06-10 18:16:22 +00:00
$( VENV) /bin/potodo -f --exclude $( VENV) $( EXCLUDED)
2019-12-10 10:52:16 +00:00
.PHONY : verifs
verifs : wrap spell
2017-10-13 20:39:17 +00:00
.PHONY : merge
2019-12-10 10:52:16 +00:00
merge : setup
2020-07-09 20:17:57 +00:00
echo " Merge from $( UPSTREAM) "
2019-12-10 10:52:16 +00:00
git -C $( CPYTHON_PATH) fetch $( UPSTREAM)
rm -fr $( WORKTREES) /$( BRANCH)
git -C $( CPYTHON_PATH) worktree prune
git -C $( CPYTHON_PATH) worktree add $( WORKTREES) /$( BRANCH) $( word 1,$( shell git -C $( CPYTHON_PATH) remote -v | grep python/cpython) ) /$( BRANCH)
$( MAKE) -C $( WORKTREES) /$( BRANCH) /Doc/ VENVDIR = $( WORKTREES) /$( BRANCH) /Doc/venv/ PYTHON = $( PYTHON) venv;
2020-07-20 08:31:23 +00:00
( cd $( WORKTREES) /$( BRANCH) /Doc; $( WORKTREES) /$( BRANCH) /Doc/venv/bin/sphinx-build -Q -b gettext -D gettext_compact = 0 . ../pot)
2019-12-10 10:52:16 +00:00
find $( WORKTREES) /$( BRANCH) -name '*.pot' | \
2017-10-13 20:39:17 +00:00
while read -r POT; \
do \
2019-12-10 10:52:16 +00:00
PO = " ./ $$ (echo " $$ POT" | sed " s#$( WORKTREES) /$( BRANCH) /pot/##; s#\. pot\$ $# .po#")" ; \
2017-10-13 20:39:17 +00:00
mkdir -p " $$ (dirname " $$ PO")" ; \
if [ -f " $$ PO " ] ; \
then \
2018-05-01 22:09:15 +00:00
case " $$ POT " in\
*whatsnew*) msgmerge --backup= off --force-po --no-fuzzy-matching -U " $$ PO " " $$ POT " ; ; \
*) msgmerge --backup= off --force-po -U " $$ PO " " $$ POT " ; ; \
esac \
2017-10-13 20:39:17 +00:00
else \
msgcat -o " $$ PO " " $$ POT " ; \
fi \
done
2020-07-20 08:56:42 +00:00
echo "Replacing CPYTHON_CURRENT_COMMIT Makefile by: " $( shell git -C $( WORKTREES) /$( BRANCH) rev-parse HEAD)
2019-12-10 10:52:16 +00:00
sed -i 's/^CPYTHON_CURRENT_COMMIT :=.*/CPYTHON_CURRENT_COMMIT := $(shell git -C $(WORKTREES)/$(BRANCH) rev-parse HEAD)/' Makefile
rm -fr $( WORKTREES) /$( BRANCH)
git -C $( CPYTHON_PATH) worktree prune
2020-07-20 08:45:25 +00:00
sed -i 's|^#: .*Doc/|#: |' *.po */*.po
-$( VENV) /bin/powrap -m
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'
2019-12-10 10:52:16 +00:00
.PHONY : clean
clean :
2020-07-09 20:17:57 +00:00
echo " Cleaning *.mo, $( VENV) , and $( POSPELL_TMP_DIR) "
2020-05-21 13:18:51 +00:00
rm -fr $( VENV) $( POSPELL_TMP_DIR)
2019-12-10 10:52:16 +00:00
find -name '*.mo' -delete