Skip to content

Commit

Permalink
Use tomllib from the standard library on Python 3.11+ (#2463)
Browse files Browse the repository at this point in the history
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
  • Loading branch information
3 people committed Aug 29, 2022
1 parent 3d67ccc commit 6b76e18
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -28,7 +28,7 @@ repos:
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [ black==21.12b0 ]
additional_dependencies: [ black==22.6 ]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2463.feature.rst
@@ -0,0 +1 @@
Use ``tomllib`` on Python 3.11 or later and ``tomli`` instead of ``toml`` library on lower versions - by :user:`hroncok`.
2 changes: 1 addition & 1 deletion docs/example/jenkins.rst
Expand Up @@ -63,7 +63,7 @@ with this:
url = "https://bitbucket.org/hpk42/tox/raw/default/toxbootstrap.py"
# os.environ['USETOXDEV']="1" # use tox dev version
d = dict(__file__="toxbootstrap.py")
exec urllib.urlopen(url).read() in d
exec(urllib.urlopen(url).read(), globals=d)
d["cmdline"](["--recreate"])
The downloaded ``toxbootstrap.py`` file downloads all necessary files to
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Expand Up @@ -39,10 +39,11 @@ install_requires =
pluggy>=0.12.0
py>=1.4.17
six>=1.14.0 # required when virtualenv>=20
toml>=0.9.4
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"
toml>=0.10.2;python_version<="3.6"
tomli>=2.0.1;python_version>="3.7" and python_version<"3.11"
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*

[options.packages.find]
Expand Down
25 changes: 21 additions & 4 deletions src/tox/config/__init__.py
Expand Up @@ -20,7 +20,24 @@
import pluggy
import py
import six
import toml

if sys.version_info >= (3, 11):
import tomllib as toml_loader

toml_mode = "rb"
toml_encoding = None
elif sys.version_info >= (3, 7):
import tomli as toml_loader

toml_mode = "rb"
toml_encoding = None
else:
import toml as toml_loader

toml_mode = "r"
toml_encoding = "UTF-8"


from packaging import requirements
from packaging.utils import canonicalize_name
from packaging.version import Version
Expand Down Expand Up @@ -304,9 +321,9 @@ def parseconfig(args, plugins=()):


def get_py_project_toml(path):
with io.open(str(path), encoding="UTF-8") as file_handler:
config_data = toml.load(file_handler)
return config_data
with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler:
config_data = toml_loader.load(file_handler)
return config_data


def propose_configs(cli_config_file):
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Expand Up @@ -48,7 +48,7 @@ passenv =
basepython = python3.10
skip_install = true
deps =
pre-commit>=2.16
pre-commit>=2.20
extras =
lint
commands =
Expand All @@ -65,8 +65,8 @@ setenv =
COVERAGE_FILE = {toxworkdir}/.coverage
skip_install = true
deps =
coverage>=6.2
diff-cover>=6.4
coverage>=6.4.4
diff-cover>=6.5.1
parallel_show_output = true
commands =
coverage combine
Expand All @@ -90,7 +90,7 @@ description = check that the long description is valid
basepython = python3.9
skip_install = true
deps =
twine>=3.7.1
twine>=4.0.1
extras =
commands =
pip wheel -w {envtmpdir}/build --no-deps .
Expand All @@ -114,9 +114,9 @@ passenv =
*
basepython = python3.10
deps =
gitpython>=3.1.24
gitpython>=3.1.27
packaging>=21.3
towncrier>=21.3
towncrier>=21.9
commands =
python {toxinidir}/tasks/release.py --version {posargs}

Expand Down

0 comments on commit 6b76e18

Please sign in to comment.