refactor: make print-vars parsing based to prevent exporting

This commit is contained in:
Daylin Morgan 2023-01-20 12:19:35 -06:00
parent 920c7c2cc8
commit 365e0e1353
4 changed files with 17 additions and 24 deletions

View file

@ -69,7 +69,7 @@ info: ## demonstrate usage of tprint
task.mk: $(TEMPLATES) generate.py task.mk: $(TEMPLATES) generate.py
./generate.py $(VERSION) > task.mk ./generate.py $(VERSION) > task.mk
-include .task.mk .task.cfg.mk -include .task.cfg.mk .task.mk
.task.mk: $(TEMPLATES) generate.py .task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local .task.mk) $(call msg,re-jinjaing the local .task.mk)
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk) @./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk)

View file

@ -8,10 +8,10 @@ h help: ## show this 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))) TASKMK_VARS=$(subst $(eval ) ,<|>,$(foreach v,$(PRINT_VARS),$(v)=$($(v))))
.PHONY: vars v .PHONY: vars v
vars v: v vars:
$(call py,vars_py,$(PRINT_VARS)) $(call py,vars_py,$(TASKMK_VARS))
endif endif
### |> -ws --hidden ### |> -ws --hidden
### task.mk builtins: |> -d --hidden ### task.mk builtins: |> -d --hidden

View file

@ -10,15 +10,10 @@ from utils import Ansi
# -### # -###
##- '$(utils_py)' -## ##- '$(utils_py)' -##
ansi = Ansi(target="stdout") ansi = Ansi(target="stdout")
vars = "$2".split() ###- $2 is a list of variables set by task.mk delimited with '<|>' -###
length = max((len(v) for v in vars)) task_vars = tuple(v.split('=') for v in "$2".split('<|>'))
length = max((len(v[0]) for v in task_vars))
print(f"{ansi.header}vars{ansi.end}:\n") rows = (f" {ansi.params}{v[0]:<{length}}{ansi.end} = {v[1]}" for v in task_vars)
print('\n'.join((f"{ansi.header}vars{ansi.end}:\n", *rows,'')))
for v in vars:
print(f" {ansi.params}{v:<{length}}{ansi.end} = {os.getenv(v)}")
print()
#% endblock %# #% endblock %#

18
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: v22.9.28-13-gfd96a45dev # version: v22.9.28-16-g920c7c2dev
# #
# task.mk should be included at the bottom of your Makefile with `-include .task.mk` # 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. # See below for the standard configuration options that should be set prior to including this file.
@ -30,10 +30,10 @@ h help: ## show this 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))) TASKMK_VARS=$(subst $(eval ) ,<|>,$(foreach v,$(PRINT_VARS),$(v)=$($(v))))
.PHONY: vars v .PHONY: vars v
vars v: v vars:
$(call py,vars_py,$(PRINT_VARS)) $(call py,vars_py,$(TASKMK_VARS))
endif endif
### |> -ws --hidden ### |> -ws --hidden
### task.mk builtins: |> -d --hidden ### task.mk builtins: |> -d --hidden
@ -286,12 +286,10 @@ define vars_py
import os import os
$(utils_py) $(utils_py)
ansi = Ansi(target="stdout") ansi = Ansi(target="stdout")
vars = "$2".split() task_vars = tuple(v.split('=') for v in "$2".split('<|>'))
length = max((len(v) for v in vars)) length = max((len(v[0]) for v in task_vars))
print(f"{ansi.header}vars{ansi.end}:\n") rows = (f" {ansi.params}{v[0]:<{length}}{ansi.end} = {v[1]}" for v in task_vars)
for v in vars: print('\n'.join((f"{ansi.header}vars{ansi.end}:\n", *rows,'')))
print(f" {ansi.params}{v:<{length}}{ansi.end} = {os.getenv(v)}")
print()
endef endef
define confirm_py define confirm_py
import sys import sys