Skip to content

Commit

Permalink
Use tomli instead of toml
Browse files Browse the repository at this point in the history
Fixes a nasty encoding bug, see uiri/toml#404.
  • Loading branch information
davidfokkema committed Sep 20, 2022
1 parent 6e7d0cf commit ece266a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
10 changes: 4 additions & 6 deletions pruner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from glob import glob
from pathlib import Path

import toml
import tomli


def prune(base_dir, exclude, include):
Expand Down Expand Up @@ -33,12 +33,10 @@ def prune(base_dir, exclude, include):


def main():
with open("pyproject.toml") as f:
config = toml.load(f)
with open("pyproject.toml", "rb") as f:
config = tomli.load(f)
pruner_config = config["tool"]["pruner"][sys.platform]
prune(
pruner_config["base_dir"], pruner_config["exclude"], pruner_config["include"]
)
prune(pruner_config["base_dir"], pruner_config["exclude"], pruner_config["include"])


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ sources = ['src/tailor']
requires = [
'std-nslog',
'appdirs>=1.4.4,<2.0.0',
'toml>=0.10.2,<1.0.0',
'tomli>=2.0.1,<3.0.0',
'tomli_w>=1.0.0,<2.0.0',
'numpy>=1.22.1,<2.0.0',
'pandas>=1.4.0,<2.0.0',
'lmfit>=1.0.3,<2.0.0',
Expand Down
12 changes: 6 additions & 6 deletions src/tailor/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pathlib
import sys
from importlib import metadata as importlib_metadata

import appdirs
import toml
import pathlib

import tomli
import tomli_w

app_module = sys.modules["__main__"].__package__
metadata = importlib_metadata.metadata(app_module)
Expand All @@ -18,8 +18,8 @@ def read_config():
"""Read configuration file."""
config_path = get_config_path()
if config_path.is_file():
with open(config_path) as f:
return toml.load(f)
with open(config_path, "rb") as f:
return tomli.load(f)
else:
return {}

Expand All @@ -32,7 +32,7 @@ def write_config(config):
"""
create_config_dir()
config_path = get_config_path()
toml_config = toml.dumps(config)
toml_config = tomli_w.dumps(config)
with open(config_path, "w") as f:
# separate TOML generation from writing to file, or an exception
# generating TOML will result in an empty file
Expand Down

0 comments on commit ece266a

Please sign in to comment.