From 097cfd5addbed22ba8ab21d4657da24459b09667 Mon Sep 17 00:00:00 2001 From: Kieran BW <41634689+FredHappyface@users.noreply.github.com> Date: Sat, 29 Jan 2022 13:37:32 +0000 Subject: [PATCH] Fix https://github.com/vemel/handsdown/issues/16 --- handsdown/generator.py | 2 +- handsdown/md_document.py | 2 +- handsdown/utils/__init__.py | 2 +- tests/processors/test_pep257.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/handsdown/generator.py b/handsdown/generator.py index 19735733..15810fd6 100644 --- a/handsdown/generator.py +++ b/handsdown/generator.py @@ -163,7 +163,7 @@ def cleanup_old_docs(self) -> None: if doc_path in preserve_paths: continue - file_content = doc_path.read_text() + file_content = doc_path.read_text(encoding=self._encoding) is_autogenerated = "> Auto-generated documentation" in file_content if not is_autogenerated: continue diff --git a/handsdown/md_document.py b/handsdown/md_document.py index eba6b11e..c1f2258e 100644 --- a/handsdown/md_document.py +++ b/handsdown/md_document.py @@ -34,7 +34,7 @@ class MDDocument: md_doc.write() # output is indented for readability - Path('output.md').read_text() + Path('output.md').read_text(encoding=self._encoding) '''# My doc - [My doc](#my-doc) diff --git a/handsdown/utils/__init__.py b/handsdown/utils/__init__.py index 60402aa4..3c106003 100644 --- a/handsdown/utils/__init__.py +++ b/handsdown/utils/__init__.py @@ -60,7 +60,7 @@ def render_asset(name: str, target_path: Path, format_dict: Dict[str, str], enco format_dict -- Format asset with values from the dict before writing. encoding -- File encoding. """ - content = pkg_resources.files(assets_resource).joinpath(name).read_text() + content = pkg_resources.files(assets_resource).joinpath(name).read_text(encoding=encoding) content = content.format(**format_dict) target_path.write_text(content, encoding=encoding) diff --git a/tests/processors/test_pep257.py b/tests/processors/test_pep257.py index f777a6f1..0f4a2b48 100644 --- a/tests/processors/test_pep257.py +++ b/tests/processors/test_pep257.py @@ -9,7 +9,7 @@ class TestLoader(unittest.TestCase): def test_init(self): pep257_docstring = ( Path(__file__).parent.parent / "static" / "pep257_docstring.txt" - ).read_text() + ).read_text(encoding="utf-8") processor = PEP257DocstringProcessor() sections = processor.build_sections(pep257_docstring) self.assertEqual(sections[""].title, "")