Compare commits

...

8 Commits

9 changed files with 96 additions and 44 deletions

View File

@ -2,8 +2,8 @@ name: GitHub Pages
on:
push:
branches:
- main
tags: ["v*.*.*"]
workflow_dispatch:
jobs:
deploy:
@ -20,7 +20,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
python-version: "3.9"
- name: Upgrade pip
run: |

10
.task.cfg.mk Normal file
View File

@ -0,0 +1,10 @@
define USAGE
{a.style('usage','header')}:\n make <recipe>\n
Turn your {a.style('`Makefile`','b_magenta')} into
the {a.italic}{a.underline}task runner{a.end} you always needed.
See the example output below.\n
endef
EPILOG = \nfor more info: gh.dayl.in/task.mk
PRINT_VARS := VERSION SHELL

View File

@ -1,12 +1,10 @@
VERSION ?= $(shell git describe --tags --always --dirty | sed s'/dirty/dev/')
VERSION ?= $(shell git describe --tags --always --dirty=dev)
TEMPLATES := $(shell find src/ -type f)
.DEFAULT_GOAL := help
msg = $(if $(tprint),$(call tprint,{a.bold}==> {a.magenta}$(1){a.end}),@echo '==> $(1)')
### task.mk development | args: -d -ms b_green --align center
## bootstrap | generate local dev environment
### task.mk development |> -d -ms b_green --align center
## bootstrap | generate local dev environment |> -ms b_magenta -gs b_cyan
.PHONY: bootstrap env hooks
bootstrap: env hooks
env:
@ -17,6 +15,7 @@ hooks:
@git config core.hooksPath .githooks
docs-env:
@mamba run -p ./env pip install mkdocs-material mkdocs-git-revision-date-localized-plugin
## l, lint | lint the python
.PHONY: l lint
l lint:
@ -29,33 +28,40 @@ l lint:
assets:
@yartsu -o assets/help.svg -t "make help" -- make --no-print-directory help
define release_sh
./generate.py $(subst v,,$(VERSION)) > task.mk
sed -i 's/task.mk\/.*\/task.mk/task.mk\/$(VERSION)\/task.mk/g' README.md docs/index.md
git add task.mk README.md docs/index.md
git commit -m "release: $(VERSION)" --no-verify
git tag $(VERSION)
endef
## release | release new version of task.mk
.PHONY: release
release: version-check
$(call msg,Release Project)
@./generate.py $(VERSION) > task.mk
@sed -i 's/task.mk\/.*\/task.mk/task.mk\/v$(VERSION)\/task.mk/g' README.md
@sed -i 's/task.mk\/.*\/task.mk/task.mk\/v$(VERSION)\/task.mk/g' docs/index.md
@git add task.mk README.md docs/index.md
@git commit -m "release: v$(VERSION)" --no-verify
@git tag v$(VERSION)
$(call tbash,release_sh)
## c, clean | remove the generated files
.PHONY: clean
c clean:
@rm -f task.mk .task.mk
define version_check_sh
if [[ "${VERSION}" == *'-'* ]]; then
$(call tprint-sh,{a.red}VERSION INVALID! Uncommited or untagged work{a.end})
exit 1
elif [[ $(shell echo "${VERSION}" | awk -F. '{ print NF }') -lt 3 ]];then\
$(call tprint-sh,{a.red}VERSION INVALID! Expected CalVer string{a.end})
exit 1
fi
endef
.PHONY: version-check
version-check:
@if [[ "${VERSION}" == *'-'* ]]; then\
$(call tprint-sh,{a.red}VERSION INVALID! Uncommited or untagged work{a.end});\
echo ">> version: $(VERSION)"; exit 1;\
elif [[ $(shell echo "${VERSION}" | awk -F. '{ print NF }') -lt 3 ]];then\
$(call tprint-sh,{a.red}VERSION INVALID! Expected CalVer string{a.end});\
echo ">> version: $(VERSION)"; exit 1;\
else \
$(call tprint-sh,{a.green}VERSION LOOKS GOOD!{a.end});\
fi
@$(call tprint,>> version: {a.green}$(VERSION){a.end})
@$(call tbash,version_check_sh)
@$(call tprint,>> {a.green}VERSION LOOKS GOOD!{a.end})
## info | demonstrate usage of tprint
.PHONY: task
@ -68,15 +74,6 @@ info:
task.mk: $(TEMPLATES) generate.py
./generate.py $(VERSION) > task.mk
define USAGE
{a.style('usage','header')}:\n make <recipe>\n
Turn your {a.style('`Makefile`','b_magenta')} into
the {a.italic}{a.underline}task runner{a.end} you always needed.
See the example output below.\n
endef
EPILOG = \nfor more info: gh.dayl.in/task.mk
PRINT_VARS := VERSION SHELL
-include .task.mk
.task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local .task.mk)

View File

