Skip to content

Commit

Permalink
Run black and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Aug 9, 2022
1 parent 418d545 commit 0abf290
Show file tree
Hide file tree
Showing 3 changed files with 675 additions and 258 deletions.
20 changes: 12 additions & 8 deletions nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ class HTMLExporter(TemplateExporter):

export_from_notebook = "HTML"

anchor_link_text = Unicode("¶", help="The text used as the text for anchor links.").tag(
config=True
)
anchor_link_text = Unicode(
"¶", help="The text used as the text for anchor links."
).tag(config=True)

exclude_anchor_links = Bool(False, help="If anchor links should be included or not.").tag(
config=True
)
exclude_anchor_links = Bool(
False, help="If anchor links should be included or not."
).tag(config=True)

require_js_url = Unicode(
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js",
Expand Down Expand Up @@ -131,7 +131,9 @@ class HTMLExporter(TemplateExporter):
"https://unpkg.com/", help="URL base for Jupyter widgets"
).tag(config=True)

widget_renderer_url = Unicode("", help="Full URL for Jupyter widgets").tag(config=True)
widget_renderer_url = Unicode("", help="Full URL for Jupyter widgets").tag(
config=True
)

html_manager_semver_range = Unicode(
"*", help="Semver range for Jupyter widgets HTML manager"
Expand Down Expand Up @@ -226,7 +228,9 @@ def from_notebook_node(self, nb, resources=None, **kw):
def _init_resources(self, resources):
def resources_include_css(name):
env = self.environment
code = """<style type="text/css">\n%s</style>""" % (env.loader.get_source(env, name)[0])
code = """<style type="text/css">\n%s</style>""" % (
env.loader.get_source(env, name)[0]
)
return markupsafe.Markup(code)

def resources_include_lab_theme(name):
Expand Down
65 changes: 46 additions & 19 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ class TemplateExporter(Exporter):
"""

# finish the docstring
__doc__ = __doc__.format(filters="- " + "\n - ".join(sorted(default_filters.keys())))
__doc__ = __doc__.format(
filters="- " + "\n - ".join(sorted(default_filters.keys()))
)

_template_cached = None

Expand Down Expand Up @@ -186,9 +188,9 @@ def default_config(self):
config=True, affects_template=True
)

template_file = Unicode(None, allow_none=True, help="Name of the template file to use").tag(
config=True, affects_template=True
)
template_file = Unicode(
None, allow_none=True, help="Name of the template file to use"
).tag(config=True, affects_template=True)

raw_template = Unicode("", help="raw template string").tag(affects_environment=True)

Expand Down Expand Up @@ -257,7 +259,8 @@ def _default_extra_template_basedirs(self):
template_extension = Unicode().tag(config=True, affects_environment=True)

template_data_paths = List(
jupyter_path("nbconvert", "templates"), help="Path where templates can be installed too."
jupyter_path("nbconvert", "templates"),
help="Path where templates can be installed too.",
).tag(affects_environment=True)

# Extension that the template files use.
Expand All @@ -271,11 +274,13 @@ def _template_extension_default(self):
return self.file_extension

exclude_input = Bool(
False, help="This allows you to exclude code cell inputs from all templates if set to True."
False,
help="This allows you to exclude code cell inputs from all templates if set to True.",
).tag(config=True)

exclude_input_prompt = Bool(
False, help="This allows you to exclude input prompts from all templates if set to True."
False,
help="This allows you to exclude input prompts from all templates if set to True.",
).tag(config=True)

exclude_output = Bool(
Expand All @@ -284,7 +289,8 @@ def _template_extension_default(self):
).tag(config=True)

exclude_output_prompt = Bool(
False, help="This allows you to exclude output prompts from all templates if set to True."
False,
help="This allows you to exclude output prompts from all templates if set to True.",
).tag(config=True)

exclude_output_stdin = Bool(
Expand All @@ -293,19 +299,23 @@ def _template_extension_default(self):
).tag(config=True)

exclude_code_cell = Bool(
False, help="This allows you to exclude code cells from all templates if set to True."
False,
help="This allows you to exclude code cells from all templates if set to True.",
).tag(config=True)

exclude_markdown = Bool(
False, help="This allows you to exclude markdown cells from all templates if set to True."
False,
help="This allows you to exclude markdown cells from all templates if set to True.",
).tag(config=True)

exclude_raw = Bool(
False, help="This allows you to exclude raw cells from all templates if set to True."
False,
help="This allows you to exclude raw cells from all templates if set to True.",
).tag(config=True)

exclude_unknown = Bool(
False, help="This allows you to exclude unknown cells from all templates if set to True."
False,
help="This allows you to exclude unknown cells from all templates if set to True.",
).tag(config=True)

extra_loaders = List(
Expand Down Expand Up @@ -344,9 +354,12 @@ def __init__(self, config=None, **kw):
super().__init__(config=config, **kw)

self.observe(
self._invalidate_environment_cache, list(self.traits(affects_environment=True))
self._invalidate_environment_cache,
list(self.traits(affects_environment=True)),
)
self.observe(
self._invalidate_template_cache, list(self.traits(affects_template=True))
)
self.observe(self._invalidate_template_cache, list(self.traits(affects_template=True)))

def _load_template(self):
"""Load the Jinja template object from the template file
Expand Down Expand Up @@ -557,7 +570,9 @@ def _template_paths(self, prune=True, root_dirs=None):
base_dir = os.path.join(root_dir, "nbconvert", "templates")
paths.append(base_dir)

compatibility_dir = os.path.join(root_dir, "nbconvert", "templates", "compatibility")
compatibility_dir = os.path.join(
root_dir, "nbconvert", "templates", "compatibility"
)
paths.append(compatibility_dir)

additional_paths = []
Expand Down Expand Up @@ -594,7 +609,9 @@ def get_template_names(self):
with open(conf_file) as f:
conf = recursive_update(json.load(f), conf)
for root_dir in root_dirs:
template_dir = os.path.join(root_dir, "nbconvert", "templates", base_template)
template_dir = os.path.join(
root_dir, "nbconvert", "templates", base_template
)
if os.path.exists(template_dir):
found_at_least_one = True
conf_file = os.path.join(template_dir, "conf.json")
Expand All @@ -606,7 +623,11 @@ def get_template_names(self):
for root_dir in root_dirs:
compatibility_file = base_template + ".tpl"
compatibility_path = os.path.join(
root_dir, "nbconvert", "templates", "compatibility", compatibility_file
root_dir,
"nbconvert",
"templates",
"compatibility",
compatibility_file,
)
if os.path.exists(compatibility_path):
found_at_least_one = True
Expand All @@ -627,7 +648,11 @@ def get_template_names(self):
merged_conf = recursive_update(dict(conf), merged_conf)
base_template = conf.get("base_template")
conf = merged_conf
mimetypes = [mimetype for mimetype, enabled in conf.get("mimetypes", {}).items() if enabled]
mimetypes = [
mimetype
for mimetype, enabled in conf.get("mimetypes", {}).items()
if enabled
]
if self.output_mimetype and self.output_mimetype not in mimetypes and mimetypes:
supported_mimetypes = "\n\t".join(mimetypes)
raise ValueError(
Expand All @@ -641,7 +666,9 @@ def get_prefix_root_dirs(self):
# relative to the package directory (first entry, meaning with highest precedence)
root_dirs = []
if DEV_MODE:
root_dirs.append(os.path.abspath(os.path.join(ROOT, "..", "..", "share", "jupyter")))
root_dirs.append(
os.path.abspath(os.path.join(ROOT, "..", "..", "share", "jupyter"))
)
root_dirs.extend(jupyter_path())
return root_dirs

Expand Down
Loading

0 comments on commit 0abf290

Please sign in to comment.