Skip to content

Commit 0ed31db

Browse files
hroncokgaborbernat
authored andcommitted
fixup: Fallback to toml, not tomli, for Python 2 support
1 parent b2bbc6e commit 0ed31db

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ 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;python_version<"3.11"
45+
toml;python_version<"3.11"
4646
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
4747

4848
[options.packages.find]

src/tox/config/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
import six
2323

2424
if sys.version_info >= (3, 11):
25-
import tomllib
25+
import tomllib as toml_loader
26+
toml_mode = "rb"
27+
toml_encoding = None
2628
else:
27-
import tomli as tomllib
29+
import toml as toml_loader
30+
toml_mode = "r"
31+
toml_encoding = "UTF-8"
2832

2933
from packaging import requirements
3034
from packaging.utils import canonicalize_name
@@ -309,8 +313,8 @@ def parseconfig(args, plugins=()):
309313

310314

311315
def get_py_project_toml(path):
312-
with io.open(str(path), mode="rb") as file_handler:
313-
config_data = tomllib.load(file_handler)
316+
with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler:
317+
config_data = toml_loader.load(file_handler)
314318
return config_data
315319

316320

0 commit comments

Comments
 (0)