chore: reduce final output whitespace

This commit is contained in:
Daylin Morgan 2022-09-16 12:47:40 -05:00
parent 7a04912891
commit 2e4a82a6f8
5 changed files with 15 additions and 38 deletions

View file

@ -5,7 +5,7 @@ from pathlib import Path
import jinja2 import jinja2
py_script_names = ["help", "ansi", "info", "print-ansi", "vars","confirm"] py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm"]
def get_jinja_env(): def get_jinja_env():
@ -16,6 +16,8 @@ def get_jinja_env():
block_end_string="%#", block_end_string="%#",
variable_start_string="##-", variable_start_string="##-",
variable_end_string="-##", variable_end_string="-##",
comment_start_string="###-",
comment_end_string="-###",
) )
@ -24,6 +26,10 @@ def render(env, template, **kwargs):
return template.render(**kwargs) return template.render(**kwargs)
def dropnewlines(text):
return "\n".join([line for line in text.splitlines() if line])
def main(): def main():
if len(sys.argv) == 2: if len(sys.argv) == 2:
version = sys.argv[1] version = sys.argv[1]
@ -31,9 +37,7 @@ def main():
version = "dev" version = "dev"
env = get_jinja_env() env = get_jinja_env()
py_scripts = [dropnewlines(render(env, f"{name}.py")) for name in py_script_names]
py_scripts = [render(env, f"{name}.py") for name in py_script_names]
print(render(env, "task.mk", py_scripts=py_scripts, version=version)) print(render(env, "task.mk", py_scripts=py_scripts, version=version))

View file

@ -1,40 +1,29 @@
# ---- [buitlin recipes] ---- # # ---- [buitlin recipes] ---- #
## h, help | show this help ## h, help | show this help
.PHONY: help h .PHONY: help h
help h: help h:
$(call py,help_py) $(call py,help_py)
.PHONY: _help .PHONY: _help
_help: export SHOW_HIDDEN=true _help: export SHOW_HIDDEN=true
_help: help _help: help
ifdef PRINT_VARS ifdef PRINT_VARS
$(foreach v,$(PRINT_VARS),$(eval export $(v))) $(foreach v,$(PRINT_VARS),$(eval export $(v)))
.PHONY: vars v .PHONY: vars v
vars v: vars v:
$(call py,vars_py,$(PRINT_VARS)) $(call py,vars_py,$(PRINT_VARS))
endif endif
### | args: -ws --hidden ### | args: -ws --hidden
### task.mk builtins: | args: -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
.PHONY: .PHONY:
_print-ansi: _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,info_py,$(1)) tprint = $(call py,info_py,$(1))
tprint-sh = $(call pysh,info_py,$(1)) tprint-sh = $(call pysh,info_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: _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
export MAKEFILE_LIST export MAKEFILE_LIST

View file

@ -1,4 +1,4 @@
# ---- CONFIG ---- # # ---- [config] ---- #
HEADER_COLOR ?= b_cyan HEADER_COLOR ?= b_cyan
PARAMS_COLOR ?= b_magenta PARAMS_COLOR ?= b_magenta
ACCENT_COLOR ?= b_yellow ACCENT_COLOR ?= b_yellow
@ -7,11 +7,6 @@ MSG_COLOR ?= faint
DIVIDER_COLOR ?= default DIVIDER_COLOR ?= default
DIVIDER ?= DIVIDER ?=
HELP_SEP ?= HELP_SEP ?=
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=
define USAGE ?= USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make <recipe>
{ansi.$(HEADER_COLOR)}usage{ansi.end}:
make <recipe>
endef

View file

@ -1,21 +1,16 @@
# ---- [python/bash script runner] ---- # # ---- [python/bash script runner] ---- #
###-- modified from https://unix.stackexchange.com/a/223093 -###
# modified from https://unix.stackexchange.com/a/223093
define \n define \n
endef endef
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
escape_printf = $(subst \,\\,$(subst %,%%,$1)) escape_printf = $(subst \,\\,$(subst %,%%,$1))
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
printline = printf -- "<----------------------------------->\n"
ifdef DEBUG ifdef DEBUG
define _debug_runner define _debug_runner
@printf "$(1) Script:\n" @printf "$(1) Script:\n";$(printline);printf "$(call create_string,$(3))\n";$(printline)
@printf -- "<----------------------------------->\n"
@printf "$(call create_string,$(3))\n"
@printf -- "<----------------------------------->\n"
@printf "$(call create_string,$(3))" | $(2) @printf "$(call create_string,$(3))" | $(2)
endef endef
py = $(call _debug_runner,Python,python3,$($(1))) py = $(call _debug_runner,Python,python3,$($(1)))
@ -24,5 +19,4 @@ else
py = @python3 <(printf "$(call create_string,$($(1)))") py = @python3 <(printf "$(call create_string,$($(1)))")
tbash = @bash <(printf "$(call create_string,$($(1)))") tbash = @bash <(printf "$(call create_string,$($(1)))")
endif endif
pysh = python3 <(printf "$(call create_string,$($(1)))") pysh = python3 <(printf "$(call create_string,$($(1)))")

View file

@ -1,13 +1,8 @@
#% include 'header.mk' %# #% include 'header.mk' %#
#% include 'config.mk' %# #% include 'config.mk' %#
#% include 'builtins.mk' %# #% include 'builtins.mk' %#
#% include 'runners.mk' %# #% include 'runners.mk' %#
# ---- [python scripts] ---- # # ---- [python scripts] ---- #
#%- for script in py_scripts %#
#% for script in py_scripts %#
##- script -## ##- script -##
#% endfor %# #%- endfor %#