@@ -11,7 +11,12 @@ B ?= build/
1111* ?= %
1212
1313# Default python interpreter
14- PYTHON ?= $(shell command -v python3 || cygpath -m `which python.exe`)
14+ OSTYPE ?= $(shell echo $$OSTYPE)
15+ ifneq (,$(findstring $(OSTYPE ) ,win32 msys cygwin) )
16+ PYTHON ?= $(shell cygpath -m `which python.exe`)
17+ else
18+ PYTHON ?= $(shell command -v python3)
19+ endif
1520
1621# Python interpreter
1722$/_PYTHON ?= $(PYTHON )
@@ -50,58 +55,42 @@ $/$B$*.py.tested: $/$*.py $/$B$*.py.bringup
5055 $< --test > $@
5156
5257
53- # ## Document usage of this builder
58+ # self-test
59+
60+ define FUNCTION
61+ def hello():
62+ """
63+ >>> hello()
64+ Hello World!
65+ """
66+ print('Hello World!')
67+ endef
5468
55- # We are going build a python module with a doctest in a hello function available as a command line argument:
5669define SH-TEST
5770$$ cat build/test.py.tested
5871All 1 python usage examples PASS
72+ All 0 command usage examples PASS
5973
6074$$ test.py
75+ NAME
76+ test.py
6177
62- $$ test.py hello
63- Hello World!
64-
65- $$ cat test.py
66-
67- endef
68-
69- # We are going verify all the command usages above:
70- define SH-TEST.EXPECTED
71- All 4 command usage examples PASS
72- endef
78+ SYNOPSIS
79+ test.py COMMAND
7380
74- # After bringup, these are the exact sections we expect to see in the module:
75- define SHEBANG
76- # !...python...
77-
78- endef
79- define DEPENDENCIES
80- """
81- Dependencies:
82- pip
83- """
81+ COMMANDS
82+ COMMAND is one of the following:
8483
85- endef
86- define IMPORTS
87- import make
88- import pip
84+ hello
85+ >>> hello() Hello World!
8986
90- endef
91- define FUNCTION
92- def hello():
93- """
94- >>> hello()
95- Hello World!
96- """
97- print('Hello World!')
87+ $$ test.py hello
88+ Hello World!
9889
9990endef
100- define CLI
101- if __name__ == '__main__':
102- make.argparser.parse_known_args()
103- fire.fire(dict([(name, item) for name, item in globals().items() if callable(item)]))
10491
92+ define SH-TEST.EXPECTED
93+ All 3 command usage examples PASS
10594endef
10695
10796$/.py/build/ :
@@ -111,33 +100,17 @@ $/.py/build/test.py.sh-test.expected: | $/.py/build/
111100 $(file >$@ ,$(SH-TEST.EXPECTED ) )
112101
113102$/.py/build/test.py.sh-test : | $/.py/build/
114- $(file >$@ ,$(SH-TEST )$( SHEBANG )$( DEPENDENCIES )$( IMPORTS )$( FUNCTION )$( CLI ) )
103+ $(file >$@ ,$(SH-TEST ) )
115104
116105$/.py/test.py : $/.py/build/test.py.sh-test | $/.py/build/
117106 $(file >$@ ,$(FUNCTION ) )
118107
119- # Put the bare function into test.py and verify that make.py test.py --shebang inserts make into it:
120108$/.py/build/test.py.tested : $/.py/test.py $/.py.mk $/make.py | $/.py/
121- @echo
122- # Self-tested source code:
123- cat $<
124- @echo
125- # The Makefile for .py source code:
126109 ln -sf ../.py.mk $| Makefile
127- @echo
128- # The python module that Makefile needs:
129110 ln -sf ../make.py $| make.py
130- @echo
131- # Now building $@
132111 (cd $| && make tested)
133112
134- # Verify
135- $/.py/build/test.py.sh-test.tested : $/.py/build/test.py.sh-test \
136- $/.py/build/test.py.tested $/.py/build/test.py.sh-test.expected | $/.py/
137- @echo
138- # Expected command line usage:
139- cat $<
140- @echo
141- # Now verifying that
142- (cd $| && test.py --sh-test $<) > $@ && \
113+ $/.py/build/test.py.sh-test.tested : $/.py/test.py $/.py/build/test.py.tested \
114+ $/.py/build/test.py.sh-test $/.py/build/test.py.sh-test.expected
115+ $< --sh-test $(word 3,$^) > $@ && \
143116 diff -u $(lastword $^) $@
0 commit comments