Skip to content

Commit

Permalink
Support any OS, CPU and PYTHON in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Joppe committed Feb 16, 2024
1 parent 490ebb7 commit cca0584
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ There is a simpler variant:
```sh
$ python3 makemake.py --makemake
all: build/makemake.py.tested

build/makemake.py.tested: makemake.py build/makemake.py.bringup
python3 makemake.py --test > $@
makemake.py --test > $@
build/makemake.py.bringup: makemake.py
mkdir build/ && \
python3 -c 'import sys; assert sys.version_info[:2] >= (3, 7), sys.version' > $@ && \
python3 -m pip install requests >> $@ && \
$(PYTHON) -c 'import sys; assert sys.version_info[:2] >= (3, 7), sys.version' > $@ && \
$(SPEEDUP_WSL_PIP)$(PYTHON) -m pip install requests --no-warn-script-location >> $@ && \
$(PYTHON) makemake.py --shebang >> $@ && \
chmod +x $< >> $@

```
Expand Down
44 changes: 39 additions & 5 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,47 @@ Hello world!
$ cat build/greeter.py.mk
$(_example_BUILD)greeter.py.bringup: $(_example)greeter.py $(_example_BUILD)greeter.py.mk $(_example_PYTHON)
( cd $(_example_DIR) && make example --no-print-directory ) > $@ && \
$(_example_PYTHON) -m pip install fire >> $@ && \
$(SPEEDUP_WSL_PIP)$(_example_PYTHON) -m pip install fire --no-warn-script-location >> $@ && \
$(_example_PYTHON) $< --shebang >> $@ && \
chmod +x $< >> $@
$ cat build.mk | grep -E '^_example |^_example_BUILD |^_example_PYTHON '
_example := $(subst $(PWD)/,,$(_example_ABSPATH))
_example_BUILD := $(subst $(PWD)/,,$(_example_ABSPATH)$(__example_BUILD))
_example_PYTHON := $(_example_DIR)venv/bin/python
$ greeter.py --help | awk '{ print "\t" $0 }'
usage: greeter.py [-h] [--makemake] [--generic] [--dep DEP] [-c C]
[--timeout TIMEOUT] [--test] [--sh-test SH_TEST] [--shebang]
...
Greetings from the source code
function hello: Greetings from the source code examples in this folder
function run: Run a command and return the decoded result
positional arguments:
world hello(world)
options:
-h, --help show this help message and exit
--makemake Print Makefile for greeter.py, and exit
--generic Print generic Makefile for greeter.py, and exit
--dep DEP Build a greeter.dep target, print its Makefile include
statement, and exit
-c C Execute a program string and exit
--timeout TIMEOUT Test timeout in seconds (3)
--test Verify usage examples and exit
--sh-test SH_TEST Test command usage examples in a file, and exit
--shebang Insert a Windows-compatible shebang, print its PATH
configuration if needed, and exit
Examples:
$ ./greeter.py
Hello from greeter.py!
Hello from main.c!
Hello from greeter.cpp!
$ ./greeter.py world
Hello world!
$ greeter.py README.md reader
Hello README.md reader!
~~~
\normalsize
11 changes: 7 additions & 4 deletions example/greeter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!venv/python.exe
#!venv/bin/python3
"""Greetings from the source code
Dependencies:
Expand All @@ -19,16 +19,19 @@ def run(cmd):
"""
return subprocess.check_output(cmd.split()).decode('utf-8')[:-1]

def hello(world=None):
def hello(*world):
"""Greetings from the source code examples in this folder
>>> hello()
Hello from greeter.py!
Hello from main.c!
Hello from greeter.cpp!
"""
print(f"Hello {world or 'from greeter.py'}!")
if not world:

if world:
print(f"Hello {' '.join(world)}!")
else:
print("Hello from greeter.py!")
print(run(f"{makemake.path}example"))

EXAMPLES = """
Expand Down
2 changes: 1 addition & 1 deletion example2/factorize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!venv/python.exe
#!venv/bin/python3
"""Programming example: Strings and numbers
>>> print(" ".join(fizz3fuzz5(*range(1, 101))))
Expand Down

0 comments on commit cca0584

Please sign in to comment.