Skip to content
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

Merged
merged 1 commit into from
Nov 30, 2017
Merged

Conversation

jart
Copy link
Contributor

@jart jart commented Nov 30, 2017

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.

@jart jart requested a review from chihuahua November 30, 2017 02:01
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.
Copy link
Member

@chihuahua chihuahua left a 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'))
Copy link
Member

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.

Copy link
Contributor Author

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__)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct.

@jart jart merged commit 54db26a into tensorflow:master Nov 30, 2017
@jart jart deleted the namespace branch November 30, 2017 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants