Skip to content

Commit

Permalink
refactor(make): organize preparation directives
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 committed Jun 2, 2024
1 parent e54aa0a commit 6f4b68f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ SPHINX_CONF := $(CPYTHON_CLONE)/Doc/conf.py
LANGUAGE := zh_TW
LC_MESSAGES := $(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/LC_MESSAGES
VENV := ~/.venvs/python-docs-i18n/
PYTHON := $(shell which python3)
MODE := autobuild-dev-html
JOBS := 4

.PHONY: all
all: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an html local version
mkdir -p $(LC_MESSAGES)
all: prepare_deps ## Automatically build an html local version
for dirname in $$(find . -name '*.po' | xargs -n1 dirname | sort -u | grep -v '^\.$$'); do mkdir -p $(LC_MESSAGES)/$$dirname; done
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 for a single file
build: prepare_deps ## Automatically build an html local version for a single file
@$(eval target=$(filter-out $@,$(MAKECMDGOALS)))
@if [ -z $(target) ]; then \
echo "\x1B[1;31m""Please provide a file argument.""\x1B[m"; \
Expand All @@ -80,15 +78,18 @@ build: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build a
help:
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

clone: ## Clone latest cpython repository to `../cpython/` if it doesn't exist
.PHONY: prepare_deps
prepare_deps: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb upgrade_venv prepare_cpython ## Prepare dependencies

.PHONY: prepare_cpython
prepare_cpython: ## Prepare CPython clone at `../cpython/`.
git clone --depth 1 --no-single-branch https://github.com/python/cpython.git $(CPYTHON_CLONE) || echo "cpython exists"
cd $(CPYTHON_CLONE) && git checkout $(VERSION)
cd $(CPYTHON_CLONE) && git checkout $(VERSION) && git pull origin $(VERSION)
mkdir -p $(LC_MESSAGES)


$(VENV)/bin/activate:
mkdir -p $(VENV)
$(PYTHON) -m venv $(VENV)

python3 -m venv $(VENV)

$(VENV)/bin/sphinx-build: $(VENV)/bin/activate
. $(VENV)/bin/activate; python3 -m pip install sphinx python-docs-theme
Expand All @@ -102,7 +103,7 @@ $(VENV)/bin/blurb: $(VENV)/bin/activate

.PHONY: upgrade_venv
upgrade_venv: $(VENV)/bin/activate ## Upgrade the venv that compiles the doc
. $(VENV)/bin/activate; python3 -m pip install --upgrade sphinx python-docs-theme blurb sphinx-lint
@. $(VENV)/bin/activate; python3 -m pip install -q --upgrade sphinx python-docs-theme blurb sphinx-lint


.PHONY: progress
Expand All @@ -118,7 +119,7 @@ todo: ## List remaining tasks


.PHONY: merge
merge: upgrade_venv ## To merge pot from upstream
merge: prepare_deps ## To merge pot from upstream
(cd $(CPYTHON_CLONE)/Doc; rm -f build/NEWS)
(cd $(CPYTHON_CLONE)/Doc; $(VENV)/bin/sphinx-build -Q -b gettext -D gettext_compact=0 . locales/pot/)
find $(CPYTHON_CLONE)/Doc/locales/pot/ -name '*.pot' |\
Expand Down

0 comments on commit 6f4b68f

Please sign in to comment.