From 1ca47bcf400847d01556ac82652862f2114f7192 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Thu, 16 Sep 2021 20:16:46 -0700 Subject: [PATCH 1/2] Do not attempt to create additional template paths. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- nbconvert/exporters/templateexporter.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 8b619224e..1ba7a6fb0 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -18,7 +18,6 @@ from traitlets.config import Config from traitlets.utils.importstring import import_item from jupyter_core.paths import jupyter_path -from jupyter_core.utils import ensure_dir_exists from jinja2 import ( TemplateNotFound, Environment, ChoiceLoader, FileSystemLoader, BaseLoader, DictLoader @@ -547,14 +546,7 @@ def _template_paths(self, prune=True, root_dirs=None): compatibility_dir = os.path.join(root_dir, 'nbconvert', 'templates', 'compatibility') paths.append(compatibility_dir) - additional_paths = self.template_data_paths - for path in additional_paths: - try: - ensure_dir_exists(path, mode=0o700) - except OSError: - pass - - return paths + self.extra_template_paths + additional_paths + return paths + self.extra_template_paths + self.template_data_paths @classmethod def get_compatibility_base_template_conf(cls, name): From c3c85330a46935bf8252b0b9f1f51258097b50a0 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 17 Sep 2021 00:50:18 -0700 Subject: [PATCH 2/2] Filter additional template paths to existing paths to be consistent. --- nbconvert/exporters/templateexporter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 1ba7a6fb0..01bffce5b 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -546,7 +546,13 @@ def _template_paths(self, prune=True, root_dirs=None): compatibility_dir = os.path.join(root_dir, 'nbconvert', 'templates', 'compatibility') paths.append(compatibility_dir) - return paths + self.extra_template_paths + self.template_data_paths + additional_paths = [] + for path in self.template_data_paths: + if not prune or os.path.exists(path): + additional_paths.append(path) + + + return paths + self.extra_template_paths + additional_paths @classmethod def get_compatibility_base_template_conf(cls, name):