mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 18:00:44 -06:00
Compare commits
No commits in common. "3244dba8dcd87291c082409f59c0a55b9cf07458" and "bf0394c5e18f7d72b236462930248876bc8a5336" have entirely different histories.
3244dba8dc
...
bf0394c5e1
9 changed files with 44 additions and 96 deletions
6
.github/workflows/docs.yml
vendored
6
.github/workflows/docs.yml
vendored
|
@ -2,8 +2,8 @@ name: GitHub Pages
|
|||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*.*.*"]
|
||||
workflow_dispatch:
|
||||
branches:
|
||||
- main
|
||||
|
||||
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
10
.task.cfg.mk
|
@ -1,10 +0,0 @@
|
|||
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
|
||||
|
55
Makefile
55
Makefile
|
@ -1,10 +1,12 @@
|
|||
VERSION ?= $(shell git describe --tags --always --dirty=dev)
|
||||
VERSION ?= $(shell git describe --tags --always --dirty | sed s'/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 |> -d -ms b_green --align center
|
||||
## bootstrap | generate local dev environment |> -ms b_magenta -gs b_cyan
|
||||
|
||||
### task.mk development | args: -d -ms b_green --align center
|
||||
## bootstrap | generate local dev environment
|
||||
.PHONY: bootstrap env hooks
|
||||
bootstrap: env hooks
|
||||
env:
|
||||
|
@ -15,7 +17,6 @@ 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:
|
||||
|
@ -28,40 +29,33 @@ 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)
|
||||
$(call tbash,release_sh)
|
||||
@./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)
|
||||
|
||||
## 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:
|
||||
@$(call tprint,>> version: {a.green}$(VERSION){a.end})
|
||||
@$(call tbash,version_check_sh)
|
||||
@$(call tprint,>> {a.green}VERSION LOOKS GOOD!{a.end})
|
||||
@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
|
||||
|
||||
## info | demonstrate usage of tprint
|
||||
.PHONY: task
|
||||
|
@ -74,6 +68,15 @@ 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)
|
||||
|
|
|
@ -54,7 +54,6 @@ 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] ---- #
|
||||
|
@ -88,7 +87,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 `TASKMK_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 `DEBUG=1` when you run `make` and it will first print the script that will be piped to `python`.
|
||||
|
||||
```make
|
||||
define list_files_py
|
||||
|
|
|
@ -5,7 +5,7 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
|
|||
endif
|
||||
## h, help | show this help
|
||||
h help:
|
||||
$(call py,help_py)
|
||||
$(call py,help_py) || { echo "exiting early!"; exit 1; }
|
||||
_help: export SHOW_HIDDEN=true
|
||||
_help: help
|
||||
ifdef PRINT_VARS
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# ---- [config] ---- #
|
||||
-include .task.cfg.mk
|
||||
HEADER_STYLE ?= b_cyan
|
||||
ACCENT_STYLE ?= b_yellow
|
||||
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
||||
|
|
28
src/help.py
28
src/help.py
|
@ -20,30 +20,8 @@ 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>.*?)\s?\|\s?(?P<msg>.*?)
|
||||
\s?
|
||||
(?:
|
||||
(?:\|\s?args:\s?|\|>)
|
||||
\s?
|
||||
(?P<msgargs>.*?)
|
||||
)?
|
||||
$$
|
||||
|
|
||||
^\#\#\#\
|
||||
(?P<rawmsg>.*?)
|
||||
\s?
|
||||
(?:
|
||||
(?:\|\s?args:|\|\>)
|
||||
\s?
|
||||
(?P<rawargs>.*?)
|
||||
)?
|
||||
$$
|
||||
""",
|
||||
re.X,
|
||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
||||
)
|
||||
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
|
||||
|
||||
|
@ -207,14 +185,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), "\n")))
|
||||
print("\n".join(parse_goal(gen_makefile(), arg)))
|
||||
print()
|
||||
|
||||
|
||||
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()
|
||||
|
|
|
@ -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 TASKMK_DEBUG
|
||||
ifdef DEBUG
|
||||
define _debug_runner
|
||||
@printf "$(1) Script:\n";$(_printline);
|
||||
@printf "$(call _create_string,$(3))\n" | cat -n
|
||||
|
|
33
task.mk
33
task.mk
|
@ -1,7 +1,7 @@
|
|||
# }> [github.com/daylinmorgan/task.mk] <{ #
|
||||
# Copyright (c) 2022 Daylin Morgan
|
||||
# MIT License
|
||||
# version: v22.9.28-8-g4fcab2adev
|
||||
# version: v22.9.28-3-g76e9ece-dev
|
||||
#
|
||||
# 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)
|
||||
$(call py,help_py) || { echo "exiting early!"; exit 1; }
|
||||
_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 TASKMK_DEBUG
|
||||
ifdef DEBUG
|
||||
define _debug_runner
|
||||
@printf "$(1) Script:\n";$(_printline);
|
||||
@printf "$(call _create_string,$(3))\n" | cat -n
|
||||
|
@ -91,28 +91,7 @@ $(utils_py)
|
|||
a = ansi = Ansi(target="stdout")
|
||||
MaxLens = namedtuple("MaxLens", "goal msg")
|
||||
pattern = re.compile(
|
||||
r"""
|
||||
^\#\#\
|
||||
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
|
||||
\s?
|
||||
(?:
|
||||
(?:\|\s?args:\s?|\|>)
|
||||
\s?
|
||||
(?P<msgargs>.*?)
|
||||
)?
|
||||
$$
|
||||
|
|
||||
^\#\#\#\
|
||||
(?P<rawmsg>.*?)
|
||||
\s?
|
||||
(?:
|
||||
(?:\|\s?args:|\|\>)
|
||||
\s?
|
||||
(?P<rawargs>.*?)
|
||||
)?
|
||||
$$
|
||||
""",
|
||||
re.X,
|
||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
||||
)
|
||||
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
|
||||
def parseargs(argstring):
|
||||
|
@ -250,12 +229,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), "\n")))
|
||||
print("\n".join(parse_goal(gen_makefile(), arg)))
|
||||
print()
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue