@@ -14,12 +14,15 @@ B ?= build/
1414OSTYPE ?= $(shell echo $$OSTYPE)
1515ifneq (,$(findstring $(OSTYPE ) ,win32 msys cygwin) )
1616 PYTHON ?= $(shell cygpath -m `which python.exe`)
17+ VENV_PYTHON ?= Scripts/python.exe
1718else
1819 PYTHON ?= $(shell where python3)
20+ VENV_PYTHON ?= bin/python3
1921endif
2022
2123# Python interpreter
22- $/_PYTHON ?= $(PYTHON )
24+ $/_PYTHON ?= $/.venv/$(VENV_PYTHON )
25+ $/_PIP_DIR ?= $($/_PYTHON:%/$(VENV_PYTHON ) =% ) /lib/site-packages/
2326
2427# Matched Python modules here
2528$/*.py := $(wildcard $(subst % ,* ,$/$* .py) )
@@ -33,6 +36,14 @@ $/self-test: $/.py/build/test.py.sh-test.tested
3336.DELETE_ON_ERROR :
3437.PRECIOUS : $($/*.py:$/%=$/$B%.shebang )
3538
39+ # Make sure python exists where expected
40+ $($/_PYTHON ) : | $(PYTHON )
41+ $| -m venv --upgrade-deps $(@:%/$(VENV_PYTHON ) =% )
42+
43+ # Make sure a pip package exists
44+ $($/_PIP_DIR ) % : | $($/_PYTHON )
45+ $| -m pip install --prefer-binary $*
46+
3647# Make sure a local build directory exists
3748ifneq (,$B)
3849 $/$B :
@@ -53,8 +64,16 @@ $/$B$*.py.mk: $/$*.py $/$B$*.py.shebang | $(.-ON-PATH)
5364# Include all those bringup recipies
5465-include $($/*.py :$/% =$/$B% .mk)
5566
67+ # Check Python 3.9 syntax
68+ $B$* .py.syntax : $/$* .py | $($/_PYTHON ) $($/_PIP_DIR ) ruff
69+ $(firstword $|) -m ruff check --select=E9,F63,F7,F82 --target-version=py39 $< > $@ || (cat $@ && false)
70+
71+ # Check Python 3.9 style
72+ $B$* .py.style : $/$* .py $B$* .py.syntax | $($/_PYTHON )
73+ $| -m ruff check --fix --target-version=py39 $< > $@ || (cat $@ && false)
74+
5675# Make sure the python module tested OK
57- $/$B$* .py.tested : $/$* .py $/$B$* .py.bringup
76+ $/$B$* .py.tested : $/$* .py $/$B$* .py.style $/$B $* .py. bringup
5877 $< --test > $@
5978
6079
0 commit comments