Compare commits

..

No commits in common. "c036a27a57ff800a84907374a5a9bb1fa27d22d6" and "26edcad5c5a185f0b02f80fa5dfe0fb3dc71c277" have entirely different histories.

6 changed files with 29 additions and 102 deletions

View file

@ -2,12 +2,12 @@ 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
msg = $(call tprint,{a.bold}==>{a.end} {a.magenta}$(1){a.end} {a.bold}<=={a.end}) header = $(call tprint,{a.bold}==>{a.end} {a.magenta}$(1){a.end} {a.bold}<=={a.end})
## bootstrap | generate local dev environment ## bootstrap | generate local dev environment
.PHONY: bootstrap .PHONY: bootstrap
bootstrap: bootstrap:
$(call msg,Bootstrap Environment) $(call header,Bootstrap Environment)
@mamba create -p ./env python jinja2 black -y @mamba create -p ./env python jinja2 black -y
@mamba run -p ./env pip install yartsu @mamba run -p ./env pip install yartsu
@ -35,12 +35,11 @@ list-%:
## release | release new version of task.mk ## release | release new version of task.mk
.PHONY: release .PHONY: release
release: version-check release: version-check
$(call msg,Release Project) $(call header,Release Project)
@./generate.py $(VERSION) > task.mk @./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' README.md
@git add task.mk README.md @git add task.mk README.md
@git commit -m "release: v$(VERSION)" @git commit -m "release: v$(VERSION)"
@git tag v$(VERSION)
## c, clean | remove the generated files ## c, clean | remove the generated files
.PHONY: clean .PHONY: clean
@ -70,7 +69,7 @@ test-bash:
$(call tbash,bash_script,test bash multiline) $(call tbash,bash_script,test bash multiline)
define mlmsg define msg
{a.b_yellow} {a.b_yellow}
It can even be multiline!{a.end} It can even be multiline!{a.end}
and styles can be defined{a.end} and styles can be defined{a.end}
@ -81,10 +80,9 @@ endef
## info | demonstrate usage of tprint ## info | demonstrate usage of tprint
.PHONY: task .PHONY: task
info: info:
$(call msg, Info Message) $(call header, 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,$(msg))
$(call tprint,{a.custom(fg=(148, 255, 15),bg=(103, 2, 15))}Custom Colors TOO!{a.end})
task.mk: task.mk:
./generate.py $(shell git describe --tags) > task.mk ./generate.py $(shell git describe --tags) > task.mk

View file

