Compare commits

..

2 commits

7 changed files with 34 additions and 16 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
.task.cfg.dev.mk
.task.mk .task.mk
env/ env/

View file

@ -64,7 +64,7 @@ info: ## demonstrate usage of tprint
task.mk: $(TEMPLATES) generate.py task.mk: $(TEMPLATES) generate.py
./generate.py $(VERSION) > task.mk ./generate.py $(VERSION) > task.mk
-include .task.cfg.mk .task.mk -include .task.cfg.dev.mk .task.cfg.mk .task.mk
.task.mk: $(TEMPLATES) generate.py .task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local {a.b_cyan}.task.mk{a.end}) $(call msg,re-jinjaing the local {a.b_cyan}.task.mk{a.end})
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk) @./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk)

View file

@ -27,9 +27,9 @@ tconfirm = $(call py,confirm_py,$(1))
.PHONY: h help _help _print-ansi _update-task.mk .PHONY: h help _help _print-ansi _update-task.mk
TASK_MAKEFILE_LIST := $(filter-out $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)),$(MAKEFILE_LIST)) TASK_MAKEFILE_LIST := $(filter-out $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)),$(MAKEFILE_LIST))
export MAKEFILE_LIST MAKE TASK_MAKEFILE_LIST export MAKEFILE_LIST MAKE TASK_MAKEFILE_LIST
ifndef INHERIT_SHELL # ifndef INHERIT_SHELL
SHELL := $(shell which bash) # SHELL := $(shell which bash)
endif # endif
ifdef PHONIFY ifdef PHONIFY
$(shell $(call py-verbose,phonify_py)) $(shell $(call py-verbose,phonify_py))
endif endif

View file

@ -52,14 +52,14 @@ def parse_help(file, hidden=False):
and str(match.groupdict().get("goal")).startswith("_") and str(match.groupdict().get("goal")).startswith("_")
): ):
pass pass
elif not any(match.groupdict().get(k) for k in ('msg','msgargs')): elif not any(match.groupdict().get(k) for k in ("msg", "msgargs")):
pass pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield {k: v for k, v in match.groupdict().items() if v is not None}
def parseargs(argstring): def parseargs(argstring):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--align") parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true") parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true") parser.add_argument("-ws", "--whitespace", action="store_true")

View file

@ -1,5 +1,13 @@
# ---- [python/bash script runner] ---- # # ---- [python/bash script runner] ---- #
###-- modified from https://unix.stackexchange.com/a/223093 -### ###-- modified from https://unix.stackexchange.com/a/223093 -###
###-
# possible posix process substitions solution:
# https://unix.stackexchange.com/a/639752
# -###
SHELL_CHECK ?= $(shell /bin/sh --version | grep 'bash|zsh|ksh')
ifndef SHELL_CHECK
$(error task.mk requires a process substition compatible shell)
endif
define _newline define _newline

View file

@ -6,13 +6,15 @@ import re
import sys import sys
from dataclasses import dataclass from dataclasses import dataclass
def strip_ansi(txt): def strip_ansi(txt):
""" """
Removes ANSI escape codes, as defined by ECMA-048 in Removes ANSI escape codes, as defined by ECMA-048 in
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
""" """
pattern = re.compile(r'\x1B\[\d+(;\d+){0,2}m') pattern = re.compile(r"\x1B\[\d+(;\d+){0,2}m")
return pattern.sub('', txt) return pattern.sub("", txt)
@dataclass @dataclass
class Config: class Config:
@ -131,4 +133,5 @@ a = ansi = Ansi()
cfg = Config( cfg = Config(
"$(DIVIDER)", f"""$(HELP_SEP)""", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)") "$(DIVIDER)", f"""$(HELP_SEP)""", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
) )
#% endblock %# #% endblock %#

21
task.mk
View file

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ # # }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan # Copyright (c) 2022 Daylin Morgan
# MIT License # MIT License
TASKMK_VERSION ?= v23.1.1-5-g9ee6d34-dev TASKMK_VERSION ?= v23.1.1-7-gb411303-dev
# task.mk should be included at the bottom of your Makefile with `-include .task.mk` # task.mk should be included at the bottom of your Makefile with `-include .task.mk`
# See below for the standard configuration options that should be set prior to including this file. # See below for the standard configuration options that should be set prior to including this file.
# You can update your .task.mk with `make _update-task.mk` # You can update your .task.mk with `make _update-task.mk`
@ -219,8 +219,8 @@ def strip_ansi(txt):
Removes ANSI escape codes, as defined by ECMA-048 in Removes ANSI escape codes, as defined by ECMA-048 in
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
""" """
pattern = re.compile(r'\x1B\[\d+(;\d+){0,2}m') pattern = re.compile(r"\x1B\[\d+(;\d+){0,2}m")
return pattern.sub('', txt) return pattern.sub("", txt)
@dataclass @dataclass
class Config: class Config:
div: str div: str
@ -373,12 +373,12 @@ def parse_help(file, hidden=False):
and str(match.groupdict().get("goal")).startswith("_") and str(match.groupdict().get("goal")).startswith("_")
): ):
pass pass
elif not any(match.groupdict().get(k) for k in ('msg','msgargs')): elif not any(match.groupdict().get(k) for k in ("msg", "msgargs")):
pass pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield {k: v for k, v in match.groupdict().items() if v is not None}
def parseargs(argstring): def parseargs(argstring):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--align") parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true") parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true") parser.add_argument("-ws", "--whitespace", action="store_true")
@ -389,6 +389,11 @@ def parseargs(argstring):
return parser.parse_args(argstring.split()) return parser.parse_args(argstring.split())
endef endef
# ---- [python/bash script runner] ---- # # ---- [python/bash script runner] ---- #
SHELL_CHECK ?= $(shell /bin/sh --version | grep 'bash|zsh|ksh')
ifndef SHELL_CHECK
$(error task.mk requires a process substition compatible shell)
endif
define _newline define _newline
@ -440,9 +445,9 @@ tconfirm = $(call py,confirm_py,$(1))
.PHONY: h help _help _print-ansi _update-task.mk .PHONY: h help _help _print-ansi _update-task.mk
TASK_MAKEFILE_LIST := $(filter-out $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)),$(MAKEFILE_LIST)) TASK_MAKEFILE_LIST := $(filter-out $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)),$(MAKEFILE_LIST))
export MAKEFILE_LIST MAKE TASK_MAKEFILE_LIST export MAKEFILE_LIST MAKE TASK_MAKEFILE_LIST
ifndef INHERIT_SHELL # ifndef INHERIT_SHELL
SHELL := $(shell which bash) # SHELL := $(shell which bash)
endif # endif
ifdef PHONIFY ifdef PHONIFY
$(shell $(call py-verbose,phonify_py)) $(shell $(call py-verbose,phonify_py))
endif endif