Skip to content

Commit 6b76e18

Browse files
hroncokpre-commit-ci[bot]gaborbernat
authored
Use tomllib from the standard library on Python 3.11+ (#2463)
Co-authored-by: Miro Hrončok <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bernát Gábor <[email protected]>
1 parent 3d67ccc commit 6b76e18

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
rev: v1.12.1
2929
hooks:
3030
- id: blacken-docs
31-
additional_dependencies: [ black==21.12b0 ]
31+
additional_dependencies: [ black==22.6 ]
3232
- repo: https://github.com/pre-commit/pygrep-hooks
3333
rev: v1.9.0
3434
hooks:

docs/changelog/2463.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use ``tomllib`` on Python 3.11 or later and ``tomli`` instead of ``toml`` library on lower versions - by :user:`hroncok`.

docs/example/jenkins.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ with this:
6363
url = "https://bitbucket.org/hpk42/tox/raw/default/toxbootstrap.py"
6464
# os.environ['USETOXDEV']="1" # use tox dev version
6565
d = dict(__file__="toxbootstrap.py")
66-
exec urllib.urlopen(url).read() in d
66+
exec(urllib.urlopen(url).read(), globals=d)
6767
d["cmdline"](["--recreate"])
6868
6969
The downloaded ``toxbootstrap.py`` file downloads all necessary files to

setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ install_requires =
3939
pluggy>=0.12.0
4040
py>=1.4.17
4141
six>=1.14.0 # required when virtualenv>=20
42-
toml>=0.9.4
4342
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
4443
colorama>=0.4.1 ;platform_system=="Windows"
4544
importlib-metadata>=0.12;python_version<"3.8"
45+
toml>=0.10.2;python_version<="3.6"
46+
tomli>=2.0.1;python_version>="3.7" and python_version<"3.11"
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

+21-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@
2020
import pluggy
2121
import py
2222
import six
23-
import toml
23+
24+
if sys.version_info >= (3, 11):
25+
import tomllib as toml_loader
26+
27+
toml_mode = "rb"
28+
toml_encoding = None
29+
elif sys.version_info >= (3, 7):
30+
import tomli as toml_loader
31+
32+
toml_mode = "rb"
33+
toml_encoding = None
34+
else:
35+
import toml as toml_loader
36+
37+
toml_mode = "r"
38+
toml_encoding = "UTF-8"
39+
40+
2441
from packaging import requirements
2542
from packaging.utils import canonicalize_name
2643
from packaging.version import Version
@@ -304,9 +321,9 @@ def parseconfig(args, plugins=()):
304321

305322

306323
def get_py_project_toml(path):
307-
with io.open(str(path), encoding="UTF-8") as file_handler:
308-
config_data = toml.load(file_handler)
309-
return config_data
324+
with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler:
325+
config_data = toml_loader.load(file_handler)
326+
return config_data
310327

311328

312329
def propose_configs(cli_config_file):

tox.ini

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ passenv =
4848
basepython = python3.10
4949
skip_install = true
5050
deps =
51-
pre-commit>=2.16
51+
pre-commit>=2.20
5252
extras =
5353
lint
5454
commands =
@@ -65,8 +65,8 @@ setenv =
6565
COVERAGE_FILE = {toxworkdir}/.coverage
6666
skip_install = true
6767
deps =
68-
coverage>=6.2
69-
diff-cover>=6.4
68+
coverage>=6.4.4
69+
diff-cover>=6.5.1
7070
parallel_show_output = true
7171
commands =
7272
coverage combine
@@ -90,7 +90,7 @@ description = check that the long description is valid
9090
basepython = python3.9
9191
skip_install = true
9292
deps =
93-
twine>=3.7.1
93+
twine>=4.0.1
9494
extras =
9595
commands =
9696
pip wheel -w {envtmpdir}/build --no-deps .
@@ -114,9 +114,9 @@ passenv =
114114
*
115115
basepython = python3.10
116116
deps =
117-
gitpython>=3.1.24
117+
gitpython>=3.1.27
118118
packaging>=21.3
119-
towncrier>=21.3
119+
towncrier>=21.9
120120
commands =
121121
python {toxinidir}/tasks/release.py --version {posargs}
122122

0 commit comments

Comments
 (0)