Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ca5428

Browse files
committed
Simplify Makefile
1 parent 02aa080 commit 1ca5428

File tree

3 files changed

+76
-90
lines changed

3 files changed

+76
-90
lines changed

Makefile

Lines changed: 73 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Here is what you can do:
44
#
5-
# - make # Automatically build an html local version
5+
# - make # Automatically build an HTML local version
66
# - make todo # To list remaining tasks
77
# - make verifs # To check for correctness: wrapping, spelling
88
# - make wrap # To check for wrapping
@@ -33,12 +33,10 @@ EXCLUDED := whatsnew/ c-api/
3333
# Internal variables
3434

3535
UPSTREAM := https://github.com/python/cpython
36-
VENV := $(shell pwd)/venv/
36+
3737
PYTHON := $(shell which python3)
3838
MODE := html
3939
POSPELL_TMP_DIR := .pospell/
40-
WORKTREES := $(VENV)/worktrees/
41-
WORKTREE := $(WORKTREES)/$(CPYTHON_CURRENT_COMMIT)/
4240
JOBS := auto
4341

4442
# Detect OS
@@ -59,132 +57,120 @@ else
5957
endif
6058

6159
.PHONY: all
62-
all: setup
63-
mkdir -p $(WORKTREE)/locales/$(LANGUAGE)/LC_MESSAGES/
64-
$(CP_CMD) -uv --parents *.po */*.po $(WORKTREE)/locales/$(LANGUAGE)/LC_MESSAGES/ | cut -d"'" -f2
65-
$(MAKE) -C $(WORKTREE)/Doc/ VENVDIR=$(WORKTREE)/Doc/venv/ PYTHON=$(PYTHON) \
60+
all: ensure_prerequisites
61+
git -C $(CPYTHON_PATH) checkout $(CPYTHON_CURRENT_COMMIT)
62+
mkdir -p $(CPYTHON_PATH)/locales/$(LANGUAGE)/LC_MESSAGES/
63+
$(CP_CMD) -uv --parents *.po */*.po $(CPYTHON_PATH)/locales/$(LANGUAGE)/LC_MESSAGES/ | cut -d"'" -f2
64+
$(MAKE) -C $(CPYTHON_PATH)/Doc/ \
6665
SPHINXOPTS='-qW -j$(JOBS) \
6766
-D locale_dirs=../locales \
6867
-D language=$(LANGUAGE) \
6968
-D gettext_compact=0 \
7069
-D latex_engine=xelatex \
7170
-D latex_elements.inputenc= \
7271
-D latex_elements.fontenc=' \
73-
$(MODE) && echo "Build success, open file://$(WORKTREE)/Doc/build/html/index.html or run 'make serve' to see them."
74-
75-
76-
.PHONY: setup
77-
setup: venv
78-
echo "Setup the main clone"
79-
if ! [ -d $(CPYTHON_PATH) ]; then \
80-
git clone --depth 16 --branch $(BRANCH) $(UPSTREAM) $(CPYTHON_PATH); \
72+
$(MODE)
73+
# Cleanup
74+
git -C $(CPYTHON_PATH) checkout -
75+
rm -fr $(CPYTHON_PATH)/locales/
76+
# Info
77+
@echo "Build success, open file://$(abspath $(CPYTHON_PATH))/Doc/build/html/index.html or run 'make serve' to see them."
78+
79+
80+
.PHONY: ensure_prerequisites
81+
ensure_prerequisites:
82+
@if [ -z $(CPYTHON_PATH) ]; then \
83+
echo "Your CPYTHON_PATH is empty, please provide one."; \
84+
exit 1; \
8185
fi
82-
83-
echo "Setup the current worktree"
84-
if ! [ -d $(WORKTREE) ]; then \
85-
rm -fr $(WORKTREES); \
86-
git -C $(CPYTHON_PATH) worktree prune; \
87-
mkdir -p $(WORKTREES); \
88-
if [ -n "$(CPYTHON_CURRENT_COMMIT)" ]; \
89-
then \
90-
depth=32; \
91-
while ! git -C $(CPYTHON_PATH) cat-file -e $(CPYTHON_CURRENT_COMMIT); \
92-
do \
93-
depth=$$((depth * 2)); \
94-
git -C $(CPYTHON_PATH) fetch --depth $$depth $(UPSTREAM) $(BRANCH); \
95-
done \
96-
else \
97-
git -C $(CPYTHON_PATH) fetch --depth 1 $(UPSTREAM); \
98-
fi; \
99-
git -C $(CPYTHON_PATH) worktree add $(WORKTREE)/ $(CPYTHON_CURRENT_COMMIT); \
100-
$(MAKE) -C $(WORKTREE)/Doc/ VENVDIR=$(WORKTREE)/Doc/venv/ PYTHON=$(PYTHON) venv; \
86+
@if ! [ -d $(CPYTHON_PATH) ]; then \
87+
echo "Building the translation requires a cpython clone."; \
88+
echo "Please provide the path to a clone using the CPYTHON_PATH variable."; \
89+
echo "(Currently CPYTHON_PATH is $(CPYTHON_PATH)."; \
90+
echo "So you may want to run:"; \
91+
echo ""; \
92+
echo " git clone $(UPSTREAM) $(CPYTHON_PATH)"; \
93+
exit 1; \
10194
fi
102-
103-
104-
.PHONY: venv
105-
venv:
106-
echo "Setup venv in $(VENV)"
107-
if [ ! -d $(VENV) ]; then $(PYTHON) -m venv --prompt python-docs-fr $(VENV); fi
108-
$(VENV)/bin/python -m pip install -q -r requirements.txt 2> $(VENV)/pip-install.log
109-
if grep -q 'pip install --upgrade pip' $(VENV)/pip-install.log; then \
110-
$(VENV)/bin/pip install -q --upgrade pip; \
95+
@if [ -n "$$(git -C $(CPYTHON_PATH) status --porcelain | grep -v locales/)" ]; then \
96+
echo "Your cpython clone at $(CPYTHON_PATH) is not clean."; \
97+
echo "In order to avoid breaking things, please clean it first."; \
98+
exit 1; \
99+
fi
100+
@if ! (blurb help >/dev/null 2>&1 && sphinx-build --version >/dev/null 2>&1); then \
101+
echo "You're missing dependencies, please enable a venv and install:"; \
102+
echo ""; \
103+
echo " python -m pip install -r requirements.txt -r $(CPYTHON_PATH)/Doc/requirements.txt"; \
104+
exit 1; \
111105
fi
112-
113106

