diff --git a/Makefile b/Makefile index a51a8315f..7b412c88c 100644 --- a/Makefile +++ b/Makefile @@ -58,14 +58,15 @@ EXCLUDED := \ library/xdrlib.po # Internal variables - UPSTREAM := https://github.com/python/cpython - -PYTHON := $(shell which python3) -MODE := html POSPELL_TMP_DIR := .pospell/ -JOBS := auto -SERVE_PORT := + +# You can set these variables from the command line. +VENVDIR = ./venv +PYTHON = $(VENVDIR)/bin/python3 +MODE = html +JOBS = auto +SERVE_PORT = # Detect OS @@ -90,6 +91,8 @@ all: ensure_prerequisites mkdir -p locales/$(LANGUAGE)/LC_MESSAGES/ $(CP_CMD) -u --parents *.po */*.po locales/$(LANGUAGE)/LC_MESSAGES/ $(MAKE) -C venv/cpython/Doc/ \ + PYTHON=$(abspath $(PYTHON)) \ + VENVDIR=$(abspath $(VENVDIR)) \ SPHINXOPTS='-j$(JOBS) \ -D locale_dirs=$(abspath locales) \ -D language=$(LANGUAGE) \ @@ -109,31 +112,64 @@ venv/cpython/.git/HEAD: .PHONY: ensure_prerequisites ensure_prerequisites: venv/cpython/.git/HEAD - @if ! (blurb help >/dev/null 2>&1 && sphinx-build --version >/dev/null 2>&1); then \ + @if ! ($(VENVDIR)/bin/blurb help >/dev/null 2>&1 && $(VENVDIR)/bin/sphinx-build --version >/dev/null 2>&1); then \ git -C venv/cpython/ checkout $(BRANCH); \ - echo "You're missing dependencies please install:"; \ + echo "You're missing dependencies please install using:"; \ echo ""; \ - echo " python -m pip install -r requirements.txt -r venv/cpython/Doc/requirements.txt"; \ + echo "make update_venv"; \ exit 1; \ fi +.PHONY: $(PYTHON) +$(PYTHON): + @if [ ! -x $(PYTHON) ] || \ + [ "`$(PYTHON) --version | cut --fields=1 --delimiter='.'`" != "Python 3" ] ; then \ + echo "You don't have a suitable Python in: " $(abspath $(dir $(PYTHON))); \ + echo "The recommended way to proceed is to install a virtual env in: "$(abspath $(VENVDIR)); \ + echo "You can achieve this with:"; \ + echo "make install_venv PYTHON_BASE=/your/version/of/python"; \ + echo ""; \ + echo "or you can customize the variable PYTHON of the Makefile"; \ + exit 1; \ + fi + +PYTHON_BASE = $(shell which python) +PYTHON_BASE_VERSION = $(shell $(PYTHON_BASE) --version | cut --fields=1 --delimiter='.') + +.PHONY: install_venv +install_venv: +ifneq ($(PYTHON_BASE_VERSION), Python 3) + @echo $(PYTHON_BASE) " is not a Python executable" ; \ + echo $(PYTHON_BASE_VERSION) ; \ + exit 1 +endif + $(PYTHON_BASE) -m venv $(VENVDIR) + @echo "Python virtual env installed in $(abspath $(VENVDIR))" + make update_venv + +.PHONY: update_venv +update_venv: $(PYTHON) venv/cpython/.git/HEAD + $(PYTHON) -m pip install -r requirements.txt -r venv/cpython/Doc/requirements.txt .PHONY: serve serve: ifdef SERVE_PORT - $(MAKE) -C venv/cpython/Doc/ serve SERVE_PORT=$(SERVE_PORT) + $(MAKE) -C venv/cpython/Doc/ \ + PYTHON=$(abspath $(PYTHON)) \ + SERVE_PORT=$(SERVE_PORT) \ + serve else - $(MAKE) -C venv/cpython/Doc/ serve + $(MAKE) -C venv/cpython/Doc/ PYTHON=$(abspath $(PYTHON)) serve endif .PHONY: todo todo: ensure_prerequisites - potodo --exclude venv .venv $(EXCLUDED) + $(VENVDIR)/bin/potodo --exclude venv .venv $(EXCLUDED) .PHONY: wrap wrap: ensure_prerequisites @echo "Re wrapping modified files" - powrap -m + $(VENVDIR)/bin/powrap -m SRCS = $(shell git diff --name-only $(BRANCH) | grep '.po$$') # foo/bar.po => $(POSPELL_TMP_DIR)/foo/bar.po.out @@ -145,15 +181,15 @@ spell: ensure_prerequisites $(DESTS) $(POSPELL_TMP_DIR)/%.po.out: %.po dict @echo "Pospell checking $<..." mkdir -p $(@D) - pospell -p dict -l fr_FR $< && touch $@ + $(VENVDIR)/bin/pospell -p dict -l fr_FR $< && touch $@ .PHONY: fuzzy fuzzy: ensure_prerequisites - potodo -f --exclude venv .venv $(EXCLUDED) + $(VENVDIR)/bin/potodo -f --exclude venv .venv $(EXCLUDED) .PHONY: verifs verifs: spell - powrap --check --quiet *.po */*.po + $(VENVDIR)/bin/powrap --check --quiet *.po */*.po .PHONY: clean clean: