-
Notifications
You must be signed in to change notification settings - Fork 568
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
Refactor template system to be easily extensible and voila compatible #1056
Conversation
@t-makaro should probably help review this as he's been more involved on the template side of things recently. |
I need to do some testing this weekend to help make sure everything is in working order, but it looks like all the changes were what we discussed. I'm not sure if we agreed for this change to be in 6.0 release or in 5.x path, if you remember? The test suite is quite angry and will need some attention for the new patterns. |
Can also be a follow-up PR to avoid making this any larger |
Probably needs a separate issue to discuss. We may want this to be a dynamic calculation. |
Need to look at the differences here, but I think there was consensus to have exports be the classic notebook format by default and lab format to be an opt-in pattern, if that's what's being referenced by this question. |
Missed the 6.0 tag on the PR makes sense. Let me know if you need any help with figuring out tests later on. |
I've changed it, such that lab is a template: The old system of using a template file still exists, but now is available as |
I've seem to have hit a bug in traitlets however, like voila, I want this to work:
Such that arguments However, it seems the HTMLExporters does not pick this up, the alias
Maybe I am missing something, if not we should open an issue for traitlets. |
@@ -74,7 +74,7 @@ def test_prompt_number(self): | |||
} | |||
} | |||
) | |||
exporter = HTMLExporter(config=no_prompt_conf, template_file='full') | |||
exporter = HTMLExporter(config=no_prompt_conf, template_name='notebook') |
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 the name of the template should be classic
instead of notebook
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.
For now 'default' is the classic one, it may have been a good idea to have the default html template be a 'nothing' template, without css and all
The classic template would just add some css to the template, have some opinion on the dom structure etc. This way the lab template would not inherit from the classical template.
@@ -1,5 +1,5 @@ | |||
{%- extends 'basic.tpl' -%} |
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.
does default
stand for the default html template?
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.
yes, I think we can make reveal actually a normal template, just like we want with voila, with just some extra resources. So you would do --template reveal
.
e44311d
to
2fc375d
Compare
I don't understand check-manifest, I added:
To MANIFEST.in, but it still gave a warning, so FTM I'm ignoring that directory. |
2fc375d
to
d6946f4
Compare
I will take a deeper look at this (hopefully) tomorrow, but I do have a few things on my mind that I'd like to put out there.
(looking at the code I believe the answer is yes).
Perhaps related to #822? |
yes, convered in test
yes
I'm 50/50 on it, maybe other may express their opinion, I'll leave it like this for the moment, we can always do a rename at the end.
yes
covered in tests
yes, in the same, and other directories. |
After discussion with @SylvainCorlay, the plan is to:
in conf.json, each template can list the mimetype it outputs to (so you can still have multiple mimetypes/formats in 1 template directory, e.g. latex+html). This makes it easier to list only templates of a specific mimetype. |
the suggested change are in, I think this is ready for review. |
Why not rename |
In number #1076, I made it possible to use
where the first 2 are equivalent (and the extension can in theory be dropped). My understand as that after this PR I would do:
This is where my concern is. It may seem arbitrary to a user to have to use
will it work? If not, I would refactor these latex templates a fair bit to make these Though I would like if we could detect if a user passed in a |
Ok rebasing 6.x with master added some conflict files unfortunately. |
cc487ef
to
621eb9d
Compare
squash and rebased. |
4b2009f
to
6df9090
Compare
@maartenbreddels If you wish you can coauthor the rebase commit by adding https://help.github.com/en/articles/creating-a-commit-with-multiple-authors I'm good to merge either way, I'll check on this tomorrow and merge it then either way. Thanks a ton for getting this prepped. |
6df9090
to
d41a2f8
Compare
I added two last commits that were needed to make integration with voila smoother, which will make a review easier. I'll squash it all before committing. @SylvainCorlay do you want to take another look? The more visible change is in null.tpl/null.j2. |
I can do the squash on merge if you want, or we can leave a few minor commits hanging around. |
Co-authored-by: Sylvain Corlay <sylvain.corlay@gmail.com>
d41a2f8
to
f4c7dae
Compare
I'm gonna merge this -- we can make changes later if need be :D |
✨✨✨✨✨💪💪💪💪🤩🤩🤩🤩🤩 |
Awesome!
And the voila templates contains almost no code, except for the spinner in the lab template: |
Fixes jupyter#1430 Many users are reporting that nbconvert 6.x has permission errors when queried or converting files. These seem to arise when nbconvert is installed as root, then used as a user. We hypothesize that the code removed in this commit, which attempts to create template directories throughout the jupyter path hierarchy, succeeds in creating template directories when running as root. Note that it creates the template directories with permission 700. Those permissions as root mean that regular users won’t be able to read these directories, and those are the sort of permission errors we are seeing reported. This directory creation was originally introduced in jupyter#1028, where I think it was limited to a single user configuration directory (based on the PR discussion). In jupyter#1056, this code appears to have been copied over and applied to the entire Jupyter directory hierarchy.
* Do not attempt to create additional template paths. Fixes #1430 Many users are reporting that nbconvert 6.x has permission errors when queried or converting files. These seem to arise when nbconvert is installed as root, then used as a user. We hypothesize that the code removed in this commit, which attempts to create template directories throughout the jupyter path hierarchy, succeeds in creating template directories when running as root. Note that it creates the template directories with permission 700. Those permissions as root mean that regular users won’t be able to read these directories, and those are the sort of permission errors we are seeing reported. This directory creation was originally introduced in #1028, where I think it was limited to a single user configuration directory (based on the PR discussion). In #1056, this code appears to have been copied over and applied to the entire Jupyter directory hierarchy. * Filter additional template paths to existing paths to be consistent.
Is this issue related, at all, to why there is no "to gridstack"-like entry in the export menu item? I've been able to get the Voila-DejaVu-like (static page) behavior using the following config settings, in a script. c = Config()
c.TemplateExporter.exclude_input = True
c.TemplateExporter.exclude_output_prompt = True
c.TemplateExporter.exclude_input_prompt = True
c.ExecutePreprocessor.enabled=True
c.HTMLExporter.template_name = 'gridstack' Barring any potentially-related fundamental issues, possibly like this, I would think adding a Gridstack render export could be pretty straight-forward(?). I apologize if this is too unrelated to this and should be in it's own issue. |
cc @SylvainCorlay @martinRenou @jtpio
This is the followup of what was discussed in #1028, planned for voila in voila-dashboards/voila#208.
The basic idea is that templates are a directory in either:
$prefix/nbconvert/templates/<template_name> where $prefix is determined by jupyter_paths.
On OSX it would be:
With this PR, #1005 would simply be a directory share/jupyter/nbconvert/templates/lab and now the old full.tpl is a template called 'notebook'.
In combination with voila-dashboards/voila#208 we can make all nbconvert template compatible by only overriding the
{% block ipywidgets %}
, and instead of inlining CSS, we can request it from the server.Loose ends
TemplateExporter.template_file
changed a bit, it's cannot be an absolute path anymore, it now refers to the filename in the search path, resolved by jinja2 only. (also the reason unit tests fail).