-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is still a bit of a WIP, but the API will stay backwards compatible so I'm OK putting it in the stdlib. This efectively cascades through null (customizable sentinel value) results, not running a node if any of its dependencies are null.
- Loading branch information
1 parent
7700507
commit e7bda85
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from hamilton import driver | ||
from hamilton.lifecycle import default | ||
|
||
|
||
class DoNotProceed(Exception): | ||
pass | ||
|
||
|
||
def working_res_1() -> int: | ||
return 1 | ||
|
||
|
||
def working_res_2() -> int: | ||
return 2 | ||
|
||
|
||
def do_not_proceed_1(working_res_1: int, working_res_2: int) -> int: | ||
raise DoNotProceed() | ||
|
||
|
||
def proceed_1(working_res_1: int, working_res_2: int) -> int: | ||
return working_res_1 + working_res_2 | ||
|
||
|
||
def proceed_2(working_res_1: int, working_res_2: int) -> int: | ||
return working_res_1 * working_res_2 | ||
|
||
|
||
def short_circuited_1(working_res_1: int, working_res_2: int, do_not_proceed_1: int) -> int: | ||
return 1 # this should not be reached | ||
|
||
|
||
def proceed_3(working_res_1: int, working_res_2: int) -> int: | ||
return working_res_1 - working_res_2 | ||
|
||
|
||
def do_not_proceed_2(proceed_1: int, proceed_2: int, proceed_3: int) -> int: | ||
raise DoNotProceed() | ||
|
||
|
||
def short_circuited_2(proceed_1: int, proceed_2: int, proceed_3: int, do_not_proceed_2: int) -> int: | ||
return 1 # this should not be reached | ||
|
||
|
||
def short_circuited_3(short_circuited_1: int) -> int: | ||
return 1 # this should not be reached | ||
|
||
|
||
def proceed_4(proceed_1: int, proceed_2: int, proceed_3: int) -> int: | ||
return proceed_1 + proceed_2 + proceed_3 | ||
|
||
|
||
if __name__ == "__main__": | ||
import __main__ | ||
|
||
dr = ( | ||
driver.Builder() | ||
.with_modules(__main__) | ||
.with_adapters( | ||
default.GracefulErrorAdapter(error_to_catch=DoNotProceed, sentinel_value=None) | ||
) | ||
.build() | ||
) | ||
dr.display_all_functions() | ||
vars = dr.list_available_variables() | ||
res = dr.execute(vars) | ||
import pprint | ||
|
||
pprint.pprint(res) |