Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tomllib from the standard library on Python 3.11+ #2463

Merged
merged 12 commits into from Aug 29, 2022
Merged
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -42,7 +42,7 @@ install_requires =
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
colorama>=0.4.1 ;platform_system=="Windows"
importlib-metadata>=0.12;python_version<"3.8"
tomli;python_version<"3.11"
toml;python_version<"3.11"
hroncok marked this conversation as resolved.
Show resolved Hide resolved
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*

[options.packages.find]
Expand Down
12 changes: 8 additions & 4 deletions src/tox/config/__init__.py
Expand Up @@ -22,9 +22,13 @@
import six

if sys.version_info >= (3, 11):
import tomllib
import tomllib as toml_loader
toml_mode = "rb"
toml_encoding = None
else:
import tomli as tomllib
import toml as toml_loader
toml_mode = "r"
toml_encoding = "UTF-8"

from packaging import requirements
from packaging.utils import canonicalize_name
Expand Down Expand Up @@ -309,8 +313,8 @@ def parseconfig(args, plugins=()):


def get_py_project_toml(path):
with io.open(str(path), mode="rb") as file_handler:
config_data = tomllib.load(file_handler)
with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler:
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
config_data = toml_loader.load(file_handler)
return config_data


Expand Down