Compare commits

..

No commits in common. "ea85b2378ef7c92a9332eeafad4ca27159d16b6f" and "f62def68fc04eeedb2b7f23e63073733ed987171" have entirely different histories.

8 changed files with 136 additions and 312 deletions

View file

@ -2,10 +2,8 @@ VERSION ?= $(shell git describe --tags --always --dirty | sed s'/dirty/dev/')
TEMPLATES := $(shell find src/ -type f) TEMPLATES := $(shell find src/ -type f)
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
msgfmt = {a.style('==>','bold')} {a.style('$(1)','b_magenta')} {a.style('<==','bold')} msg = $(call tprint,{a.bold}==>{a.end} {a.magenta}$(1){a.end} {a.bold}<=={a.end})
msg = $(call tprint,$(call msgfmt ,$(1)))
### task.mk development | args: -d -ms b_green --align center
## bootstrap | generate local dev environment ## bootstrap | generate local dev environment
.PHONY: bootstrap .PHONY: bootstrap
bootstrap: bootstrap:
@ -14,17 +12,26 @@ bootstrap:
@mamba run -p ./env pip install yartsu @mamba run -p ./env pip install yartsu
@git config core.hooksPath .githooks @git config core.hooksPath .githooks
## l, lint | lint the python ## lint | lint the python
.PHONY: l lint .PHONY: lint
l lint: lint:
$(call msg,Linting)
@black generate.py @black generate.py
@black src/*.py --fast @black src/*.py --fast
## assets | generate assets ## assets | generate assets
.PHONY: assets .PHONY: assets
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 list_files_py
from pathlib import Path
print("files in $(2)")
print([f.name for f in (Path("$(2)").iterdir())])
endef
## list-% | use pathlib.Path to list files
list-%:
$(call py,list_files_py,$*)
## release | release new version of task.mk ## release | release new version of task.mk
.PHONY: release .PHONY: release
@ -41,19 +48,6 @@ release: version-check
c clean: c clean:
@rm -f task.mk .task.mk @rm -f task.mk .task.mk
### | args: --divider --whitespace
### examples of task.mk features | args: --divider --align center --msg-style b_red
define list_files_py
from pathlib import Path
print("files in $(2)")
print([f.name for f in (Path("$(2)").iterdir())])
endef
## list-% | use pathlib.Path to list files
### name the directory in rule (make list-src) | args: --align sep
list-%:
$(call py,list_files_py,$*)
.PHONY: version-check .PHONY: version-check
version-check: version-check:
@if [[ "${VERSION}" == *'-'* ]]; then\ @if [[ "${VERSION}" == *'-'* ]]; then\
@ -76,10 +70,11 @@ endef
test-bash: test-bash:
$(call tbash,bash_script,test bash multiline) $(call tbash,bash_script,test bash multiline)
define mlmsg define mlmsg
{a.b_yellow} {a.b_yellow}
It can even be multiline!{a.end} It can even be multiline!{a.end}
{a.style('and styles can be defined','red')} and styles can be defined{a.end}
as python {a.bold}f-string{a.end} literals as python {a.bold}f-string{a.end} literals
{a.end} {a.end}
endef endef
@ -92,8 +87,6 @@ info:
$(call tprint,$(mlmsg)) $(call tprint,$(mlmsg))
$(call tprint,{a.custom(fg=(148, 255, 15),bg=(103, 2, 15))}Custom Colors TOO!{a.end}) $(call tprint,{a.custom(fg=(148, 255, 15),bg=(103, 2, 15))}Custom Colors TOO!{a.end})
### | args: --divider
task.mk: $(TEMPLATES) generate.py task.mk: $(TEMPLATES) generate.py
./generate.py $(VERSION) > task.mk ./generate.py $(VERSION) > task.mk
@ -101,7 +94,7 @@ define USAGE
{a.$(HEADER_COLOR)}usage:{a.end} {a.$(HEADER_COLOR)}usage:{a.end}
make <recipe> make <recipe>
Turn your {a.style('`Makefile`','b_magenta')} into Turn your {a.b_magenta}`Makefile`{a.end} into
the {a.italic}{a.underline}task runner{a.end} you always needed. the {a.italic}{a.underline}task runner{a.end} you always needed.
See the example output below. See the example output below.
@ -112,4 +105,4 @@ PRINT_VARS := VERSION
-include .task.mk -include .task.mk
.task.mk: $(TEMPLATES) generate.py .task.mk: $(TEMPLATES) generate.py
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk) ./generate.py $(VERSION) > .task.mk

View file

@ -21,8 +21,7 @@ Current Features:
Depends on `GNU Make`, obviously and `Python >=3.7`. Depends on `GNU Make`, obviously and `Python >=3.7`.
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile. Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
I agree, all you need is one file [`.task.mk`](./task.mk). I agree, so I've hacked together a file containing the bits of python we need with some tricks to run it.
You can automagically include it with just two additional lines to your `Makefile` (and probably one to your `.gitignore`) and your good to go.
## Setup ## Setup
@ -31,14 +30,14 @@ If someone tries to invoke `make help` it will download `.task.mk` for them.
```make ```make
-include .task.mk -include .task.mk
$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.14/task.mk -o .task.mk)) $(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.12/task.mk -o .task.mk))
``` ```
You might also consider making it a consistently downloaded dependency if you plan to use any of it's advanced feature set, by dropping the `$(MAKECMDGOALS)` check. You might also consider making it a consistently downloaded dependency if you plan to use any of it's advanced feature set, by dropping the `$(MAKECMDGOALS)` check.
```make ```make
-include .task.mk -include .task.mk
$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.14/task.mk -o .task.mk) $(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.12/task.mk -o .task.mk)
``` ```
## Usage ## Usage

View file

@ -1,4 +1,4 @@
<svg class="rich-terminal shadow" viewBox="0 0 720.3333333333334 692.3333333333334" xmlns="http://www.w3.org/2000/svg"> <svg class="rich-terminal shadow" viewBox="0 0 598.3333333333334 497.13333333333327" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io --> <!-- Generated with Rich https://www.textualize.io -->
<style> <style>
@font-face { @font-face {
@ -16,14 +16,14 @@
font-weight: 700; font-weight: 700;
} }
.terminal-1030366103-matrix { .terminal-3542066451-matrix {
font-family: Fira Code, monospace; font-family: Fira Code, monospace;
font-size: 20px; font-size: 20px;
line-height: 24.4px; line-height: 24.4px;
font-variant-east-asian: full-width; font-variant-east-asian: full-width;
} }
.terminal-1030366103-title { .terminal-3542066451-title {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
font-family: arial; font-family: arial;
@ -33,129 +33,95 @@
-webkit-filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7)); -webkit-filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7));
filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7)); filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7));
} }
.terminal-1030366103-r1 { fill: #94e2d5;font-weight: bold } .terminal-3542066451-r1 { fill: #94e2d5;font-weight: bold }
.terminal-1030366103-r2 { fill: #c6d0f5 } .terminal-3542066451-r2 { fill: #c6d0f5 }
.terminal-1030366103-r3 { fill: #f5c2e7;font-weight: bold } .terminal-3542066451-r3 { fill: #f5c2e7;font-weight: bold }
.terminal-1030366103-r4 { fill: #c6d0f5;font-style: italic;;text-decoration: underline; } .terminal-3542066451-r4 { fill: #c6d0f5;font-style: italic;;text-decoration: underline; }
.terminal-1030366103-r5 { fill: #a6e3a1;font-weight: bold } .terminal-3542066451-r5 { fill: #f9e2af;font-weight: bold }
.terminal-1030366103-r6 { fill: #f9e2af;font-weight: bold } .terminal-3542066451-r6 { fill: #8288a5 }
.terminal-1030366103-r7 { fill: #8288a5 }
.terminal-1030366103-r8 { fill: #f38ba8;font-weight: bold }
</style> </style>
<defs> <defs>
<clipPath id="terminal-1030366103-clip-terminal"> <clipPath id="terminal-3542066451-clip-terminal">
<rect x="0" y="0" width="682.1999999999999" height="609.0" /> <rect x="0" y="0" width="560.1999999999999" height="413.79999999999995" />
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-0"> <clipPath id="terminal-3542066451-line-0">
<rect x="0" y="1.5" width="683.2" height="24.65"/> <rect x="0" y="1.5" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-1"> <clipPath id="terminal-3542066451-line-1">
<rect x="0" y="25.9" width="683.2" height="24.65"/> <rect x="0" y="25.9" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-2"> <clipPath id="terminal-3542066451-line-2">
<rect x="0" y="50.3" width="683.2" height="24.65"/> <rect x="0" y="50.3" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-3"> <clipPath id="terminal-3542066451-line-3">
<rect x="0" y="74.7" width="683.2" height="24.65"/> <rect x="0" y="74.7" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-4"> <clipPath id="terminal-3542066451-line-4">
<rect x="0" y="99.1" width="683.2" height="24.65"/> <rect x="0" y="99.1" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-5"> <clipPath id="terminal-3542066451-line-5">
<rect x="0" y="123.5" width="683.2" height="24.65"/> <rect x="0" y="123.5" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-6"> <clipPath id="terminal-3542066451-line-6">
<rect x="0" y="147.9" width="683.2" height="24.65"/> <rect x="0" y="147.9" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-7"> <clipPath id="terminal-3542066451-line-7">
<rect x="0" y="172.3" width="683.2" height="24.65"/> <rect x="0" y="172.3" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-8"> <clipPath id="terminal-3542066451-line-8">
<rect x="0" y="196.7" width="683.2" height="24.65"/> <rect x="0" y="196.7" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-9"> <clipPath id="terminal-3542066451-line-9">
<rect x="0" y="221.1" width="683.2" height="24.65"/> <rect x="0" y="221.1" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-10"> <clipPath id="terminal-3542066451-line-10">
<rect x="0" y="245.5" width="683.2" height="24.65"/> <rect x="0" y="245.5" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-11"> <clipPath id="terminal-3542066451-line-11">
<rect x="0" y="269.9" width="683.2" height="24.65"/> <rect x="0" y="269.9" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-12"> <clipPath id="terminal-3542066451-line-12">
<rect x="0" y="294.3" width="683.2" height="24.65"/> <rect x="0" y="294.3" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-13"> <clipPath id="terminal-3542066451-line-13">
<rect x="0" y="318.7" width="683.2" height="24.65"/> <rect x="0" y="318.7" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-14"> <clipPath id="terminal-3542066451-line-14">
<rect x="0" y="343.1" width="683.2" height="24.65"/> <rect x="0" y="343.1" width="561.2" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1030366103-line-15"> <clipPath id="terminal-3542066451-line-15">
<rect x="0" y="367.5" width="683.2" height="24.65"/> <rect x="0" y="367.5" width="561.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-16">
<rect x="0" y="391.9" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-17">
<rect x="0" y="416.3" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-18">
<rect x="0" y="440.7" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-19">
<rect x="0" y="465.1" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-20">
<rect x="0" y="489.5" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-21">
<rect x="0" y="513.9" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-22">
<rect x="0" y="538.3" width="683.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-1030366103-line-23">
<rect x="0" y="562.7" width="683.2" height="24.65"/>
</clipPath> </clipPath>
</defs> </defs>
<rect fill="#1e1e2e" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="10.1667" y="1" width="700" height="658" rx="8"/><text class="terminal-1030366103-title" fill="#c6d0f5" text-anchor="middle" x="350" y="27">make&#160;help</text> <rect fill="#1e1e2e" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="10.1667" y="1" width="578" height="462.8" rx="8"/><text class="terminal-3542066451-title" fill="#c6d0f5" text-anchor="middle" x="289" y="27">make&#160;help</text>
<g transform="translate(32,22)"> <g transform="translate(32,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/> <circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/> <circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/> <circle cx="44" cy="0" r="7" fill="#28c840"/>
</g> </g>
<g transform="translate(18.166666666666664, 41) scale(.95)" clip-path="url(#terminal-1030366103-clip-terminal)"> <g transform="translate(18.166666666666664, 41) scale(.95)" clip-path="url(#terminal-3542066451-clip-terminal)">
<g class="terminal-1030366103-matrix"> <g class="terminal-3542066451-matrix">
<text class="terminal-1030366103-r1" x="0" y="20" textLength="73.2" clip-path="url(#terminal-1030366103-line-0)">usage:</text><text class="terminal-1030366103-r2" x="683.2" y="20" textLength="12.2" clip-path="url(#terminal-1030366103-line-0)"> <text class="terminal-3542066451-r1" x="0" y="20" textLength="73.2" clip-path="url(#terminal-3542066451-line-0)">usage:</text><text class="terminal-3542066451-r2" x="561.2" y="20" textLength="12.2" clip-path="url(#terminal-3542066451-line-0)">
</text><text class="terminal-1030366103-r2" x="97.6" y="44.4" textLength="158.6" clip-path="url(#terminal-1030366103-line-1)">make&#160;&lt;recipe&gt;</text><text class="terminal-1030366103-r2" x="683.2" y="44.4" textLength="12.2" clip-path="url(#terminal-1030366103-line-1)"> </text><text class="terminal-3542066451-r2" x="97.6" y="44.4" textLength="158.6" clip-path="url(#terminal-3542066451-line-1)">make&#160;&lt;recipe&gt;</text><text class="terminal-3542066451-r2" x="561.2" y="44.4" textLength="12.2" clip-path="url(#terminal-3542066451-line-1)">
</text><text class="terminal-1030366103-r2" x="683.2" y="68.8" textLength="12.2" clip-path="url(#terminal-1030366103-line-2)"> </text><text class="terminal-3542066451-r2" x="561.2" y="68.8" textLength="12.2" clip-path="url(#terminal-3542066451-line-2)">
</text><text class="terminal-1030366103-r2" x="0" y="93.2" textLength="146.4" clip-path="url(#terminal-1030366103-line-3)">&#160;&#160;Turn&#160;your&#160;</text><text class="terminal-1030366103-r3" x="146.4" y="93.2" textLength="122" clip-path="url(#terminal-1030366103-line-3)">`Makefile`</text><text class="terminal-1030366103-r2" x="268.4" y="93.2" textLength="61" clip-path="url(#terminal-1030366103-line-3)">&#160;into</text><text class="terminal-1030366103-r2" x="683.2" y="93.2" textLength="12.2" clip-path="url(#terminal-1030366103-line-3)"> </text><text class="terminal-3542066451-r2" x="0" y="93.2" textLength="146.4" clip-path="url(#terminal-3542066451-line-3)">&#160;&#160;Turn&#160;your&#160;</text><text class="terminal-3542066451-r3" x="146.4" y="93.2" textLength="122" clip-path="url(#terminal-3542066451-line-3)">`Makefile`</text><text class="terminal-3542066451-r2" x="268.4" y="93.2" textLength="61" clip-path="url(#terminal-3542066451-line-3)">&#160;into</text><text class="terminal-3542066451-r2" x="561.2" y="93.2" textLength="12.2" clip-path="url(#terminal-3542066451-line-3)">
</text><text class="terminal-1030366103-r2" x="0" y="117.6" textLength="73.2" clip-path="url(#terminal-1030366103-line-4)">&#160;&#160;the&#160;</text><text class="terminal-1030366103-r4" x="73.2" y="117.6" textLength="134.2" clip-path="url(#terminal-1030366103-line-4)">task&#160;runner</text><text class="terminal-1030366103-r2" x="207.4" y="117.6" textLength="231.8" clip-path="url(#terminal-1030366103-line-4)">&#160;you&#160;always&#160;needed.</text><text class="terminal-1030366103-r2" x="683.2" y="117.6" textLength="12.2" clip-path="url(#terminal-1030366103-line-4)"> </text><text class="terminal-3542066451-r2" x="0" y="117.6" textLength="73.2" clip-path="url(#terminal-3542066451-line-4)">&#160;&#160;the&#160;</text><text class="terminal-3542066451-r4" x="73.2" y="117.6" textLength="134.2" clip-path="url(#terminal-3542066451-line-4)">task&#160;runner</text><text class="terminal-3542066451-r2" x="207.4" y="117.6" textLength="231.8" clip-path="url(#terminal-3542066451-line-4)">&#160;you&#160;always&#160;needed.</text><text class="terminal-3542066451-r2" x="561.2" y="117.6" textLength="12.2" clip-path="url(#terminal-3542066451-line-4)">
</text><text class="terminal-1030366103-r2" x="0" y="142" textLength="378.2" clip-path="url(#terminal-1030366103-line-5)">&#160;&#160;See&#160;the&#160;example&#160;output&#160;below.</text><text class="terminal-1030366103-r2" x="683.2" y="142" textLength="12.2" clip-path="url(#terminal-1030366103-line-5)"> </text><text class="terminal-3542066451-r2" x="0" y="142" textLength="378.2" clip-path="url(#terminal-3542066451-line-5)">&#160;&#160;See&#160;the&#160;example&#160;output&#160;below.</text><text class="terminal-3542066451-r2" x="561.2" y="142" textLength="12.2" clip-path="url(#terminal-3542066451-line-5)">
</text><text class="terminal-1030366103-r2" x="683.2" y="166.4" textLength="12.2" clip-path="url(#terminal-1030366103-line-6)"> </text><text class="terminal-3542066451-r2" x="561.2" y="166.4" textLength="12.2" clip-path="url(#terminal-3542066451-line-6)">
</text><text class="terminal-1030366103-r5" x="24.4" y="190.8" textLength="475.8" clip-path="url(#terminal-1030366103-line-7)">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;task.mk&#160;development&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-1030366103-r2" x="683.2" y="190.8" textLength="12.2" clip-path="url(#terminal-1030366103-line-7)"> </text><text class="terminal-3542066451-r5" x="24.4" y="190.8" textLength="109.8" clip-path="url(#terminal-3542066451-line-7)">bootstrap</text><text class="terminal-3542066451-r2" x="134.2" y="190.8" textLength="36.6" clip-path="url(#terminal-3542066451-line-7)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="190.8" textLength="366" clip-path="url(#terminal-3542066451-line-7)">generate&#160;local&#160;dev&#160;environment</text><text class="terminal-3542066451-r2" x="561.2" y="190.8" textLength="12.2" clip-path="url(#terminal-3542066451-line-7)">
</text><text class="terminal-1030366103-r2" x="0" y="215.2" textLength="536.8" clip-path="url(#terminal-1030366103-line-8)">&#160;&#160;──────────────────────────────────────────</text><text class="terminal-1030366103-r2" x="683.2" y="215.2" textLength="12.2" clip-path="url(#terminal-1030366103-line-8)"> </text><text class="terminal-3542066451-r5" x="24.4" y="215.2" textLength="109.8" clip-path="url(#terminal-3542066451-line-8)">&#160;&#160;&#160;&#160;&#160;lint</text><text class="terminal-3542066451-r2" x="134.2" y="215.2" textLength="36.6" clip-path="url(#terminal-3542066451-line-8)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="215.2" textLength="183" clip-path="url(#terminal-3542066451-line-8)">lint&#160;the&#160;python</text><text class="terminal-3542066451-r2" x="561.2" y="215.2" textLength="12.2" clip-path="url(#terminal-3542066451-line-8)">
</text><text class="terminal-1030366103-r6" x="0" y="239.6" textLength="134.2" clip-path="url(#terminal-1030366103-line-9)">&#160;&#160;bootstrap</text><text class="terminal-1030366103-r2" x="134.2" y="239.6" textLength="36.6" clip-path="url(#terminal-1030366103-line-9)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="239.6" textLength="366" clip-path="url(#terminal-1030366103-line-9)">generate&#160;local&#160;dev&#160;environment</text><text class="terminal-1030366103-r2" x="683.2" y="239.6" textLength="12.2" clip-path="url(#terminal-1030366103-line-9)"> </text><text class="terminal-3542066451-r5" x="24.4" y="239.6" textLength="109.8" clip-path="url(#terminal-3542066451-line-9)">&#160;&#160;&#160;assets</text><text class="terminal-3542066451-r2" x="134.2" y="239.6" textLength="36.6" clip-path="url(#terminal-3542066451-line-9)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="239.6" textLength="183" clip-path="url(#terminal-3542066451-line-9)">generate&#160;assets</text><text class="terminal-3542066451-r2" x="561.2" y="239.6" textLength="12.2" clip-path="url(#terminal-3542066451-line-9)">
</text><text class="terminal-1030366103-r6" x="0" y="264" textLength="134.2" clip-path="url(#terminal-1030366103-line-10)">&#160;&#160;&#160;&#160;l,&#160;lint</text><text class="terminal-1030366103-r2" x="134.2" y="264" textLength="36.6" clip-path="url(#terminal-1030366103-line-10)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="264" textLength="183" clip-path="url(#terminal-1030366103-line-10)">lint&#160;the&#160;python</text><text class="terminal-1030366103-r2" x="683.2" y="264" textLength="12.2" clip-path="url(#terminal-1030366103-line-10)"> </text><text class="terminal-3542066451-r5" x="24.4" y="264" textLength="109.8" clip-path="url(#terminal-3542066451-line-10)">&#160;&#160;&#160;list-%</text><text class="terminal-3542066451-r2" x="134.2" y="264" textLength="36.6" clip-path="url(#terminal-3542066451-line-10)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="264" textLength="366" clip-path="url(#terminal-3542066451-line-10)">use&#160;pathlib.Path&#160;to&#160;list&#160;files</text><text class="terminal-3542066451-r2" x="561.2" y="264" textLength="12.2" clip-path="url(#terminal-3542066451-line-10)">
</text><text class="terminal-1030366103-r6" x="0" y="288.4" textLength="134.2" clip-path="url(#terminal-1030366103-line-11)">&#160;&#160;&#160;&#160;&#160;assets</text><text class="terminal-1030366103-r2" x="134.2" y="288.4" textLength="36.6" clip-path="url(#terminal-1030366103-line-11)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="288.4" textLength="183" clip-path="url(#terminal-1030366103-line-11)">generate&#160;assets</text><text class="terminal-1030366103-r2" x="683.2" y="288.4" textLength="12.2" clip-path="url(#terminal-1030366103-line-11)"> </text><text class="terminal-3542066451-r5" x="24.4" y="288.4" textLength="109.8" clip-path="url(#terminal-3542066451-line-11)">&#160;&#160;release</text><text class="terminal-3542066451-r2" x="134.2" y="288.4" textLength="36.6" clip-path="url(#terminal-3542066451-line-11)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="288.4" textLength="366" clip-path="url(#terminal-3542066451-line-11)">release&#160;new&#160;version&#160;of&#160;task.mk</text><text class="terminal-3542066451-r2" x="561.2" y="288.4" textLength="12.2" clip-path="url(#terminal-3542066451-line-11)">
</text><text class="terminal-1030366103-r6" x="0" y="312.8" textLength="134.2" clip-path="url(#terminal-1030366103-line-12)">&#160;&#160;&#160;&#160;release</text><text class="terminal-1030366103-r2" x="134.2" y="312.8" textLength="36.6" clip-path="url(#terminal-1030366103-line-12)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="312.8" textLength="366" clip-path="url(#terminal-1030366103-line-12)">release&#160;new&#160;version&#160;of&#160;task.mk</text><text class="terminal-1030366103-r2" x="683.2" y="312.8" textLength="12.2" clip-path="url(#terminal-1030366103-line-12)"> </text><text class="terminal-3542066451-r5" x="24.4" y="312.8" textLength="109.8" clip-path="url(#terminal-3542066451-line-12)">&#160;c,&#160;clean</text><text class="terminal-3542066451-r2" x="134.2" y="312.8" textLength="36.6" clip-path="url(#terminal-3542066451-line-12)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="312.8" textLength="317.2" clip-path="url(#terminal-3542066451-line-12)">remove&#160;the&#160;generated&#160;files</text><text class="terminal-3542066451-r2" x="561.2" y="312.8" textLength="12.2" clip-path="url(#terminal-3542066451-line-12)">
</text><text class="terminal-1030366103-r6" x="0" y="337.2" textLength="134.2" clip-path="url(#terminal-1030366103-line-13)">&#160;&#160;&#160;c,&#160;clean</text><text class="terminal-1030366103-r2" x="134.2" y="337.2" textLength="36.6" clip-path="url(#terminal-1030366103-line-13)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="337.2" textLength="317.2" clip-path="url(#terminal-1030366103-line-13)">remove&#160;the&#160;generated&#160;files</text><text class="terminal-1030366103-r2" x="683.2" y="337.2" textLength="12.2" clip-path="url(#terminal-1030366103-line-13)"> </text><text class="terminal-3542066451-r5" x="24.4" y="337.2" textLength="109.8" clip-path="url(#terminal-3542066451-line-13)">&#160;&#160;&#160;&#160;&#160;info</text><text class="terminal-3542066451-r2" x="134.2" y="337.2" textLength="36.6" clip-path="url(#terminal-3542066451-line-13)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="337.2" textLength="329.4" clip-path="url(#terminal-3542066451-line-13)">demonstrate&#160;usage&#160;of&#160;tprint</text><text class="terminal-3542066451-r2" x="561.2" y="337.2" textLength="12.2" clip-path="url(#terminal-3542066451-line-13)">
</text><text class="terminal-1030366103-r2" x="0" y="361.6" textLength="536.8" clip-path="url(#terminal-1030366103-line-14)">&#160;&#160;──────────────────────────────────────────</text><text class="terminal-1030366103-r2" x="683.2" y="361.6" textLength="12.2" clip-path="url(#terminal-1030366103-line-14)"> </text><text class="terminal-3542066451-r5" x="24.4" y="361.6" textLength="109.8" clip-path="url(#terminal-3542066451-line-14)">&#160;&#160;h,&#160;help</text><text class="terminal-3542066451-r2" x="134.2" y="361.6" textLength="36.6" clip-path="url(#terminal-3542066451-line-14)">&#160;|&#160;</text><text class="terminal-3542066451-r6" x="170.8" y="361.6" textLength="170.8" clip-path="url(#terminal-3542066451-line-14)">show&#160;this&#160;help</text><text class="terminal-3542066451-r2" x="561.2" y="361.6" textLength="12.2" clip-path="url(#terminal-3542066451-line-14)">
</text><text class="terminal-1030366103-r2" x="683.2" y="386" textLength="12.2" clip-path="url(#terminal-1030366103-line-15)"> </text><text class="terminal-3542066451-r2" x="561.2" y="386" textLength="12.2" clip-path="url(#terminal-3542066451-line-15)">
</text><text class="terminal-1030366103-r8" x="24.4" y="410.4" textLength="475.8" clip-path="url(#terminal-1030366103-line-16)">&#160;&#160;&#160;&#160;&#160;&#160;examples&#160;of&#160;task.mk&#160;features&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-1030366103-r2" x="683.2" y="410.4" textLength="12.2" clip-path="url(#terminal-1030366103-line-16)"> </text><text class="terminal-3542066451-r2" x="0" y="410.4" textLength="561.2" clip-path="url(#terminal-3542066451-line-16)">for&#160;more&#160;info:&#160;github.com/daylinmorgan/task.mk</text><text class="terminal-3542066451-r2" x="561.2" y="410.4" textLength="12.2" clip-path="url(#terminal-3542066451-line-16)">
</text><text class="terminal-1030366103-r2" x="0" y="434.8" textLength="536.8" clip-path="url(#terminal-1030366103-line-17)">&#160;&#160;──────────────────────────────────────────</text><text class="terminal-1030366103-r2" x="683.2" y="434.8" textLength="12.2" clip-path="url(#terminal-1030366103-line-17)">
</text><text class="terminal-1030366103-r6" x="0" y="459.2" textLength="134.2" clip-path="url(#terminal-1030366103-line-18)">&#160;&#160;&#160;&#160;&#160;list-%</text><text class="terminal-1030366103-r2" x="134.2" y="459.2" textLength="36.6" clip-path="url(#terminal-1030366103-line-18)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="459.2" textLength="366" clip-path="url(#terminal-1030366103-line-18)">use&#160;pathlib.Path&#160;to&#160;list&#160;files</text><text class="terminal-1030366103-r2" x="683.2" y="459.2" textLength="12.2" clip-path="url(#terminal-1030366103-line-18)">
</text><text class="terminal-1030366103-r7" x="170.8" y="483.6" textLength="512.4" clip-path="url(#terminal-1030366103-line-19)">name&#160;the&#160;directory&#160;in&#160;rule&#160;(make&#160;list-src)</text><text class="terminal-1030366103-r2" x="683.2" y="483.6" textLength="12.2" clip-path="url(#terminal-1030366103-line-19)">
</text><text class="terminal-1030366103-r6" x="0" y="508" textLength="134.2" clip-path="url(#terminal-1030366103-line-20)">&#160;&#160;&#160;&#160;&#160;&#160;&#160;info</text><text class="terminal-1030366103-r2" x="134.2" y="508" textLength="36.6" clip-path="url(#terminal-1030366103-line-20)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="508" textLength="329.4" clip-path="url(#terminal-1030366103-line-20)">demonstrate&#160;usage&#160;of&#160;tprint</text><text class="terminal-1030366103-r2" x="683.2" y="508" textLength="12.2" clip-path="url(#terminal-1030366103-line-20)">
</text><text class="terminal-1030366103-r2" x="0" y="532.4" textLength="536.8" clip-path="url(#terminal-1030366103-line-21)">&#160;&#160;──────────────────────────────────────────</text><text class="terminal-1030366103-r2" x="683.2" y="532.4" textLength="12.2" clip-path="url(#terminal-1030366103-line-21)">
</text><text class="terminal-1030366103-r6" x="0" y="556.8" textLength="134.2" clip-path="url(#terminal-1030366103-line-22)">&#160;&#160;&#160;&#160;h,&#160;help</text><text class="terminal-1030366103-r2" x="134.2" y="556.8" textLength="36.6" clip-path="url(#terminal-1030366103-line-22)">&#160;&#160;</text><text class="terminal-1030366103-r7" x="170.8" y="556.8" textLength="170.8" clip-path="url(#terminal-1030366103-line-22)">show&#160;this&#160;help</text><text class="terminal-1030366103-r2" x="683.2" y="556.8" textLength="12.2" clip-path="url(#terminal-1030366103-line-22)">
</text><text class="terminal-1030366103-r2" x="683.2" y="581.2" textLength="12.2" clip-path="url(#terminal-1030366103-line-23)">
</text><text class="terminal-1030366103-r2" x="0" y="605.6" textLength="561.2" clip-path="url(#terminal-1030366103-line-24)">for&#160;more&#160;info:&#160;github.com/daylinmorgan/task.mk</text><text class="terminal-1030366103-r2" x="683.2" y="605.6" textLength="12.2" clip-path="url(#terminal-1030366103-line-24)">
</text> </text>
</g> </g>
</g> </g>

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -33,8 +33,6 @@ class Ansi:
def __init__(self): def __init__(self):
self.setcode("end", "\033[0m") self.setcode("end", "\033[0m")
self.setcode("default", "\033[38m")
self.setcode("bg_default", "\033[48m")
for name, byte in color2byte.items(): for name, byte in color2byte.items():
self.setcode(name, f"\033[{fg(byte)}m") self.setcode(name, f"\033[{fg(byte)}m")
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m") self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
@ -80,13 +78,6 @@ class Ansi:
return code + end return code + end
def style(self, text, style):
if style not in self.__dict__:
print(f"unknown style {style}")
sys.exit(1)
else:
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
a = ansi = Ansi() a = ansi = Ansi()
#% endblock %# #% endblock %#

View file

@ -4,9 +4,8 @@ PARAMS_COLOR ?= b_magenta
ACCENT_COLOR ?= b_yellow ACCENT_COLOR ?= b_yellow
GOAL_COLOR ?= $(ACCENT_COLOR) GOAL_COLOR ?= $(ACCENT_COLOR)
MSG_COLOR ?= faint MSG_COLOR ?= faint
DIVIDER_COLOR ?= default HELP_SEP ?= |
DIVIDER ?= HELP_SORT ?= # sort goals alphabetically
HELP_SEP ?=
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=

View file

@ -1,100 +1,40 @@
#% extends "py-script.mk" %# #% extends "py-script.mk" %#
#% block name %#help#% endblock %# #% block name %#help#% endblock %#
#% block script %# #% block script %#
import argparse
from collections import namedtuple
import os import os
import re import re
from typing import Any
##- '$(ansi_py)' -## ##- '$(ansi_py)' -##
ansi: Any pattern = re.compile(r"^## (.*) \| (.*)")
MaxLens = namedtuple("MaxLens", "goal msg") makefile = ""
for file in os.getenv("MAKEFILE_LIST").split():
# double dollar signs to prevent make escaping them
pattern = re.compile(
r"^## (?P<goal>.*) \| (?P<msg>.*)|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<args>.*?))?$$"
)
def rawargs(argstring):
parser = argparse.ArgumentParser()
parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true")
parser.add_argument("-ms", "--msg-style", type=str)
return parser.parse_args(argstring.split())
def gen_makefile():
makefile = ""
for file in os.getenv("MAKEFILE_LIST").split():
with open(file, "r") as f: with open(file, "r") as f:
makefile += f.read() + "\n\n" makefile += f.read() + "\n\n"
return makefile
def parse_make(file): def get_help(file):
for line in file.splitlines(): for line in file.splitlines():
match = pattern.search(line) match = pattern.search(line)
if match: if match:
if not os.getenv("SHOW_HIDDEN") and str( if not os.getenv("SHOW_HIDDEN") and match.groups()[0].startswith("_"):
match.groupdict().get("goal") continue
).startswith("_"):
pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield match.groups()
def print_goal(goal, msg, max_goal_len): print(f"""$(USAGE)""")
goals = list(get_help(makefile))
if os.getenv("SORT_HELP", False):
goals.sort(key=lambda i: i[0])
goal_len = max(len(goal[0]) for goal in goals)
for goal, msg in goals:
print( print(
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)") f" {ansi.$(GOAL_COLOR)}{goal:>{goal_len}}{ansi.end} $(HELP_SEP) {ansi.$(MSG_COLOR)}{msg}{ansi.end}"
+ " $(HELP_SEP) "
+ ansi.style(msg, "$(MSG_COLOR)")
) )
print(f"""$(EPILOG)""")
def print_rawmsg(msg, argstr, maxlens):
args = rawargs(argstr)
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
if msg:
if args.align == "sep":
print(
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
)
elif args.align == "center":
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
else:
print(f" {ansi.style(msg,msg_style)}")
if args.divider:
print(
ansi.style(
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
"$(DIVIDER_COLOR)",
)
)
if args.whitespace:
print()
def print_help():
print(f"""$(USAGE)""")
items = list(parse_make(gen_makefile()))
maxlens = MaxLens(
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
)
for item in items:
if "goal" in item:
print_goal(item["goal"], item["msg"], maxlens.goal)
if "rawmsg" in item:
print_rawmsg(item["rawmsg"], item.get("args", ""), maxlens)
print(f"""$(EPILOG)""")
print_help()
#% endblock %# #% endblock %#

View file

@ -3,7 +3,10 @@
#% block script %# #% block script %#
##- '$(ansi_py)' -## ##- '$(ansi_py)' -##
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__} codes_names = {
getattr(ansi, attr): attr
for attr in ansi.__dict__
}
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)): for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
print("{:>20} {}".format(codes_names[code], code + "******" + ansi.end)) print("{:>20} {}".format(codes_names[code], code + "******" + ansi.end))

115
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: 22.9.14 # version: v22.9.12-dev
# #
# task.mk should be included at the bottom of your Makefile. # task.mk should be included at the bottom of your Makefile.
# 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.
@ -13,9 +13,8 @@ PARAMS_COLOR ?= b_magenta
ACCENT_COLOR ?= b_yellow ACCENT_COLOR ?= b_yellow
GOAL_COLOR ?= $(ACCENT_COLOR) GOAL_COLOR ?= $(ACCENT_COLOR)
MSG_COLOR ?= faint MSG_COLOR ?= faint
DIVIDER_COLOR ?= default HELP_SEP ?= |
DIVIDER ?= HELP_SORT ?= # sort goals alphabetically
HELP_SEP ?=
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=
@ -96,102 +95,42 @@ pysh = printf "$(call create_string,$($(1)))" | python3
define help_py define help_py
import argparse
from collections import namedtuple
import os import os
import re import re
from typing import Any
$(ansi_py) $(ansi_py)
ansi: Any pattern = re.compile(r"^## (.*) \| (.*)")
MaxLens = namedtuple("MaxLens", "goal msg") makefile = ""
for file in os.getenv("MAKEFILE_LIST").split():
# double dollar signs to prevent make escaping them
pattern = re.compile(
r"^## (?P<goal>.*) \| (?P<msg>.*)|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<args>.*?))?$$"
)
def rawargs(argstring):
parser = argparse.ArgumentParser()
parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true")
parser.add_argument("-ms", "--msg-style", type=str)
return parser.parse_args(argstring.split())
def gen_makefile():
makefile = ""
for file in os.getenv("MAKEFILE_LIST").split():
with open(file, "r") as f: with open(file, "r") as f:
makefile += f.read() + "\n\n" makefile += f.read() + "\n\n"
return makefile
def parse_make(file): def get_help(file):
for line in file.splitlines(): for line in file.splitlines():
match = pattern.search(line) match = pattern.search(line)
if match: if match:
if not os.getenv("SHOW_HIDDEN") and str( if not os.getenv("SHOW_HIDDEN") and match.groups()[0].startswith("_"):
match.groupdict().get("goal") continue
).startswith("_"):
pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield match.groups()
def print_goal(goal, msg, max_goal_len): print(f"""$(USAGE)""")
goals = list(get_help(makefile))
if os.getenv("SORT_HELP", False):
goals.sort(key=lambda i: i[0])
goal_len = max(len(goal[0]) for goal in goals)
for goal, msg in goals:
print( print(
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)") f" {ansi.$(GOAL_COLOR)}{goal:>{goal_len}}{ansi.end} $(HELP_SEP) {ansi.$(MSG_COLOR)}{msg}{ansi.end}"
+ " $(HELP_SEP) "
+ ansi.style(msg, "$(MSG_COLOR)")
) )
print(f"""$(EPILOG)""")
def print_rawmsg(msg, argstr, maxlens):
args = rawargs(argstr)
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
if msg:
if args.align == "sep":
print(
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
)
elif args.align == "center":
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
else:
print(f" {ansi.style(msg,msg_style)}")
if args.divider:
print(
ansi.style(
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
"$(DIVIDER_COLOR)",
)
)
if args.whitespace:
print()
def print_help():
print(f"""$(USAGE)""")
items = list(parse_make(gen_makefile()))
maxlens = MaxLens(
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
)
for item in items:
if "goal" in item:
print_goal(item["goal"], item["msg"], maxlens.goal)
if "rawmsg" in item:
print_rawmsg(item["rawmsg"], item.get("args", ""), maxlens)
print(f"""$(EPILOG)""")
print_help()
endef endef
@ -229,8 +168,6 @@ class Ansi:
def __init__(self): def __init__(self):
self.setcode("end", "\033[0m") self.setcode("end", "\033[0m")
self.setcode("default", "\033[38m")
self.setcode("bg_default", "\033[48m")
for name, byte in color2byte.items(): for name, byte in color2byte.items():
self.setcode(name, f"\033[{fg(byte)}m") self.setcode(name, f"\033[{fg(byte)}m")
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m") self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
@ -276,13 +213,6 @@ class Ansi:
return code + end return code + end
def style(self, text, style):
if style not in self.__dict__:
print(f"unknown style {style}")
sys.exit(1)
else:
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
a = ansi = Ansi() a = ansi = Ansi()
@ -300,7 +230,10 @@ define print_ansi_py
$(ansi_py) $(ansi_py)
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__} codes_names = {
getattr(ansi, attr): attr
for attr in ansi.__dict__
}
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)): for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
print("{:>20} {}".format(codes_names[code], code + "******" + ansi.end)) print("{:>20} {}".format(codes_names[code], code + "******" + ansi.end))