-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build with Local Function Directly #793
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1669,6 +1669,17 @@ def with_config(self, config: Dict[str, Any]) -> "Builder": | |
self.config.update(config) | ||
return self | ||
|
||
def with_local_modules(self) -> "Builder": | ||
"""Adds the local modules to the modules list. | ||
|
||
:return: self | ||
""" | ||
import inspect | ||
|
||
module = inspect.getmodule(inspect.stack()[1][0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See Thierry's comment. I think we can make this more robust. |
||
self.modules.append(module) | ||
return self | ||
|
||
def with_modules(self, *modules: ModuleType) -> "Builder": | ||
"""Adds the specified modules to the modules list. | ||
This can be called multiple times -- later calls will take precedence. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from hamilton.driver import Builder, DefaultGraphExecutor | ||
|
||
|
||
def test_driver_with_local_modules() -> None: | ||
dr = Builder().with_local_modules().build() | ||
assert isinstance(dr.graph_executor, DefaultGraphExecutor) | ||
assert __name__ == list(dr.graph_modules)[0].__name__ | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test probably needs to pull in a function and exercise the driver. e.g. define def a(b:int) -> int:
return b * 2 Then we should execute the driver to get "a". That should work right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add more caveats here.
E.g. If people use this, they could run into problems when using some of the adapters because this code will be imported under the module
__main__
.