@ -30,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.7/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.5/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.7/task.mk -o .task.mk) $(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.5/task.mk -o .task.mk)
``` ```
## Usage ## Usage
@ -59,7 +59,7 @@ build:
... ...
``` ```
Now when you invoke `make help` it will parse these and generate your help output. Now when you invoke `task.mk` it will parse these and generate your help output.
In addition to a generic help output you can expose some configuration settings with `make vars`. In addition to a generic help output you can expose some configuration settings with `make vars`.
To do so define the variables you'd like to print with `PRINT_VARS := VAR1 VAR2 VAR3`. To do so define the variables you'd like to print with `PRINT_VARS := VAR1 VAR2 VAR3`.
@ -88,11 +88,6 @@ To see the available colors and formatting(bold,italic,etc.) use the hidden reci
**Note**: Any help commands starting with an underscore will be ignored. **Note**: Any help commands starting with an underscore will be ignored.
To view hidden `tasks` (or recipes in GNU Make land) you can use `make _help`. To view hidden `tasks` (or recipes in GNU Make land) you can use `make _help`.
In addition, you can use custom colors using the builtin `ansi.custom` or (`a.custom`) method.
It has two optional arguments `fg` and `bg`. Which can be used to specify either an 8-bit color from the [256 colors](https://en.wikipedia.org/wiki/8-bit_color).
Or a tuple/list to define an RBG 24-bit color, for instance `a.custom(fg=(5,10,255))`.
See this project's `make info` for an example.
## Configuration ## Configuration
You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`. You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`.
@ -116,12 +111,6 @@ define USAGE ?=
endef endef
``` ```
To use a custom color for one of the predefined configuration variables specify only the custom method.
```make
HEADER_COLOR = custom(fg=171,bg=227)
```
**NOTE**: `HELP_SEP` does not change the argument definitions syntax only the format of `make help`. **NOTE**: `HELP_SEP` does not change the argument definitions syntax only the format of `make help`.
## Advanced Usage: Embedded Python Scripts ## Advanced Usage: Embedded Python Scripts
@ -173,7 +162,7 @@ zstyle ':completion::complete:make:*:targets' call-command true
## Why Make? ## Why Make?
There are lot of `GNU Make` alternatives but none have near the same level of ubiquity. There are lot of `GNU Make` alternatives but none have near the same level of ubiquity.
This project attaches to `make` some of the native features of [`just`](https://github.com/casey/just), a command runner. This project attaches to `make` some of native features of [`just`](https://github.com/casey/just), a command runner.
Just is a great task runner, but it suffers two problems, users probably don't have it installed already, and there is no way to define file specific recipes. Just is a great task runner, but it suffers two problems, users probably don't have it installed already, and there is no way to define file specific recipes.
Most of my `Makefile`'s are comprised primarily of handy `.PHONY` recipes, but I always end up with a few file specific recipes. Most of my `Makefile`'s are comprised primarily of handy `.PHONY` recipes, but I always end up with a few file specific recipes.
@ -181,13 +170,13 @@ Most of my `Makefile`'s are comprised primarily of handy `.PHONY` recipes, but I
Another interesting project I've evaluated for these purposes is [`go-task/task`](https://github.com/go-task/task). Another interesting project I've evaluated for these purposes is [`go-task/task`](https://github.com/go-task/task).
`Task` has many of the features of `GNU Make` and some novel features of it's own. `Task` has many of the features of `GNU Make` and some novel features of it's own.
But like `just` it's a tool people don't usually already have and it's configured using a `yaml` file. But like `just` it's a tool people don't usually already have and it's configured using a `yaml` file.
`Yaml` files can be finicky to work with and and it uses a golang based shell runtime, not your native shell, which might lead to unexpected behavior. `Yaml` files can be finicky to work with and and it uses a golang based shell runtime not your native shell, which might lead to unexpected behavior.
## Simpler Alternative ## Simpler Alternative
But I just want a basic help output, surely I don't need python for this... you would be right. But I just want a basic help output, surely I don't need python for this... you would be right.
`Task.mk` replaces my old `make help` recipe boilerplate which may better serve you (so long as you have `sed`/`awk`). `Task.mk` replaces my old `make help` recipe boilerplate which may better serve you.
```make ```make

View file

@ -31,6 +31,12 @@ def bg(byte):
class Ansi: class Ansi:
"""ANSI color codes""" """ANSI color codes"""
def setcode(self, name, escape_code):
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
setattr(self, name, "")
else:
setattr(self, name, escape_code)
def __init__(self): def __init__(self):
self.setcode("end", "\033[0m") self.setcode("end", "\033[0m")
for name, byte in color2byte.items(): for name, byte in color2byte.items():
@ -42,42 +48,6 @@ class Ansi:
for name, byte in state2byte.items(): for name, byte in state2byte.items():
self.setcode(name, f"\033[{byte}m") self.setcode(name, f"\033[{byte}m")
def setcode(self, name, escape_code):
"""create attr for style and escape code"""
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
setattr(self, name, "")
else:
setattr(self, name, escape_code)
def custom(self, fg=None, bg=None):
"""use custom color"""
code, end = "\033[", "m"
if fg:
if isinstance(fg, int):
code += f"38;5;{fg}"
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
code += f"38;5;{fg[0]}"
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
code += f"38;2;{';'.join((str(i) for i in fg))}"
else:
print("Expected one or three values for fg as a list")
sys.exit(1)
if bg:
if isinstance(bg, int):
code += f"{';' if fg else ''}48;5;{bg}"
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
code += f"{';' if fg else ''}48;5;{bg[0]}"
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
else:
print("Expected one or three values for bg as a list")
sys.exit(1)
return code + end
a = ansi = Ansi() a = ansi = Ansi()
#% endblock %# #% endblock %#

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: ##- version -## # ##- version -##
# #
# 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.

44
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.7 # v22.9.5-3-g9c67418
# #
# 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.
@ -174,6 +174,12 @@ def bg(byte):
class Ansi: class Ansi:
"""ANSI color codes""" """ANSI color codes"""
def setcode(self, name, escape_code):
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
setattr(self, name, "")
else:
setattr(self, name, escape_code)
def __init__(self): def __init__(self):
self.setcode("end", "\033[0m") self.setcode("end", "\033[0m")
for name, byte in color2byte.items(): for name, byte in color2byte.items():
@ -185,42 +191,6 @@ class Ansi:
for name, byte in state2byte.items(): for name, byte in state2byte.items():
self.setcode(name, f"\033[{byte}m") self.setcode(name, f"\033[{byte}m")
def setcode(self, name, escape_code):
"""create attr for style and escape code"""
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
setattr(self, name, "")
else:
setattr(self, name, escape_code)
def custom(self, fg=None, bg=None):
"""use custom color"""
code, end = "\033[", "m"
if fg:
if isinstance(fg, int):
code += f"38;5;{fg}"
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
code += f"38;5;{fg[0]}"
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
code += f"38;2;{';'.join((str(i) for i in fg))}"
else:
print("Expected one or three values for fg as a list")
sys.exit(1)
if bg:
if isinstance(bg, int):
code += f"{';' if fg else ''}48;5;{bg}"
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
code += f"{';' if fg else ''}48;5;{bg[0]}"
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
else:
print("Expected one or three values for bg as a list")
sys.exit(1)
return code + end
a = ansi = Ansi() a = ansi = Ansi()