Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 6, 2024
1 parent f72aac3 commit b25bc2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions build.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
config.verbose = True
config.jobs = 1

Rule()([], [], desc = "Run all tests", command = "cd tests && rm -rf build && ./test.py 2> /dev/null")
Rule()([], [], desc = "Build all tutorials", command = "cd tutorial && rm -rf build && hancho --quiet")
Rule()([], [], desc = "Build hello_world", command = "cd examples/hello_world && rm -rf build && hancho --quiet")
Expand Down
16 changes: 4 additions & 12 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,14 @@ def touch(name):
if isinstance(name, Rule):
for f in name.files_out:
touch(f)
if os.path.exists(name):
return name.files_out
elif os.path.exists(name):
os.utime(name, None)
return name
else:
with open(name, "w") as file:
file.write("")


async def async_touch(task):
"""Convenience helper method"""
for name in task.files_out:
if os.path.exists(name):
os.utime(name, None)
else:
with open(name, "w") as file:
file.write("")
return task.files_out
return name

################################################################################

Expand Down
2 changes: 1 addition & 1 deletion tests/rules.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ compile_cpp = Rule(
)

touch_outputs = Rule(
command = async_touch
command = touch
)
12 changes: 7 additions & 5 deletions tutorial/tut4.hancho
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# tutorial/tut4.hancho - Async/await and custom commands
import asyncio
import os

config.build_dir = "build/tut4"

# You can use promises that return arrays of filenames in place of actual
# filenames in rules.
# Functions (synchronous or asynchronous) that return filenames or arrays of
# filenames can be used in place of actual filenames in rules.

async def do_slow_thing():
print("Doing slow thing")
await asyncio.sleep(0.1)
Expand All @@ -19,8 +19,10 @@ echo = Rule(
echo(do_slow_thing(), [])

# You can also use them in the command field.
async def custom_command(task):
await async_touch(task)
def custom_command(task):
for f in task.files_out:
with open(f, "a") as file:
file.write("asdf\n")
return task.files_out

custom_rule = Rule(
Expand Down

0 comments on commit b25bc2d

Please sign in to comment.