Skip to content

Commit

Permalink
ditch the slightly weird return value from command=callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Oct 31, 2024
1 parent 7a114b2 commit 30290a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/dynamic_dependencies/filelist/build.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def generate_result(task):
"""Read build/filelist.txt and create a new task to cat those files together into result.txt"""
file = open(task.config.in_filelist[0], "r", encoding="utf-8")
from_filelist = [f.strip() for f in file.readlines()]
task = hancho(
new_task = hancho(
desc = "Concatenate {in_files} into {out_files}",
command = "cat {in_files} > {out_files}",
in_files = from_filelist,
out_files = "result.txt",
other_files = [random_touch, filelist_txt],
)
return task
task._out_files.append(new_task)

result_txt = hancho(
desc = "Read {in_filelist} and use its contents to generate another task",
Expand Down
16 changes: 2 additions & 14 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ def log_exception():
#---------------------------------------------------------------------------------------------------
# Path manipulation

def unwrap_path(variant) -> str | list[str]:
if isinstance(variant, (Task, Expander)):
variant = variant._out_files
return variant

def abs_path(raw_path, strict=False) -> str | list[str]:
raw_path = unwrap_path(raw_path)

if isinstance(raw_path, list):
return [abs_path(p, strict) for p in raw_path]
Expand All @@ -105,8 +99,6 @@ def abs_path(raw_path, strict=False) -> str | list[str]:
return result

def rel_path(path1, path2):
path1 = unwrap_path(path1)
path2 = unwrap_path(path2)

if isinstance(path1, list):
return [rel_path(p, path2) for p in path1]
Expand All @@ -123,8 +115,6 @@ def join_path(path1, path2, *args):
return flatten(result) if isinstance(result, list) else result

def join_path2(path1, path2, *args):
path1 = unwrap_path(path1)
path2 = unwrap_path(path2)

if len(args) > 0:
return [join_path(path1, p) for p in join_path(path2, *args)]
Expand Down Expand Up @@ -955,11 +945,9 @@ async def run_command(self, command):
# Custom commands just get called and then early-out'ed.
if callable(command):
app.pushdir(self.config.task_dir)
result = command(self)
command(self)
app.popdir()
self._returncode = 0
if result is not None:
self._out_files.append(result)
return

# Non-string non-callable commands are not valid
Expand Down Expand Up @@ -995,7 +983,7 @@ async def run_command(self, command):
result.write("\n")
result.close()

if verbose or not command_pass:
if debug or verbose or not command_pass:
if not command_pass:
log(f"{color(128,255,196)}[{self._task_index}/{app.tasks_started}]{color(255,128,128)} Task failed {color()}- '{self.config.desc}'")
log(f"Task dir: {self.config.task_dir}")
Expand Down

0 comments on commit 30290a6

Please sign in to comment.