-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Magic preprocessors for conversion to vanilla Python #1491
Conversation
afa7fcb
to
727431b
Compare
@jbednar @philippjfr Tests are passing so we can now discuss the main change - the refactor of the output magic to allow a new The refactor moves almost all the logic to an I think this is the right thing to do. My major misgiving here is this is not code we like (or are at all proud of!) and I am worried to see this horrible code escape the |
holoviews/ipython/__init__.py
Outdated
OutputMagic.allowed['fig'] = list_formats('fig', backend) | ||
OutputMagic.allowed['holomap'] = list_formats('holomap', backend) | ||
|
||
Store.output_options = OutputOptions() |
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.
Don't quite get this, Store.output_options
is an instance but all the actual configuration is set on the class? Can it all be class based?
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.
Maybe although there is this:
def __init__(self, *args, **kwargs):
self.shell = kwargs.pop('shell', None)
super(OutputOptions, self).__init__(*args, **kwargs)
self.output.__func__.__doc__ = self._generate_docstring()
I can try setting shell
as a class attribute and removing this, though it will lose the generated docstring.
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.
When would a user every look at the OutputOptions
? Seems like internal API to me.
Switching everything to classmethods seems to have worked, though it does mean the param generated docstring on the magic has been lost. |
bb3346e
to
fe57fa2
Compare
Sounds great! Are you using the PNG export option from the latest Bokeh, or some other mechanism for Bokeh? |
Yes, see #1493. You can use it in the notebook too but it's slow so not too useful for interactive use. |
Ok, great! Looks like this support arrived just in time for what we needed it for! |
Note: We need to allow the opts string syntax (i.e using the parser) everywhere. Including where options can be set for saving/outputting data from the renderers. |
c016375
to
c9009f4
Compare
Do we have a way that the user could explicitly enable a warning? If so we could suggest that they do so in the release notes, but otherwise not warn for now. |
Right that is another alternative. This is what I mean about wanting a 'config' system - to set things like this. |
d1d066d
to
98eecbb
Compare
@philippjfr I'm expecting the tests to go green and I think this PR should now be reviewed/merged. It isn't 100% polished or complete but it is probably best to merge sooner rather than later, to help with debugging and to allows us to continue with the docs. Outstanding workHere are the things introduced in this PR that need finishing off/fixing. These can be associated with issues as necessary:
Edit: Related ideas
Although there are a few loose bits and pieces, the bulk of what this PR offers is the In addition, this PR adds a collection of preprocessors that make use of these utils to convert notebooks to simple .py scripts. One of the main things this will enable is launching notebooks as bokeh apps with minimal (if any!) changes. |
holoviews/__init__.py
Outdated
@@ -12,7 +12,7 @@ | |||
commit="$Format:%h$", reponame='holoviews') | |||
|
|||
from .core import archive # noqa (API import) | |||
from .core.dimension import OrderedDict, Dimension # noqa (API import) | |||
from .core.dimension import OrderedDict, Dimension, Dimensioned # noqa (API import) |
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.
How come we need Dimensioned
in the top-level namespace?
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.
Thanks! That is a stray/unnecessary import now - I still need Dimensioned
in util.__init__.py
though...
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.
Fixed in f5f12c2
holoviews/core/dimension.py
Outdated
except: | ||
options = OptsSpec.parse( | ||
'{clsname} {options}'.format(clsname=self.__class__.__name__, | ||
options=options)) |
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.
Seems okay for now but it might be better to list an explicit exception.
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.
Sure. This falls under my bullet points for something to improve. The exception is part of it, but the whole try/except
here isn't a very robust approach. I can specify an exception now but this whole thing needs improving (in another PR imho).
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.
Specified SyntaxError
in a325041
Cell magic version acts as a no-op. | ||
""" | ||
if obj is not None: | ||
return obj |
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.
Did we want to allow this in a later PR? I remember discussing that all it has to do is temporarily set the renderer options.
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.
Could you outline how you can imagine that working? Even if I set the options state temporarily for an expression, it will have no effect unless that expression has some sort of side-effect, namely output. The cell magic resets everything after display and this concept of 'display' doesn't exist outside the notebook.
If you do have ideas about this, I would like to hear them as I would like these utilities to correspond to the magics as closely as possible...
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.
Good point probably doesn't make sense afterall.
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 added a suggestion above regarding a potential show
call that could be injected by an optional preprocessor. Something to think about (maybe it isn't worth it?) and definitely not for this PR.
Looks good, as you laid out in your summary there's some more work to be done here but the PR looks to be in a mergeable state. Happy to merge when you tell me. |
@philippjfr Let's merge once the tests are green. |
Great, merging. |
I've added another item to the list above regarding validation. We need to make sure we address all the things in that list. |
This is very much a work-in-progress prototype. I will update this description if we decide to go ahead with this approach and after I have pushed forced a cleaner commit history.