_example_ update

This commit is contained in:
Dirk Alders 2025-08-15 18:33:46 +02:00
parent 877c434ccb
commit d6551e1ff2
5 changed files with 39 additions and 20 deletions

View File

@ -1,20 +1,30 @@
EXAMPLES = $(wildcard *.py) # pylibs examples Makefile: Version 1.0 (2025-08-15)
FIRSTLOGS = ${EXAMPLES:.py=_1.log}
LASTLOGS = ${EXAMPLES:.py=_2.log} .ONESHELL:
SHELL = /usr/bin/bash
MAKEFLAGS += --no-print-directory
.SILENT:
INTERPRETER = python3
.PHONY: all .PHONY: all
.SECONDAY: $(FIRSTLOGS) EXAMPLES := $(wildcard *.py)
EXAMPLES := $(filter-out config.py, $(EXAMPLES))
LOGFILES := ${EXAMPLES:.py=.log}
all: $(LASTLOGS) all: $(LOGFILES)
%_1.log: %.py -include __make.d__/*.mk
rm -f *.json *.pickle
python3 $< > $@
%_2.log: %.py %_1.log %.py_local:
python3 $< > $@
rm -f *.json *.pickle %.log: %.py
$(MAKE) $<_local
echo -e "\e[1m * Running example $<\e[0m"
$(INTERPRETER) $< > $@
localclean:
clean: localclean
echo -e "\e[1m * Example logs...\e[0m"
rm -f $(LOGFILES)
clean:
@echo "\e[1m * Example logs...\e[0m"
@rm -f $(FIRSTLOGS) $(LASTLOGS) *.json *.pickle

View File

@ -0,0 +1,9 @@
.ONESHELL:
SHELL = /usr/bin/bash
MAKEFLAGS += --no-print-directory
.SILENT:
localclean:
echo -e "\e[1m * Example cache files...\e[0m"
rm -f cache.json cache.pickle

View File

@ -1 +0,0 @@
..

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python import sys # nopep8
# -*- coding: UTF-8 -*- sys.path.append('../..') # nopep8
import caching import caching
import logging import logging
@ -55,6 +55,7 @@ class test_slow_data(object):
self.print_n_sleep("__five__") self.print_n_sleep("__five__")
return 'five' return 'five'
class test_slow_data_cached(test_slow_data): class test_slow_data_cached(test_slow_data):
def __init__(self, *args, **kwargs) -> None: def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -79,4 +80,3 @@ if __name__ == "__main__":
for key in data.keys(): for key in data.keys():
print(data.get(key)) print(data.get(key))
print('--------------------------------\nThe execution time was %.1fs' % (time.time()-tm)) print('--------------------------------\nThe execution time was %.1fs' % (time.time()-tm))

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python import sys # nopep8
# -*- coding: UTF-8 -*- sys.path.append('../..') # nopep8
import caching import caching
import logging import logging
@ -55,6 +55,7 @@ class test_slow_data(object):
self.print_n_sleep("__five__") self.print_n_sleep("__five__")
return 'five' return 'five'
class test_slow_data_cached(test_slow_data): class test_slow_data_cached(test_slow_data):
def __init__(self, *args, **kwargs) -> None: def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)