33# Here is what you can do:
44#
55# - make all # Automatically build an html local version
6+ # - make build <po-file> # To build a single .po file
67# - make todo # To list remaining tasks
78# - make merge # To merge pot from upstream
89# - make fuzzy # To find fuzzy strings
@@ -36,35 +37,59 @@ print('\n'.join(output))
3637endef
3738export PRINT_HELP_PYSCRIPT # End of python section
3839
39- CPYTHON_CLONE := ../cpython/
40+ CPYTHON_CLONE := ../cpython
41+ VERSION := $(or $(VERSION ) , 3.12)
4042SPHINX_CONF := $(CPYTHON_CLONE ) /Doc/conf.py
4143LANGUAGE := zh_TW
4244LC_MESSAGES := $(CPYTHON_CLONE ) /Doc/locales/$(LANGUAGE ) /LC_MESSAGES
4345VENV := ~/.venvs/python-docs-i18n/
44- PYTHON := $(shell which python3)
4546MODE := autobuild-dev-html
46- BRANCH := $(or $(VERSION ) , $(shell git describe --contains --all HEAD) )
4747JOBS := 4
4848
4949.PHONY : all
50- all : $(VENV ) /bin/sphinx-build $(VENV ) /bin/blurb clone # # Automatically build an html local version
51- mkdir -p $(LC_MESSAGES )
50+ all : prepare_deps # # Automatically build an html local version
5251 for dirname in $$ (find . -name ' *.po' | xargs -n1 dirname | sort -u | grep -v ' ^\.$$' ); do mkdir -p $( LC_MESSAGES) /$$ dirname; done
5352 for file in * .po * /* .po; do ln -f $$ file $( LC_MESSAGES) /$$ file; done
5453 . $(VENV ) /bin/activate; $(MAKE ) -C $(CPYTHON_CLONE ) /Doc/ SPHINXOPTS=' -j$(JOBS) -D locale_dirs=locales -D language=$(LANGUAGE) -D gettext_compact=0' $(MODE )
5554
55+ .PHONY : build
56+ build : prepare_deps # # Automatically build an html local version for a single file
57+ @$(eval target=$(filter-out $@ ,$(MAKECMDGOALS ) ) )
58+ @if [ -z $( target) ]; then \
59+ echo " \x1B[1;31m" " Please provide a file argument." " \x1B[m" ; \
60+ exit 1; \
61+ fi
62+ @if [ " $( suffix $( target) ) " != " .po" ]; then \
63+ echo " \x1B[1;31m" " Incorrect file extension. Only '.po' files are allowed." " \x1B[m" ; \
64+ exit 1; \
65+ fi
66+ @if [[ ! -f " $( target) " ]] ; then \
67+ echo " \x1B[1;31m" " ERROR: $( target) not exist." " \x1B[m" ; \
68+ exit 1; \
69+ fi
70+
71+ @$(eval dir=`echo $(target) | xargs -n1 dirname`) # # Get dir
72+ @mkdir -p $(LC_MESSAGES)/$(dir)
73+ @ln -f ./$(target) $(LC_MESSAGES)/$(target)
74+
75+ @. $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D language=$(LANGUAGE) -D locale_dirs=locales -D gettext_compact=0' SOURCES='$(basename $(target)).rst' html
76+
77+
5678help :
5779 @python3 -c " $$ PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST )
5880
59- clone : # # Clone latest cpython repository to `../cpython/` if it doesn't exist
81+ .PHONY : prepare_deps
82+ prepare_deps : $(VENV ) /bin/sphinx-build $(VENV ) /bin/blurb upgrade_venv prepare_cpython # # Prepare dependencies
83+
84+ .PHONY : prepare_cpython
85+ prepare_cpython : # # Prepare CPython clone at `../cpython/`.
6086 git clone --depth 1 --no-single-branch https://github.com/python/cpython.git $(CPYTHON_CLONE ) || echo " cpython exists"
61- cd $(CPYTHON_CLONE ) && git checkout $(BRANCH )
87+ cd $(CPYTHON_CLONE ) && git checkout $(VERSION ) && git pull origin $(VERSION )
88+ mkdir -p $(LC_MESSAGES )
6289
6390
6491$(VENV ) /bin/activate :
65- mkdir -p $(VENV )
66- $(PYTHON ) -m venv $(VENV )
67-
92+ python3 -m venv $(VENV )
6893
6994$(VENV ) /bin/sphinx-build : $(VENV ) /bin/activate
7095 . $(VENV ) /bin/activate; python3 -m pip install sphinx python-docs-theme
@@ -78,7 +103,7 @@ $(VENV)/bin/blurb: $(VENV)/bin/activate
78103
79104.PHONY : upgrade_venv
80105upgrade_venv : $(VENV ) /bin/activate # # Upgrade the venv that compiles the doc
81- . $(VENV ) /bin/activate; python3 -m pip install --upgrade sphinx python-docs-theme blurb sphinx-lint
106+ @ . $(VENV ) /bin/activate; python3 -m pip install -q --upgrade sphinx python-docs-theme blurb sphinx-lint
82107
83108
84109.PHONY : progress
@@ -94,10 +119,7 @@ todo: ## List remaining tasks
94119
95120
96121.PHONY : merge
97- merge : upgrade_venv # # To merge pot from upstream
98- ifneq "$(shell cd $(CPYTHON_CLONE ) 2>/dev/null && git describe --contains --all HEAD) " "$(BRANCH ) "
99- $(error "You're merging from a different branch")
100- endif
122+ merge : prepare_deps # # To merge pot from upstream
101123 (cd $( CPYTHON_CLONE) /Doc; rm -f build/NEWS)
102124 (cd $( CPYTHON_CLONE) /Doc; $( VENV) /bin/sphinx-build -Q -b gettext -D gettext_compact=0 . locales/pot/)
103125 find $(CPYTHON_CLONE ) /Doc/locales/pot/ -name ' *.pot' | \
@@ -116,7 +138,7 @@ endif
116138
117139.PHONY : update_txconfig
118140update_txconfig :
119- curl -L https://rawgit.com/python-doc-ja/cpython-doc-catalog/catalog-$(BRANCH ) /Doc/locales/.tx/config | \
141+ curl -L https://rawgit.com/python-doc-ja/cpython-doc-catalog/catalog-$(VERSION ) /Doc/locales/.tx/config | \
120142 grep --invert-match ' ^file_filter = *' | \
121143 sed -e ' s/source_file = pot\/\(.*\)\.pot/trans.zh_TW = \1.po/' | \
122144 sed -n ' w .tx/config'
@@ -133,3 +155,7 @@ rm_cpython: ## Remove cloned cpython repo
133155.PHONY : lint
134156lint : $(VENV ) /bin/sphinx-lint # # Run sphinx-lint
135157 $(VENV ) /bin/sphinx-lint --enable default-role
158+
159+ # This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error)
160+ % :
161+ @:
0 commit comments