-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Make import tensorboard as tb possible #778
Conversation
This change introduces a lazy loader that will allow us to provide some of the conviences TensorFlow has. For example: import tensorboard as tb tb.summary.scalar('foo', tensor) Only the hourglass summary module has been made available in this namespace, since that's probably the only thing where we're 100% positive we want this functionality.
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.
Nice loader!
pkg = lambda i: i # helps google sync process | ||
mod = lambda i: lazy.LazyLoader(i[i.rindex('.') + 1:], globals(), i) | ||
|
||
summary = mod(pkg('tensorboard.summary')) |
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.
Why does mod
have to be a lambda? Why not directly call its logic.
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.
DRY. It actually reduces a lot of boilerplate if there's a lot of modules being imported here. Even though for now there's just one.
|
||
def _load(self): | ||
# Import the target module and insert it into the parent's namespace | ||
module = importlib.import_module(self.__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.
Got it. So here, we truly don't load the module until the _load
method is called.
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.
That's correct.
This change introduces a lazy loader that will allow us to provide some of the
conviences TensorFlow has. For example:
Only the hourglass summary module has been made available in this namespace,
since that's probably the only thing where we're 100% positive we want this
functionality.