Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Makefile, it can build single html now #643

Merged
merged 5 commits into from
Apr 13, 2024

Conversation

griiid
Copy link
Contributor

@griiid griiid commented Sep 3, 2023

更新 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/ 路徑下的檔案
需要大家集思廣益,語法應該要怎麼訂比較好,謝謝。

We still need to make all once, and then we can build single html.
@griiid griiid force-pushed the feature/upgrade-makefile branch from b5b35e5 to 2b1bdc6 Compare September 3, 2023 16:30
@mattwang44 mattwang44 self-requested a review September 4, 2023 16:50
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Remove redundant 'exit 1'
@josix
Copy link
Collaborator

josix commented Sep 13, 2023

現在暫時的語法為 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

@griiid
Copy link
Contributor Author

griiid commented Sep 13, 2023

如果是用參數帶入想要 build 的文件如何?像是 make build howto/annotations.po, make build library/abc.po, etc. 實作的方式可以試試下方的範例

看起來好像不錯,我來改改看

- Get argument as build target.
- Check extension.
- Prevent throwing error when no rule to make target.
@griiid
Copy link
Contributor Author

griiid commented Sep 17, 2023

已經採用 @josix 的方法並 push。
延伸問個問題:希望使用的時候要打後面的 .po 呢,還是不要好呢?

A: VERSION=3.12 make build library/internet.po
B: VERSION=3.12 make build library/internet

目前是 A 方案

@mattwang44
Copy link
Collaborator

Screenshot_20230917-234051

@griiid
Copy link
Contributor Author

griiid commented Sep 18, 2023

@mattwang44 你的意思是想要不管輸入 A 或 B 都可以嗎?

那我這樣子做你覺得如何 (重點是第 2 點):

  1. 如果沒有 target,回傳錯誤。
  2. 如果 target 沒有副檔名,幫他加上 .po 的副檔名。
  3. 如果副檔名不是 .po,回傳錯誤。
  4. 如果 target 不存在,回傳錯誤。

@mattwang44
Copy link
Collaborator

mattwang44 commented Sep 18, 2023

我覺得可以,但想請你也一併考慮未來開發彈性:

  1. 未來有什麼東西是可能基於這個 PR 繼續發展的開發?我隨意舉例(未來不一定需要):
    • 想要下 make build library/* 就能 build 好 library 底下的多份文件的 html
    • 想要下 make build-changed 就能自動幫忙為所有被修改過的文件 build html
  2. 思考與調整目前的實作方向
    • 大概思考這些未來可能想做的東西大概會怎麼實作
    • 不要讓未來實作它們的可能性消失
    • 現在做哪些事情會讓實現他們的可能性更高?

@mattwang44 mattwang44 requested a review from josix September 18, 2023 04:04
Makefile Show resolved Hide resolved
@@ -53,6 +53,35 @@ all: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an
for file in *.po */*.po; do ln -f $$file $(LC_MESSAGES)/$$file; done
. $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D locale_dirs=locales -D language=$(LANGUAGE) -D gettext_compact=0' $(MODE)

.PHONY: build
build: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an html local version
@$(eval target=$(filter-out $@,$(MAKECMDGOALS)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somebody say this might be harmful since the variable is global, maybe I should use some special prefix on the variable name?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, how about naming this with underscore prefix

Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@josix josix merged commit 56d000b into python:3.12 Apr 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants