From dca41cd8f55c5ef22db05736f6cde93fa36828ae Mon Sep 17 00:00:00 2001 From: David Fokkema Date: Tue, 20 Sep 2022 17:55:28 +0200 Subject: [PATCH 1/3] Released version 1.5.3 --- CHANGELOG.md | 15 +++++++++++++++ pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6ba185..fead82e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 1.5.3 + +### :package: Build System + +* New version of briefcase; crashes on Windows now show error messages + +### :rocket: Features + +* New version of PySide6, only the 'Essentials' package + +### :beetle: Fixes + +* Fix toml decoding error (#56) @davidfokkema + + ## v1.5.2 ### :rocket: Features diff --git a/pyproject.toml b/pyproject.toml index 7848cee..6a940ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.briefcase] project_name = "Tailor" bundle = "com.amsphyslab.tailor" -version = "1.5.2" +version = "1.5.3" url = "https://github.com/davidfokkema/tailor" license = "GNU General Public License v3 (GPLv3)" author = 'David Fokkema' From 7c0074416267207991ac05ec7171bb1e4fbae7c3 Mon Sep 17 00:00:00 2001 From: David Fokkema Date: Fri, 13 Jan 2023 16:03:06 +0100 Subject: [PATCH 2/3] Better handling of TOML encoding / decoding --- src/tailor/config.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tailor/config.py b/src/tailor/config.py index a16dc9d..1fadf5b 100644 --- a/src/tailor/config.py +++ b/src/tailor/config.py @@ -18,8 +18,12 @@ def read_config(): """Read configuration file.""" config_path = get_config_path() if config_path.is_file(): - with open(config_path, "rb") as f: - return tomli.load(f) + try: + with open(config_path, "rb") as f: + return tomli.load(f) + except tomli.TOMLDecodeError: + # error parsing TOML + return {} else: return {} @@ -32,11 +36,13 @@ def write_config(config): """ create_config_dir() config_path = get_config_path() - toml_config = tomli_w.dumps(config) - with open(config_path, "w") as f: + # make sure that TOML conversion works before opening file + tomli_w.dumps(config) + with open(config_path, "wb") as f: # separate TOML generation from writing to file, or an exception # generating TOML will result in an empty file - f.write(toml_config) + # correct TOML unicode handling requires writing bytes + tomli_w.dump(config, f) def get_config_path(): From 173ee7cff8fe00104af3d891a43fc835d561808d Mon Sep 17 00:00:00 2001 From: David Fokkema Date: Tue, 17 Jan 2023 15:21:45 +0100 Subject: [PATCH 3/3] Catch specific UnicodeDecodeError --- src/tailor/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tailor/config.py b/src/tailor/config.py index 1fadf5b..7c45732 100644 --- a/src/tailor/config.py +++ b/src/tailor/config.py @@ -21,7 +21,7 @@ def read_config(): try: with open(config_path, "rb") as f: return tomli.load(f) - except tomli.TOMLDecodeError: + except (tomli.TOMLDecodeError, UnicodeDecodeError): # error parsing TOML return {} else: