Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions nbqa/replace_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def mutate(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) -
notebook_info
Information about notebook cells used for processing
"""
notebook_json = json.loads(notebook.read_text())
notebook_json = json.loads(notebook.read_text(encoding="utf-8"))

pycells = _get_pycells(python_file)
for code_cell_number, cell in enumerate(
Expand All @@ -167,7 +167,9 @@ def mutate(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) -
continue
cell["source"] = _get_new_source(code_cell_number, notebook_info, next(pycells))

notebook.write_text(f"{json.dumps(notebook_json, indent=1, ensure_ascii=False)}\n")
notebook.write_text(
f"{json.dumps(notebook_json, indent=1, ensure_ascii=False)}\n", encoding="utf-8"
)


def _print_diff(code_cell_number: int, cell_diff: Iterator[str]) -> None:
Expand Down Expand Up @@ -211,7 +213,7 @@ def diff(python_file: "Path", notebook: "Path", notebook_info: NotebookInfo) ->
notebook_info
Information about notebook cells used for processing
"""
notebook_json = json.loads(notebook.read_text())
notebook_json = json.loads(notebook.read_text(encoding="utf-8"))

pycells = _get_pycells(python_file)

Expand Down
6 changes: 4 additions & 2 deletions nbqa/save_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def main(
NotebookInfo

"""
cells = json.loads(notebook.read_text())["cells"]
cells = json.loads(notebook.read_text(encoding="utf-8"))["cells"]

result = []
cell_mapping = {0: "cell_0:0"}
Expand Down Expand Up @@ -366,7 +366,9 @@ def main(
result.append(re.sub(r";(\s*)$", "\\1", parsed_cell))
line_number += len(parsed_cell.splitlines())

temp_python_file.write_text("".join(result).rstrip(NEWLINE) + NEWLINE)
temp_python_file.write_text(
"".join(result).rstrip(NEWLINE) + NEWLINE, encoding="utf-8"
)

return NotebookInfo(
cell_mapping, trailing_semicolons, temporary_lines, code_cells_to_ignore
Expand Down