diff --git a/setup.cfg b/setup.cfg index 77af6608f3a..8c666f94890 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,7 +47,8 @@ install_requires = pyyaml>=4.2b1 setuptools>=19.6 sympy!=1.9,>=1.2 # see https://github.com/sympy/sympy/issues/22241 - toml>=0.10.2 + tomli>=1.2.3 + tomli-w>=0.4.0 tqdm>=3.4.0 unyt>=2.8.0 python_requires = >=3.7,<3.12 @@ -103,6 +104,8 @@ minimal = matplotlib==2.2.3 more-itertools==8.4 numpy==1.14.5 + tomli==1.2.3 + tomli-w==0.4.0 unyt==2.8.0 test = codecov~=2.0.15 diff --git a/yt/config.py b/yt/config.py index d2e3868b9c3..08bf0db65d3 100644 --- a/yt/config.py +++ b/yt/config.py @@ -1,7 +1,9 @@ import os import warnings -import toml +# TODO: import tomllib from the standard library instead in Python >= 3.11 +import tomli as tomllib +import tomli_w from more_itertools import always_iterable from yt.utilities.configuration_tree import ConfigLeaf, ConfigNode @@ -144,14 +146,16 @@ def read(self, file_names): if not os.path.exists(fname): continue metadata = {"source": f"file: {fname}"} - self.update(toml.load(fname), metadata=metadata) + with open(fname, "rb") as fh: + data = tomllib.load(fh) + self.update(data, metadata=metadata) file_names_read.append(fname) return file_names_read def write(self, file_handler): value = self.config_root.as_dict() - config_as_str = toml.dumps(value) + config_as_str = tomli_w.dumps(value) try: # Assuming file_handler has a write attribute @@ -192,8 +196,8 @@ def _repr_json_(self): if not os.path.exists(_global_config_file): cfg = {"yt": {}} # type: ignore try: - with open(_global_config_file, mode="w") as fd: - toml.dump(cfg, fd) + with open(_global_config_file, mode="wb") as fd: + tomli_w.dump(cfg, fd) except OSError: warnings.warn("unable to write new config file")