@ -54,6 +54,7 @@ See this project's `make info` for an example.
## Configuration
You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`.
These can also be included in a seperate file `.task.cfg.mk`.
```make
# ---- [config] ---- #
@ -87,7 +88,7 @@ may be easier than balancing sub-shells and strung together awk commands.
When `make` expands the function it will take the parameters passed to `py` and expand them.
`$(1)` is the variable name and `$(2)` in this case is the implicit pattern from the rule. Pay attention to quotes.
If you need to debug your python script, use `DEBUG=1` when you run `make` and it will first print the script that will be piped to `python`.
If you need to debug your python script, use `TASKMK_DEBUG=1` when you run `make` and it will first print the script that will be piped to `python`.
```make
define list_files_py

View File

@ -5,7 +5,7 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
endif
## h, help | show this help
h help:
$(call py,help_py) || { echo "exiting early!"; exit 1; }
$(call py,help_py)
_help: export SHOW_HIDDEN=true
_help: help
ifdef PRINT_VARS

View File

@ -1,4 +1,5 @@
# ---- [config] ---- #
-include .task.cfg.mk
HEADER_STYLE ?= b_cyan
ACCENT_STYLE ?= b_yellow
PARAMS_STYLE ?= $(ACCENT_STYLE)

View File

@ -20,8 +20,30 @@ a = ansi = Ansi(target="stdout")
MaxLens = namedtuple("MaxLens", "goal msg")
###- double dollar signs to prevent make escaping them -###
###- re.X requires all important whitespace is escaped -###
pattern = re.compile(
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
r"""
^\#\#\
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
\s?
(?:
(?:\|\s?args:\s?|\|>)
\s?
(?P<msgargs>.*?)
)?
$$
|
^\#\#\#\
(?P<rawmsg>.*?)
\s?
(?:
(?:\|\s?args:|\|\>)
\s?
(?P<rawargs>.*?)
)?
$$
""",
re.X,
)
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
@ -185,14 +207,14 @@ def print_help():
def print_arg_help(help_args):
print(f"{ansi.style('task.mk recipe help','header')}\n")
for arg in help_args.split():
print("\n".join(parse_goal(gen_makefile(), arg)))
print()
print("\n".join((*parse_goal(gen_makefile(), arg), "\n")))
def main():
help_args = os.getenv("HELP_ARGS")
if help_args:
print_arg_help(help_args)
print(f"{ansi.faint}exiting task.mk{ansi.end}")
sys.exit(1)
else:
print_help()

View File

@ -8,7 +8,7 @@ _escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))
_escape_printf = $(subst \,\\,$(subst %,%%,$1))
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1)))
_printline = printf -- "<----------------------------------->\n"
ifdef DEBUG
ifdef TASKMK_DEBUG
define _debug_runner
@printf "$(1) Script:\n";$(_printline);
@printf "$(call _create_string,$(3))\n" | cat -n

33
task.mk
View File

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan
# MIT License
# version: v22.9.28-3-g76e9ece-dev
# version: v22.9.28-8-g4fcab2adev
#
# 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.
@ -27,7 +27,7 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
endif
## h, help | show this help
h help:
$(call py,help_py) || { echo "exiting early!"; exit 1; }
$(call py,help_py)
_help: export SHOW_HIDDEN=true
_help: help
ifdef PRINT_VARS
@ -64,7 +64,7 @@ _escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))
_escape_printf = $(subst \,\\,$(subst %,%%,$1))
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1)))
_printline = printf -- "<----------------------------------->\n"
ifdef DEBUG
ifdef TASKMK_DEBUG
define _debug_runner
@printf "$(1) Script:\n";$(_printline);
@printf "$(call _create_string,$(3))\n" | cat -n
@ -91,7 +91,28 @@ $(utils_py)
a = ansi = Ansi(target="stdout")
MaxLens = namedtuple("MaxLens", "goal msg")
pattern = re.compile(
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
r"""
^\#\#\
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
\s?
(?:
(?:\|\s?args:\s?|\|>)
\s?
(?P<msgargs>.*?)
)?
$$
|
^\#\#\#\
(?P<rawmsg>.*?)
\s?
(?:
(?:\|\s?args:|\|\>)
\s?
(?P<rawargs>.*?)
)?
$$
""",
re.X,
)
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
def parseargs(argstring):
@ -229,12 +250,12 @@ def print_help():
def print_arg_help(help_args):
print(f"{ansi.style('task.mk recipe help','header')}\n")
for arg in help_args.split():
print("\n".join(parse_goal(gen_makefile(), arg)))
print()
print("\n".join((*parse_goal(gen_makefile(), arg), "\n")))
def main():
help_args = os.getenv("HELP_ARGS")
if help_args:
print_arg_help(help_args)
print(f"{ansi.faint}exiting task.mk{ansi.end}")
sys.exit(1)
else:
print_help()