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

Add eol --newline option for text content in nbconvert.writers.files #2145

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
  • Loading branch information
thisiswhereitype committed Feb 5, 2025
commit a0d2c708d28c45bb0a663b7e4ab73025eca6ea1f
37 changes: 9 additions & 28 deletions nbconvert/nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ def _writer_class_changed(self, change):
help="""PostProcessor class used to write the
results of the conversion"""
).tag(config=True)
postprocessor_aliases = {
"serve": "nbconvert.postprocessors.serve.ServePostProcessor"
}
postprocessor_aliases = {"serve": "nbconvert.postprocessors.serve.ServePostProcessor"}
postprocessor_factory = Type(None, allow_none=True)

@observe("postprocessor_class")
Expand Down Expand Up @@ -417,9 +415,7 @@ def init_notebooks(self):
# Use glob to find matching filenames. Allow the user to convert
# notebooks without having to type the extension.
globbed_files = glob.glob(pattern, recursive=self.recursive_glob)
globbed_files.extend(
glob.glob(pattern + ".ipynb", recursive=self.recursive_glob)
)
globbed_files.extend(glob.glob(pattern + ".ipynb", recursive=self.recursive_glob))
if not globbed_files:
self.log.warning("pattern %r matched no files", pattern)

Expand All @@ -433,10 +429,7 @@ def init_writer(self):
self._writer_class_changed({"new": self.writer_class})
if self.writer_factory:
self.writer = self.writer_factory(parent=self)
if (
hasattr(self.writer, "build_directory")
and self.writer.build_directory != ""
):
if hasattr(self.writer, "build_directory") and self.writer.build_directory != "":
self.use_output_suffix = False

def init_postprocessor(self):
Expand Down Expand Up @@ -513,17 +506,13 @@ def export_single_notebook(self, notebook_filename, resources, input_buffer=None
"""
try:
if input_buffer is not None:
output, resources = self.exporter.from_file(
input_buffer, resources=resources
)
output, resources = self.exporter.from_file(input_buffer, resources=resources)
else:
output, resources = self.exporter.from_filename(
notebook_filename, resources=resources
)
except ConversionException:
self.log.error(
"Error while converting '%s'", notebook_filename, exc_info=True
) # noqa: G201
self.log.error("Error while converting '%s'", notebook_filename, exc_info=True) # noqa: G201
self.exit(1)

return output, resources
Expand Down Expand Up @@ -592,9 +581,7 @@ def convert_single_notebook(self, notebook_filename, input_buffer=None):
argument.
"""
if input_buffer is None:
self.log.info(
"Converting notebook %s to %s", notebook_filename, self.export_format
)
self.log.info("Converting notebook %s to %s", notebook_filename, self.export_format)
else:
self.log.info("Converting notebook into %s", self.export_format)

Expand Down Expand Up @@ -665,9 +652,7 @@ def document_config_options(self):
preprocessor, postprocessor, and other sections.
"""
categories = {
category: [
c for c in self._classes_inc_parents() if category in c.__name__.lower()
]
category: [c for c in self._classes_inc_parents() if category in c.__name__.lower()]
for category in [
"app",
"exporter",
Expand All @@ -677,9 +662,7 @@ def document_config_options(self):
]
}
accounted_for = {c for category in categories.values() for c in category}
categories["other"] = [
c for c in self._classes_inc_parents() if c not in accounted_for
]
categories["other"] = [c for c in self._classes_inc_parents() if c not in accounted_for]

header = dedent(
"""
Expand All @@ -693,9 +676,7 @@ def document_config_options(self):
sections += header.format(section=category.title())
if category in ["exporter", "preprocessor", "writer"]:
sections += f".. image:: _static/{category}_inheritance.png\n\n"
sections += "\n".join(
c.class_config_rst_doc() for c in categories[category]
)
sections += "\n".join(c.class_config_rst_doc() for c in categories[category])

return sections.replace(" : ", r" \: ")

Expand Down