-
Notifications
You must be signed in to change notification settings - Fork 133
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
UI
fix code display for temporary modules
#860
Conversation
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.
No UI fixes? It just works on the client side?
"""Create a temporary module from source code""" | ||
module_name = _generate_unique_temp_module_name() | ||
module_name = module_name if module_name else _generate_unique_temp_module_name() |
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.
This probably should be using a hash of the source. E.G. so we don't repeat it a ton of times. Not sttrictly necessary but feels good.
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.
I think it's best to have module_name
as a required argument. However, didn't want to make that change now to limit the scope of this PR
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.
if I change the jupyter magic to use the source version, it does not seem to work properly when I change the cell and update the code -- the source code tracked is still the same from the first iteration.
I believe I will need to edit line 52
|
@skrawcz my understanding is that these changes won't be merged as we're rolling |
While working on other things found this code. It shows the risk of constraints of a particular use case creeping to the main library. @functools.cached_property
def version(self) -> typing.Optional[str]:
# ...
try:
# return hash of first function. It could be that others are Hamilton framework code.
return hash_source_code(self.originating_functions[0], strip=True)
except (
OSError
): # TODO -- ensure we can get the node hash in a databricks environment when using jupyter magic
logger.warning(
f"Failed to hash source code for node {self.name}. Certain environments (such as databricks) do not allow it."
" In this case, version will be None."
)
return None |
Temporary modules, most commonly generated in notebook cells, were throwing errors with the
hamilton_sdk.adapters.HamiltonTracker
. Then, the UI wouldn't properly display the registered code artifacts.The fixes aim to solve the same issues as #855. Given the problems are related to the Hamilton SDK, it seems better to apply changes there than in the Hamilton library where
module_from_source
is used in contexts with different constraints (CLI, LSP, VSCode extension, Jupyter extension, and more)Changes
_hash_module()
doesn't expect for modules to have a__package__
attribute. Modules imported in a Jupyter cell wouldn't have this attribute set, for examplepd
in the following. This changes makes theHamiltonTracker
fully functional._slurp_code()
looks for a file instead of the module object itself. Ifmodule.__file__ is None
we now read the source code from thelinecache
(set byad_hoc_utils.module_from_source()
. Then, thepath
attribute in_slurp_code()
needs to match thepath
attribute inextract_code_artifacts_from_function_grap()
How I tested this
⛔ This makes two SDK test fail. It's probably sufficient to update the hash value, but wanted to double check
Notes
Checklist