Skip to content

Commit a7b4130

Browse files
JoppeJoppe
authored andcommitted
Document variables in Makefile
Prepare for training on how to Normalize make. * [doc] New expected output from make.py --make in README.md * [py] Implement make.py --make as in README.md * [sh] Use make.py --dep as in README.md
1 parent ffd8991 commit a7b4130

5 files changed

Lines changed: 309 additions & 206 deletions

File tree

README.md

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,44 +72,6 @@ If they are already in the directory or linked to from the directory, internet a
7272
Dependencies:
7373
requests tiktoken # Needed for the --prompt option
7474

75-
76-
```
77-
78-
---
79-
80-
Standalone variant:
81-
82-
```sh
83-
$ make.py --make
84-
bringup: build/make.py.bringup # Default: Make sure everything is setup OK
85-
tested: build/make.py.tested # Make sure everything tested OK
86-
87-
build/make.py.shebang: make.py | $(PYTHON) # Make sure make.py has a working shebang
88-
mkdir -p build/ && \
89-
make.py --shebang > $@
90-
build/make.py.bringup: make.py build/make.py.shebang | $(PYTHON) # Make sure make.py is setup OK
91-
$(PYTHON) -m pip install requests tiktoken --no-warn-script-location > $@
92-
build/make.py.tested: make.py build/make.py.bringup # Make sure make.py tested OK
93-
make.py --test > $@
94-
95-
```
96-
97-
---
98-
99-
Standalone variant with dynamic bringup:
100-
101-
```sh
102-
$ make.py --make --dep make.py.mk
103-
bringup: make.py.bringup # Default: Make sure everything is setup OK
104-
tested: make.py.tested # Make sure everything tested OK
105-
106-
make.py.shebang: make.py | $(PYTHON) # Make sure make.py has a working shebang
107-
make.py --shebang > $@
108-
make.py.mk: make.py make.py.shebang | $(PYTHON) # Make sure make.py can be setup
109-
$(PYTHON) make.py --dep $@ > /dev/null
110-
-include make.py.mk # make.py.bringup: make.py.shebang ; <setup>
111-
make.py.tested: make.py make.py.bringup # Make sure make.py tested OK
112-
make.py --test > $@
11375
```
11476
11577
- Python version 3.9 or later is required, and will be installed automatically if missing on the OS.

example/README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,22 @@ Hello from greeter.cpp!
4141
\footnotesize
4242
~~~ {.sh}
4343
$ cat build/greeter.py.mk
44-
$/build/greeter.py.bringup: $/greeter.py $/build/greeter.py.shebang $($/_EXE) | $/venv/$(VENV_PYTHON) # Make sure $/greeter.py is setup OK
44+
$!greeter.py.bringup: $/greeter.py $!greeter.py.shebang $($/_EXE) | $($/_PYTHON) # Make sure $/greeter.py is setup OK
4545
$| -m pip install fire --no-warn-script-location > $@
4646
4747
$ greeter.py --help | awk '{ print "\t" $0 }'
4848
usage: greeter.py [-h] [--shebang] [--generic] [--make] [--dep DEP] [--pips]
4949
[-c C] [--timeout TIMEOUT] [--test] [--sh-test SH_TEST]
50+
[PYTHON_FILE]
5051
5152
Greetings from the source code
5253
5354
function hello: Greetings from the source code examples in this folder
5455
function run: Run a command and return the decoded result
5556
57+
positional arguments:
58+
PYTHON_FILE Python file to fixup
59+
5660
option...:
5761
-h, --help show this help message and exit
5862
--shebang Insert a local venv shebang, print its PATH configuration
@@ -94,5 +98,62 @@ $ greeter.py --help | awk '{ print "\t" $0 }'
9498
$ greeter.py run example
9599
Hello from main.c!
96100
Hello from greeter.cpp!
101+
97102
~~~
98103
\normalsize
104+
105+
---
106+
107+
Standalone variant:
108+
109+
```sh
110+
$ greeter.py --make --dep test/greeter.py.mk | tee test/greeter.mk
111+
# Path/variable prefix
112+
/ := $(patsubst %build/,%,$(patsubst ./%,%,$(patsubst C:/%,/c/%,$(subst \,/,$(dir $(Makefile))))))
113+
114+
# Build directory
115+
! ?= $/test/
116+
117+
# Default python interpreter
118+
PYTHON ?= $(shell command -v python3 || cygpath -m `which python.exe`)
119+
120+
# Python interpreter
121+
$/_PYTHON ?= $(PYTHON)
122+
123+
# Local Python modules to match
124+
* ?= greeter
125+
126+
# Matched Python modules here
127+
*.py := $(wildcard $/$*.py)
128+
129+
# Suggested targets
130+
$/bringup: $(*.py:%=$!%.bringup) # Default: Make sure everything is setup OK
131+
$/tested: $(*.py:%=$!%.tested) # Recommended: Make sure everything tested OK
132+
133+
# Make sure a local build directory (@) exists
134+
ifneq (,$!)
135+
$!:
136+
mkdir -p $@
137+
endif
138+
139+
# Make sure the python module (<) uses make, has the right python shebang and is on PATH
140+
$!$*.py.shebang: $/make.py $/$*.py | $($/_PYTHON) $!
141+
$(firstword $|) $^ --shebang > $@ && cat $@ && sh $@
142+
143+
# Make sure the python module (<) has an up-to-date $!$*.py.bringup recipy
144+
$!$*.py.mk: $/$*.py $!$*.py.shebang
145+
$< --dep $@ > /dev/null
146+
147+
# Include all $!$*.py.bringup: $!$*.py.shebang; <bringup commands>
148+
-include $(*.py:%=$!%.mk)
149+
150+
# Make sure the python module (<) tested OK
151+
$!$*.py.tested: $/$*.py $!$*.py.bringup
152+
$< --test > $@
153+
154+
# Clear the directory from *** ALL *** non-git files and directories
155+
$/clear:
156+
git clean -xfd $(dir $@)
157+
158+
$ rm -r test/
159+
```

example/greeter.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
fire
66
"""
77
import subprocess
8-
import argparse
98

109
import make
1110
import fire
@@ -30,7 +29,7 @@ def hello(*world):
3029
print("Hello from greeter.py!")
3130
print(run(f"{make.path}example"))
3231

33-
EXAMPLES = """
32+
EXAMPLES = """Examples:
3433
$ greeter.py
3534
NAME
3635
greeter.py
@@ -58,10 +57,7 @@ def hello(*world):
5857
"""
5958

6059
if __name__ == '__main__':
61-
argparser = argparse.ArgumentParser(
62-
formatter_class=argparse.RawDescriptionHelpFormatter,
63-
description=make.brief(),
64-
epilog=f"Examples:{EXAMPLES}")
65-
make.add_arguments(argparser)
66-
args = argparser.parse_known_args()
60+
make.argparser.description = make.brief()
61+
make.argparser.epilog = EXAMPLES
62+
args = make.argparser.parse_known_args()
6763
fire.Fire(dict(hello=hello, run=run))

0 commit comments

Comments
 (0)