114107
.PHONY: serve
115108
serve:
116-
$(MAKE) -C $(WORKTREE)/Doc/ serve
109+
$(MAKE) -C $(CPYTHON_PATH)/Doc/ serve
117110

118111

119112
.PHONY: progress
120113
progress:
121-
$(PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
114+
@$(PYTHON) -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
122115
$(shell msgcat *.po */*.po | msgattrib --translated | grep -c '^msgid') \
123116
$(shell msgcat *.po */*.po | grep -c '^msgid')
124117

125118

126119
.PHONY: todo
127-
todo: venv
128-
$(VENV)/bin/potodo --exclude $(VENV) $(EXCLUDED)
120+
todo: ensure_prerequisites
121+
potodo --exclude venv .venv $(EXCLUDED)
129122

130123
.PHONY: wrap
131-
wrap: venv
132-
echo "Verify wrapping"
133-
$(VENV)/bin/powrap --check --quiet *.po **/*.po
124+
wrap: ensure_prerequisites
125+
@echo "Verify wrapping"
126+
powrap --check --quiet *.po **/*.po
134127

135128
SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$')
136129
# foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out
137130
DESTS = $(addprefix $(POSPELL_TMP_DIR)/,$(addsuffix .out,$(SRCS)))
138131

139132
.PHONY: spell
140-
spell: venv $(DESTS)
133+
spell: ensure_prerequisites $(DESTS)
141134

142135
$(POSPELL_TMP_DIR)/%.po.out: %.po dict
143-
echo "Pospell checking $<..."
136+
@echo "Pospell checking $<..."
144137
mkdir -p $(@D)
145-
$(VENV)/bin/pospell -p dict -l fr_FR $< && touch $@
138+
pospell -p dict -l fr_FR $< && touch $@
146139

147140
.PHONY: fuzzy
148-
fuzzy: venv
149-
$(VENV)/bin/potodo -f --exclude $(VENV) $(EXCLUDED)
141+
fuzzy: ensure_prerequisites
142+
potodo -f --exclude venv .venv $(EXCLUDED)
150143

151144
.PHONY: verifs
152145
verifs: wrap spell
153146

154147
.PHONY: merge
155-
merge: setup
156-
echo "Merge from $(UPSTREAM)"
157-
git -C $(CPYTHON_PATH) fetch $(UPSTREAM)
158-
rm -fr $(WORKTREES)/$(BRANCH)
159-
git -C $(CPYTHON_PATH) worktree prune
160-
git -C $(CPYTHON_PATH) worktree add $(WORKTREES)/$(BRANCH) $(word 1,$(shell git -C $(CPYTHON_PATH) remote -v | grep python/cpython))/$(BRANCH)
161-
$(MAKE) -C $(WORKTREES)/$(BRANCH)/Doc/ VENVDIR=$(WORKTREES)/$(BRANCH)/Doc/venv/ PYTHON=$(PYTHON) venv;
162-
(cd $(WORKTREES)/$(BRANCH)/Doc; $(WORKTREES)/$(BRANCH)/Doc/venv/bin/sphinx-build -Q -b gettext -D gettext_compact=0 . ../pot)
163-
find $(WORKTREES)/$(BRANCH) -name '*.pot' |\
164-
while read -r POT;\
165-
do\
166-
PO="./$$(echo "$$POT" | sed "s#$(WORKTREES)/$(BRANCH)/pot/##; s#\.pot\$$#.po#")";\
167-
mkdir -p "$$(dirname "$$PO")";\
168-
if [ -f "$$PO" ];\
169-
then\
170-
case "$$POT" in\
171-
*whatsnew*) msgmerge --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
172-
*) msgmerge --backup=off --force-po -U "$$PO" "$$POT" ;;\
173-
esac\
174-
else\
175-
msgcat -o "$$PO" "$$POT";\
176-
fi\
148+
merge: ensure_prerequisites
149+
@echo "Merge from $(UPSTREAM)"
150+
git -C $(CPYTHON_PATH) checkout $(BRANCH)
151+
git -C $(CPYTHON_PATH) pull --ff-only
152+
(cd $(CPYTHON_PATH)/Doc; sphinx-build -Q -b gettext -D gettext_compact=0 . ../pot)
153+
find $(CPYTHON_PATH)/pot/ -name '*.pot' |\
154+
while read -r POT; \
155+
do \
156+
PO="./$$(echo "$$POT" | sed "s#$(CPYTHON_PATH)/pot/##; s#\.pot\$$#.po#")"; \
157+
mkdir -p "$$(dirname "$$PO")"; \
158+
if [ -f "$$PO" ]; \
159+
then \
160+
msgmerge --backup=off --force-po -U "$$PO" "$$POT"; \
161+
else \
162+
msgcat -o "$$PO" "$$POT"; \
163+
fi \
177164
done
178-
echo "Replacing CPYTHON_CURRENT_COMMIT Makefile by: " $(shell git -C $(WORKTREES)/$(BRANCH) rev-parse HEAD)
179-
sed -i 's/^CPYTHON_CURRENT_COMMIT :=.*/CPYTHON_CURRENT_COMMIT := $(shell git -C $(WORKTREES)/$(BRANCH) rev-parse HEAD)/' Makefile
180-
rm -fr $(WORKTREES)/$(BRANCH)
181-
git -C $(CPYTHON_PATH) worktree prune
165+
rm -fr $(CPYTHON_PATH)/pot/
166+
@echo "Replacing CPYTHON_CURRENT_COMMIT in Makefile by: " $(shell git -C $(CPYTHON_PATH) rev-parse HEAD)
167+
sed -i 's/^CPYTHON_CURRENT_COMMIT :=.*/CPYTHON_CURRENT_COMMIT := $(shell git -C $(CPYTHON_PATH) rev-parse HEAD)/' Makefile
182168
sed -i 's|^#: .*Doc/|#: |' *.po */*.po
183-
-$(VENV)/bin/powrap -m
184-
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'
169+
powrap -m
170+
@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'
185171

186172
.PHONY: clean
187173
clean:
188-
echo "Cleaning *.mo, $(VENV), and $(POSPELL_TMP_DIR)"
189-
rm -fr $(VENV) $(POSPELL_TMP_DIR)
174+
echo "Cleaning *.mo and $(POSPELL_TMP_DIR)"
175+
rm -fr $(POSPELL_TMP_DIR)
190176
find -name '*.mo' -delete

c-api/arg.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgstr ""
66
"Project-Id-Version: Python 3\n"
77
"Report-Msgid-Bugs-To: \n"
88
"POT-Creation-Date: 2020-10-01 16:00+0200\n"
9-
"PO-Revision-Date: 2018-10-04 12:14+0200\n"
9+
"PO-Revision-Date: 2020-12-10 16:23+0100\n"
1010
"Last-Translator: Julien Palard <[email protected]>\n"
1111
"Language-Team: FRENCH <[email protected]>\n"
1212
"Language: fr\n"
@@ -688,7 +688,7 @@ msgstr "``n`` (:class:`int`) [``Py_ssize_t``]"
688688

689689
#: c-api/arg.rst:292
690690
msgid "Convert a Python integer to a C :c:type:`Py_ssize_t`."
691-
msgstr "Convertit un entier Python en un :c:type:`short int` C."
691+
msgstr "Convertit un entier Python en un :c:type:`Py_ssize_t`."
692692

693693
#: c-api/arg.rst:299
694694
msgid "``c`` (:class:`bytes` or :class:`bytearray` of length 1) [char]"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
poutils==0.10.0
1+
poutils==0.9.0

0 commit comments

Comments
 (0)