python-docs-zh-tw
python-docs-zh-tw copied to clipboard
Upgrade Makefile, it can build single html now
更新 Makefile 讓他可以只轉換單一 html 檔。
指令為:VERSION=3.12 make build/<path-to-file>
例如:VERSION=3.12 make build/library/internet,就是要 build library/internet.po 的檔案
目前的版本需要大家至少有 make all 一次,之後才能夠使用 make build/<path-to-file> 來轉換單一 html 檔。
如果 clone 後沒有 make all 過,會失敗;這個問題暫時還找不到解法,附上遇到的錯誤訊息如下:
Traceback (most recent call last):
File "/Users/griiid/.venvs/python-docs-i18n/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 937, in load_indexer
with open(searchindexfn, encoding='utf-8') as ft:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/griiid/test/cpython/Doc/build/html/searchindex.js'
需要討論:
現在暫時的語法為 make build/<path-to-file>,會看起來很像是要 make build/ 路徑下的檔案
需要大家集思廣益,語法應該要怎麼訂比較好,謝謝。
現在暫時的語法為 make build/
,會看起來很像是要 make build/ 路徑下的檔案 需要大家集思廣益,語法應該要怎麼訂比較好,謝謝。
如果是用參數帶入想要 build 的文件如何?像是 make build howto/annotations.po, make build library/abc.po, etc.
實作的方式可以試試下方的範例
build: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an html local version
if [ -z $(filter-out $@,$(MAKECMDGOALS)) ]; then \
echo "Please provide a file argument."; \
exit 1; \
fi
if [ ! -f "$(filter-out $@,$(MAKECMDGOALS))" ]; then \
echo "File '$(filter-out $@,$(MAKECMDGOALS))' does not exist."; \
exit 1; \
fi
if [ "$(suffix $(filter-out $@,$(MAKECMDGOALS)))" != ".po" ]; then \
echo "Incorrect file extension. Only '.po' files are allowed."; \
exit 1; \
fi
@mkdir -p $(LC_MESSAGES)
@$(eval dir=`echo $* | xargs -n1 dirname`) ## Get dir
# If the build target is in under directory
# We should make direcotry in $(LC_MESSAGES) and link the file.
@if [ $(dir) != "." ]; then \
echo "mkdir -p $(LC_MESSAGES)/$(dir)"; \
mkdir -p $(LC_MESSAGES)/$(dir); \
echo "ln -f ./$*.po $(LC_MESSAGES)/$*.po"; \
ln -f ./$*.po $(LC_MESSAGES)/$*.po; \
fi
# Build
@echo "----"
@. $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D language=$(LANGUAGE) -D locale_dirs=locales -D gettext_compact=0' SOURCES="$(basename $(filter-out $@,$(MAKECMDGOALS))).rst" html
如果是用參數帶入想要 build 的文件如何?像是
make build howto/annotations.po,make build library/abc.po, etc. 實作的方式可以試試下方的範例
看起來好像不錯,我來改改看
已經採用 @josix 的方法並 push。
延伸問個問題:希望使用的時候要打後面的 .po 呢,還是不要好呢?
A: VERSION=3.12 make build library/internet.po
B: VERSION=3.12 make build library/internet
目前是 A 方案
@mattwang44 你的意思是想要不管輸入 A 或 B 都可以嗎?
那我這樣子做你覺得如何 (重點是第 2 點):
- 如果沒有 target,回傳錯誤。
- 如果 target 沒有副檔名,幫他加上
.po的副檔名。 - 如果副檔名不是
.po,回傳錯誤。 - 如果 target 不存在,回傳錯誤。
我覺得可以,但想請你也一併考慮未來開發彈性:
- 未來有什麼東西是可能基於這個 PR 繼續發展的開發?我隨意舉例(未來不一定需要):
- 想要下
make build library/*就能 build 好 library 底下的多份文件的 html - 想要下
make build-changed就能自動幫忙為所有被修改過的文件 build html
- 想要下
- 思考與調整目前的實作方向
- 大概思考這些未來可能想做的東西大概會怎麼實作
- 不要讓未來實作它們的可能性消失
- 現在做哪些事情會讓實現他們的可能性更高?