holy hell

This commit is contained in:
2019-09-16 04:31:18 -04:00
parent dbfdd2127e
commit 27ced9dbfe
4 changed files with 72 additions and 25 deletions
+31 -14
View File
@@ -155,7 +155,7 @@ class TaskScript(BaseAction):
# sources = (stdlib, self.bashfile.root_source, self.source)
if sources is None:
sources = (stdlib, self.bashfile.root_source)
sources = (stdlib, self.bashfile.funcs_source, self.bashfile.root_source)
with open(tf, "w") as f:
if insert_source:
@@ -175,14 +175,21 @@ class TaskScript(BaseAction):
init_tf = self.prepare_init()
if self.bashfile._is_shebang_line(self.source_lines[0]):
script_tf = self.prepare_init(sources=[self.source])
if self.source_lines[0] == "#!/usr/bin/env bash":
with open(script_tf, "r") as f:
lines = f.readlines()
lines.insert(1, f"source {init_tf}")
with open(script_tf, "w") as f:
f.write("\n".join(lines))
else:
script_tf = self.prepare_init(sources=[self.source], insert_source=init_tf)
args = " ".join([shlex_quote(a) for a in self.bashfile.args])
script = (
f"source {shlex_quote(init_tf)}; {shlex_quote(script_tf)} | bake-indent"
)
cmd = f"bash -c {shlex_quote(script)} {args}"
script = f"source {shlex_quote(init_tf)}; {shlex_quote(script_tf)} {args} | bake:indent"
cmd = f"bash -c {shlex_quote(script)}"
if debug:
click.echo(f" $ {cmd}", err=True)
c = os.system(cmd)
@@ -246,6 +253,9 @@ class Bakefile:
if not os.path.exists(path):
raise NoBakefileFound()
os.environ["BAKEFILE_PATH"] = self.path
os.environ["BAKE_SKIP_DONE"] = "1"
self.chunks
def __repr__(self):
@@ -335,18 +345,13 @@ class Bakefile:
@staticmethod
def _is_declaration_line(line):
if ":" in line:
return not (
line.startswith(INDENT_STYLES[0]) or line.startswith(INDENT_STYLES[1])
)
line = line.replace("\t", " " * 4)
return bool(len(line[:4].strip()))
@staticmethod
def _is_shebang_line(line):
return line.startswith("#!")
def _is_not_task_line(line):
if self._is_shebang_line(line):
return True
@staticmethod
def _is_comment_line(line):
return line.startswith("#")
@@ -375,11 +380,23 @@ class Bakefile:
else:
if not task_active:
source_lines.append(line)
else:
task_active = False
# else:
# task_active = False
return source_lines
@property
def root_source(self):
return "\n".join(self.root_source_lines)
@property
def funcs_source(self):
source = []
for task in self.tasks:
task = self[task]
source.append(
f"task:{task.name}()" + " { " + f"bake --silent {task.name} $@;" + "}"
)
return "\n".join(source)
+26 -4
View File
@@ -11,7 +11,15 @@ import pygments.lexers
import pygments.formatters
SAFE_ENVIRONS = ["HOME", "PATH", "LANG", "LOCALE", "TERM", "VIRTUAL_ENV"]
SAFE_ENVIRONS = [
"HOME",
"PATH",
"LANG",
"LOCALE",
"TERM",
"VIRTUAL_ENV",
"BAKEFILE_PATH",
]
def indent(line):
@@ -54,6 +62,9 @@ def echo_json(obj):
is_flag=True,
help="Lists available tasks (and their dependencies).",
)
@click.option(
"--skip-done", default=False, is_flag=True, hidden=True, envvar="BAKE_SKIP_DONE"
)
@click.option("--debug", default=False, is_flag=True, hidden=True)
@click.option("--shellcheck", default=False, is_flag=True, hidden=False)
@click.option(
@@ -64,6 +75,7 @@ def echo_json(obj):
hidden=False,
help="Whitelist an environment variable for use.",
)
@click.option("--no-deps", default=False, is_flag=True, hidden=False)
@click.option("--yes", is_flag=True, help="Set mediumsecurity prompts to yes.")
@click.option(
"--continue",
@@ -116,6 +128,8 @@ def entrypoint(
insecure,
allow,
_json,
skip_done,
no_deps,
yes,
):
"""bake — the strangely familiar taskrunner."""
@@ -176,6 +190,10 @@ def entrypoint(
for _task in bakefile.tasks:
depends_on = bakefile[_task].depends_on(recursive=True)
if no_deps:
depends_on = ()
if depends_on:
deps = []
for dep in depends_on:
@@ -256,18 +274,22 @@ def entrypoint(
+ click.style(":", fg="white"),
err=True,
)
return_code = task.execute(yes=yes, silent=silent)
return_code = task.execute(yes=yes, debug=debug, silent=silent)
if not _continue:
if not return_code == 0:
click.echo(click.style(f"Task {task} failed!", fg="red"), err=True)
sys.exit(return_code)
tasks = task.depends_on(recursive=True) + [task]
if not no_deps:
tasks = task.depends_on(recursive=True) + [task]
else:
tasks = [task]
for task in tasks:
execute_task(task, silent=silent)
if not silent:
if not silent and not skip_done:
click.echo(
click.style(" + ", fg="white")
+ click.style("Done", fg="green")
+15 -7
View File
@@ -1,21 +1,21 @@
#!/usr/bin/env bash
if [ "$(uname)" == Darwin ]; then
bake-sed() { command sed -l "$@"; }
bake:sed() { command sed -l "$@"; }
else
bake-sed() { command sed -u "$@"; }
bake:sed() { command sed -u "$@"; }
fi
# Syntax sugar.
bake-indent() {
bake-sed "s/^/ /"
bake:indent() {
bake:sed "s/^/ /"
}
# ---------------------
# From: https://github.com/heroku/buildpack-stdlib/blob/master/stdlib.sh
# Buildpack Steps.
bake-step() {
bake:step() {
if [[ "$*" == "-" ]]; then
read -r output
else
@@ -26,7 +26,7 @@ bake-step() {
}
# Buildpack Error.
bake-error() {
bake:error() {
if [[ "$*" == "-" ]]; then
read -r output
else
@@ -36,7 +36,7 @@ bake-error() {
}
# Buildpack Warning.
bake-warn() {
bake:warn() {
if [[ "$*" == "-" ]]; then
read -r output
else
@@ -44,3 +44,11 @@ bake-warn() {
fi
echo -e "\\e[1m\\e[33m=!= $output\\e[0m"
}
# bake:eng_join() {
# for word in ${@}; do
# echo $word
# end
# }
View File