Compare commits

..

No commits in common. "d0290aec94517a854b5369ad7d31e34655f4f00b" and "3244dba8dcd87291c082409f59c0a55b9cf07458" have entirely different histories.

5 changed files with 80 additions and 61 deletions

View file

@ -4,8 +4,9 @@ TEMPLATES := $(shell find src/ -type f)
msg = $(if $(tprint),$(call tprint,{a.bold}==> {a.magenta}$(1){a.end}),@echo '==> $(1)') msg = $(if $(tprint),$(call tprint,{a.bold}==> {a.magenta}$(1){a.end}),@echo '==> $(1)')
### task.mk development |> -d -ms b_green --align center ### task.mk development |> -d -ms b_green --align center
## bootstrap | generate local dev environment |> -ms b_magenta -gs b_cyan
.PHONY: bootstrap env hooks .PHONY: bootstrap env hooks
bootstrap: env hooks ## generate local dev environment |> -ms b_magenta -gs b_cyan bootstrap: env hooks
env: env:
$(call msg,Bootstrapping Environment) $(call msg,Bootstrapping Environment)
@mamba create -p ./env python jinja2 black -y @mamba create -p ./env python jinja2 black -y
@ -15,15 +16,16 @@ hooks:
docs-env: docs-env:
@mamba run -p ./env pip install mkdocs-material mkdocs-git-revision-date-localized-plugin @mamba run -p ./env pip install mkdocs-material mkdocs-git-revision-date-localized-plugin
## l, lint | lint the python
.PHONY: l lint .PHONY: l lint
l lint: ## lint the python l lint:
$(call msg,Linting) $(call msg,Linting)
@black generate.py @black generate.py
@black src/*.py --fast @black src/*.py --fast
## assets | generate assets
.PHONY: assets .PHONY: assets
assets: ## generate assets assets:
@yartsu -o assets/help.svg -t "make help" -- make --no-print-directory help @yartsu -o assets/help.svg -t "make help" -- make --no-print-directory help
define release_sh define release_sh
@ -34,13 +36,15 @@ git commit -m "release: $(VERSION)" --no-verify
git tag $(VERSION) git tag $(VERSION)
endef endef
## release | release new version of task.mk
.PHONY: release .PHONY: release
release: version-check ## release new version of task.mk release: version-check
$(call msg,Release Project) $(call msg,Release Project)
$(call tbash,release_sh) $(call tbash,release_sh)
## c, clean | remove the generated files
.PHONY: clean .PHONY: clean
c clean: ## remove the generated files c clean:
@rm -f task.mk .task.mk @rm -f task.mk .task.mk
define version_check_sh define version_check_sh
@ -59,8 +63,9 @@ version-check:
@$(call tbash,version_check_sh) @$(call tbash,version_check_sh)
@$(call tprint,>> {a.green}VERSION LOOKS GOOD!{a.end}) @$(call tprint,>> {a.green}VERSION LOOKS GOOD!{a.end})
## info | demonstrate usage of tprint
.PHONY: task .PHONY: task
info: ## demonstrate usage of tprint info:
$(call msg,Info Message) $(call msg,Info Message)
$(call tprint,{a.black_on_cyan}This is task-print output:{a.end}) $(call tprint,{a.black_on_cyan}This is task-print output:{a.end})
$(call tprint,$(mlmsg)) $(call tprint,$(mlmsg))
@ -69,7 +74,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.mk .task.cfg.mk -include .task.mk
.task.mk: $(TEMPLATES) generate.py .task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local .task.mk) $(call msg,re-jinjaing the local .task.mk)
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk) @./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk)

View file

@ -3,7 +3,8 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
export HELP_ARGS export HELP_ARGS
endif endif
h help: ## show this help ## h, help | show this help
h help:
$(call py,help_py) $(call py,help_py)
_help: export SHOW_HIDDEN=true _help: export SHOW_HIDDEN=true
_help: help _help: help
@ -13,15 +14,17 @@ $(foreach v,$(PRINT_VARS),$(eval export $(v)))
vars v: vars v:
$(call py,vars_py,$(PRINT_VARS)) $(call py,vars_py,$(PRINT_VARS))
endif endif
### |> -ws --hidden ### | args: -ws --hidden
### task.mk builtins: |> -d --hidden ### task.mk builtins: | args: -d --hidden
_print-ansi: ## show all possible ansi color code combinations ## _print-ansi | show all possible ansi color code combinations
_print-ansi:
$(call py,print_ansi_py) $(call py,print_ansi_py)
# functions to take f-string literals and pass to python print # functions to take f-string literals and pass to python print
tprint = $(call py,print_py,$(1)) tprint = $(call py,print_py,$(1))
tprint-sh = $(call pysh,print_py,$(1)) tprint-sh = $(call pysh,print_py,$(1))
tconfirm = $(call py,confirm_py,$(1)) tconfirm = $(call py,confirm_py,$(1))
_update-task.mk: ## downloads latest development version of task.mk ## _update-task.mk | downloads latest development version of task.mk
_update-task.mk:
$(call tprint,{a.b_cyan}Updating task.mk{a.end}) $(call tprint,{a.b_cyan}Updating task.mk{a.end})
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
.PHONY: h help _help _print-ansi _update-task.mk .PHONY: h help _help _print-ansi _update-task.mk

View file

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

View file

@ -10,7 +10,8 @@ import sys
from textwrap import wrap from textwrap import wrap
###- ###-
from utils import Ansi, cfg # this is just to trick the LSP during development # this is just to trick the LSP during development
from utils import Ansi, cfg
# -### # -###
##- '$(utils_py)' -## ##- '$(utils_py)' -##
@ -19,22 +20,28 @@ a = ansi = Ansi(target="stdout")
MaxLens = namedtuple("MaxLens", "goal msg") MaxLens = namedtuple("MaxLens", "goal msg")
###- double dollar signs to prevent make escaping them -### ###- double dollar signs to prevent make escaping them -###
###- bets on how long until I break this regex? -### ###- re.X requires all important whitespace is escaped -###
pattern = re.compile( pattern = re.compile(
r""" r"""
^\#\#\
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
\s?
(?: (?:
^\#\#\#\s+ (?:\|\s?args:\s?|\|>)
| \s?
^(?:
(?:\#\#\s+)?
(?P<goal>.*?)(?:\s+\|>|:.*?\#\#)\s+
)
)
(?P<msg>.*?)?\s?
(?:\|>\s+
(?P<msgargs>.*?) (?P<msgargs>.*?)
)? )?
$$ $$
|
^\#\#\#\
(?P<rawmsg>.*?)
\s?
(?:
(?:\|\s?args:|\|\>)
\s?
(?P<rawargs>.*?)
)?
$$
""", """,
re.X, re.X,
) )
@ -182,10 +189,7 @@ def print_help():
items = list(parse_help(gen_makefile())) items = list(parse_help(gen_makefile()))
maxlens = MaxLens( maxlens = MaxLens(
*( *(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
max((*(len(item[x]) for item in items if x in item), 0))
for x in ["goal", "msg"]
)
) )
for item in items: for item in items:
if "goal" in item: if "goal" in item:
@ -194,8 +198,8 @@ def print_help():
item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "") item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "")
) )
) )
else: if "rawmsg" in item:
lines.extend(fmt_rawmsg(item["msg"], item.get("msgargs", ""), maxlens)) lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
lines.append(cfg.epilog) lines.append(cfg.epilog)
print("\n".join(lines)) print("\n".join(lines))

48
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
# version: v22.9.28-13-gfd96a45dev # version: v22.9.28-8-g4fcab2adev
# #
# 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.
@ -25,7 +25,8 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
export HELP_ARGS export HELP_ARGS
endif endif
h help: ## show this help ## h, help | show this help
h help:
$(call py,help_py) $(call py,help_py)
_help: export SHOW_HIDDEN=true _help: export SHOW_HIDDEN=true
_help: help _help: help
@ -35,15 +36,17 @@ $(foreach v,$(PRINT_VARS),$(eval export $(v)))
vars v: vars v:
$(call py,vars_py,$(PRINT_VARS)) $(call py,vars_py,$(PRINT_VARS))
endif endif
### |> -ws --hidden ### | args: -ws --hidden
### task.mk builtins: |> -d --hidden ### task.mk builtins: | args: -d --hidden
_print-ansi: ## show all possible ansi color code combinations ## _print-ansi | show all possible ansi color code combinations
_print-ansi:
$(call py,print_ansi_py) $(call py,print_ansi_py)
# functions to take f-string literals and pass to python print # functions to take f-string literals and pass to python print
tprint = $(call py,print_py,$(1)) tprint = $(call py,print_py,$(1))
tprint-sh = $(call pysh,print_py,$(1)) tprint-sh = $(call pysh,print_py,$(1))
tconfirm = $(call py,confirm_py,$(1)) tconfirm = $(call py,confirm_py,$(1))
_update-task.mk: ## downloads latest development version of task.mk ## _update-task.mk | downloads latest development version of task.mk
_update-task.mk:
$(call tprint,{a.b_cyan}Updating task.mk{a.end}) $(call tprint,{a.b_cyan}Updating task.mk{a.end})
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
.PHONY: h help _help _print-ansi _update-task.mk .PHONY: h help _help _print-ansi _update-task.mk
@ -89,19 +92,25 @@ a = ansi = Ansi(target="stdout")
MaxLens = namedtuple("MaxLens", "goal msg") MaxLens = namedtuple("MaxLens", "goal msg")
pattern = re.compile( pattern = re.compile(
r""" r"""
^\#\#\
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
\s?
(?: (?:
^\#\#\#\s+ (?:\|\s?args:\s?|\|>)
| \s?
^(?:
(?:\#\#\s+)?
(?P<goal>.*?)(?:\s+\|>|:.*?\#\#)\s+
)
)
(?P<msg>.*?)?\s?
(?:\|>\s+
(?P<msgargs>.*?) (?P<msgargs>.*?)
)? )?
$$ $$
|
^\#\#\#\
(?P<rawmsg>.*?)
\s?
(?:
(?:\|\s?args:|\|\>)
\s?
(?P<rawargs>.*?)
)?
$$
""", """,
re.X, re.X,
) )
@ -225,10 +234,7 @@ def print_help():
lines = [cfg.usage] lines = [cfg.usage]
items = list(parse_help(gen_makefile())) items = list(parse_help(gen_makefile()))
maxlens = MaxLens( maxlens = MaxLens(
*( *(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
max((*(len(item[x]) for item in items if x in item), 0))
for x in ["goal", "msg"]
)
) )
for item in items: for item in items:
if "goal" in item: if "goal" in item:
@ -237,8 +243,8 @@ def print_help():
item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "") item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "")
) )
) )
else: if "rawmsg" in item:
lines.extend(fmt_rawmsg(item["msg"], item.get("msgargs", ""), maxlens)) lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
lines.append(cfg.epilog) lines.append(cfg.epilog)
print("\n".join(lines)) print("\n".join(lines))
def print_arg_help(help_args): def print_arg_help(help_args):