From 2e4a82a6f822840e638ba274fc0a0e82a214ca5b Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Fri, 16 Sep 2022 12:47:40 -0500 Subject: [PATCH] chore: reduce final output whitespace --- generate.py | 12 ++++++++---- src/builtins.mk | 11 ----------- src/config.mk | 9 ++------- src/runners.mk | 12 +++--------- src/task.mk | 9 ++------- 5 files changed, 15 insertions(+), 38 deletions(-) diff --git a/generate.py b/generate.py index d8877e7..e25488d 100755 --- a/generate.py +++ b/generate.py @@ -5,7 +5,7 @@ from pathlib import Path 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(): @@ -16,6 +16,8 @@ def get_jinja_env(): block_end_string="%#", variable_start_string="##-", variable_end_string="-##", + comment_start_string="###-", + comment_end_string="-###", ) @@ -24,6 +26,10 @@ def render(env, template, **kwargs): return template.render(**kwargs) +def dropnewlines(text): + return "\n".join([line for line in text.splitlines() if line]) + + def main(): if len(sys.argv) == 2: version = sys.argv[1] @@ -31,9 +37,7 @@ def main(): version = "dev" env = get_jinja_env() - - py_scripts = [render(env, f"{name}.py") for name in py_script_names] - + py_scripts = [dropnewlines(render(env, f"{name}.py")) for name in py_script_names] print(render(env, "task.mk", py_scripts=py_scripts, version=version)) diff --git a/src/builtins.mk b/src/builtins.mk index bf140cf..bac6510 100644 --- a/src/builtins.mk +++ b/src/builtins.mk @@ -1,40 +1,29 @@ # ---- [buitlin recipes] ---- # - ## h, help | show this help .PHONY: help h help h: $(call py,help_py) - .PHONY: _help _help: export SHOW_HIDDEN=true _help: help - ifdef PRINT_VARS - $(foreach v,$(PRINT_VARS),$(eval export $(v))) - .PHONY: vars v vars v: $(call py,vars_py,$(PRINT_VARS)) - endif - ### | args: -ws --hidden ### task.mk builtins: | args: -d --hidden ## _print-ansi | show all possible ansi color code combinations .PHONY: _print-ansi: $(call py,print_ansi_py) - # functions to take f-string literals and pass to python print tprint = $(call py,info_py,$(1)) tprint-sh = $(call pysh,info_py,$(1)) - tconfirm = $(call py,confirm_py,$(1)) - ## _update-task.mk | downloads latest development version of task.mk _update-task.mk: $(call tprint,{a.b_cyan}Updating task.mk{a.end}) curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk - export MAKEFILE_LIST diff --git a/src/config.mk b/src/config.mk index 944c098..8667777 100644 --- a/src/config.mk +++ b/src/config.mk @@ -1,4 +1,4 @@ -# ---- CONFIG ---- # +# ---- [config] ---- # HEADER_COLOR ?= b_cyan PARAMS_COLOR ?= b_magenta ACCENT_COLOR ?= b_yellow @@ -7,11 +7,6 @@ MSG_COLOR ?= faint DIVIDER_COLOR ?= default DIVIDER ?= ─ HELP_SEP ?= │ - # python f-string literals EPILOG ?= -define USAGE ?= -{ansi.$(HEADER_COLOR)}usage{ansi.end}: - make - -endef +USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make diff --git a/src/runners.mk b/src/runners.mk index 36262a9..1303137 100644 --- a/src/runners.mk +++ b/src/runners.mk @@ -1,21 +1,16 @@ # ---- [python/bash script runner] ---- # - -# modified from https://unix.stackexchange.com/a/223093 +###-- modified from https://unix.stackexchange.com/a/223093 -### define \n endef - escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_printf = $(subst \,\\,$(subst %,%%,$1)) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) - +printline = printf -- "<----------------------------------->\n" ifdef DEBUG define _debug_runner -@printf "$(1) Script:\n" -@printf -- "<----------------------------------->\n" -@printf "$(call create_string,$(3))\n" -@printf -- "<----------------------------------->\n" +@printf "$(1) Script:\n";$(printline);printf "$(call create_string,$(3))\n";$(printline) @printf "$(call create_string,$(3))" | $(2) endef py = $(call _debug_runner,Python,python3,$($(1))) @@ -24,5 +19,4 @@ else py = @python3 <(printf "$(call create_string,$($(1)))") tbash = @bash <(printf "$(call create_string,$($(1)))") endif - pysh = python3 <(printf "$(call create_string,$($(1)))") diff --git a/src/task.mk b/src/task.mk index e3417dc..663ee51 100644 --- a/src/task.mk +++ b/src/task.mk @@ -1,13 +1,8 @@ #% include 'header.mk' %# - #% include 'config.mk' %# - #% include 'builtins.mk' %# - #% include 'runners.mk' %# - # ---- [python scripts] ---- # - -#% for script in py_scripts %# +#%- for script in py_scripts %# ##- script -## -#% endfor %# \ No newline at end of file +#%- endfor %#