diff --git a/doc/source/release/changelog/changelog.rst b/doc/source/release/changelog/changelog.rst index fb35edd..6542903 100644 --- a/doc/source/release/changelog/changelog.rst +++ b/doc/source/release/changelog/changelog.rst @@ -1,3 +1,12 @@ +0.3.3 (2024-04-25) +================== + +Bug fixes +--------- + +- A bug has been fixed where UTF8 characters in Python files would give fatal errors. + + 0.3.2 (2024-04-25) ================== diff --git a/src/suiteas/read/config.py b/src/suiteas/read/config.py index 1d50033..dc3881a 100644 --- a/src/suiteas/read/config.py +++ b/src/suiteas/read/config.py @@ -276,7 +276,7 @@ def get_toml_config(toml_path: Path) -> TOMLProjConfig: msg = f"Could not find TOML configuration file at {toml_path}" raise FileNotFoundError(msg) - with toml_path.open(mode="r") as file: + with toml_path.open(mode="r", encoding="utf8") as file: pyproject_contents = file.read() if not pyproject_contents: diff --git a/src/suiteas/read/file.py b/src/suiteas/read/file.py index ea39c5c..3753ca1 100644 --- a/src/suiteas/read/file.py +++ b/src/suiteas/read/file.py @@ -88,7 +88,7 @@ def get_file(path: Path, *, module_name: str) -> File: msg = f"Could not find {path}" raise FileNotFoundError(msg) - with path.open(mode="r") as _f: + with path.open(mode="r", encoding="utf8") as _f: source = _f.read() try: tree = ast.parse(source) diff --git a/tests/assets/files/unicode_backquotes.py b/tests/assets/files/unicode_backquotes.py new file mode 100644 index 0000000..e63569c --- /dev/null +++ b/tests/assets/files/unicode_backquotes.py @@ -0,0 +1 @@ +"""”""" diff --git a/tests/unit/suiteas/read/test_file.py b/tests/unit/suiteas/read/test_file.py index 8699f7b..bc4b4e7 100644 --- a/tests/unit/suiteas/read/test_file.py +++ b/tests/unit/suiteas/read/test_file.py @@ -181,7 +181,7 @@ def test_multi(self, files_parent_dir: Path) -> None: def test_random_file(self, tmp_path: Path, seed: int) -> None: """Generate a random file and check we can at least run the tool.""" file_path = tmp_path / "random_file.py" - with file_path.open(mode="w") as _f: + with file_path.open(mode="w", encoding="utf8") as _f: _f.write(generate(seed=seed)) try: file = get_file(file_path, module_name="random_file") @@ -189,6 +189,10 @@ def test_random_file(self, tmp_path: Path, seed: int) -> None: return assert type(file) == File + def test_unicode_backquotes(self, files_parent_dir: Path) -> None: + file_path = files_parent_dir / "unicode_backquotes.py" + + get_file(file_path, module_name="fakey.mcfake.unicode_backquotes") class TestFlowCtrlTree: def test_correspondence(self) -> None: