Skip to content

Commit 6b36263

Browse files
committed
Use toml/tomli/tomlib
1 parent 99dd844 commit 6b36263

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ install_requires =
4242
virtualenv!=20.0.0,!=20.0.1,!=20.0.2,!=20.0.3,!=20.0.4,!=20.0.5,!=20.0.6,!=20.0.7,>=16.0.0
4343
colorama>=0.4.1 ;platform_system=="Windows"
4444
importlib-metadata>=0.12;python_version<"3.8"
45-
tomli>=2.0.1;python_version<"3.11"
45+
tomli>=2.0.1;python_version>="3.5" and python_version<"3.11"
46+
toml;python_version=="2.7"
4647
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
4748

4849
[options.packages.find]

src/tox/config/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@
2121
import six
2222

2323
if sys.version_info >= (3, 11):
24-
import tomllib as toml
24+
import tomllib as toml_loader
25+
toml_mode = "rb"
26+
toml_encoding = None
27+
elif sys.version_info >= (3,):
28+
import tomli as toml_loader
29+
toml_mode = "rb"
30+
toml_encoding = None
2531
else:
26-
import tomli as toml
32+
import toml as toml_loader
33+
toml_mode = "r"
34+
toml_encoding = "UTF-8"
35+
2736

2837
from packaging import requirements
2938
from packaging.utils import canonicalize_name
@@ -308,8 +317,8 @@ def parseconfig(args, plugins=()):
308317

309318

310319
def get_py_project_toml(path):
311-
with open(str(path), mode="rb") as file_handler:
312-
config_data = toml.load(file_handler)
320+
with open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler:
321+
config_data = toml_loader.load(file_handler)
313322
return config_data
314323

315324

0 commit comments

Comments
 (0)