From f8d10c5318d08809c6da3238744a0de9b18b7cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 21 Jul 2022 16:09:42 +0200 Subject: [PATCH 01/12] Use tomllib from the standard library on Python 3.11+ Fallback to tomli, which has the same API. Fixes https://github.com/tox-dev/tox/issues/2462 --- setup.cfg | 2 +- src/tox/config/__init__.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index afba72edc..fedce7298 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,7 @@ install_requires = pluggy>=0.12.0 py>=1.4.17 six>=1.14.0 # required when virtualenv>=20 - toml>=0.9.4 + tomli;python_version<"3.11" 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" diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 9e08725da..d3820579d 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -20,7 +20,12 @@ import pluggy import py import six -import toml + +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + from packaging import requirements from packaging.utils import canonicalize_name from packaging.version import Version @@ -304,8 +309,8 @@ 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) + with io.open(str(path), mode="rb") as file_handler: + config_data = tomllib.load(file_handler) return config_data From b2bbc6e9495216fcb0eeaf50e6cfd0bdf40765d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:11:53 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index fedce7298..9a0551529 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,10 +39,10 @@ install_requires = pluggy>=0.12.0 py>=1.4.17 six>=1.14.0 # required when virtualenv>=20 - tomli;python_version<"3.11" 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" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] From 0ed31dbd55a31cec7b7432c3ca9bde3e714f926a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Sat, 23 Jul 2022 20:54:03 +0200 Subject: [PATCH 03/12] fixup: Fallback to toml, not tomli, for Python 2 support --- setup.cfg | 2 +- src/tox/config/__init__.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9a0551529..dbc138e55 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index d3820579d..b51df44d7 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -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 @@ -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: + config_data = toml_loader.load(file_handler) return config_data From 99dd8448142299e883848d0bb30d2126f3497ff7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 18:54:53 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for more information, see https://pre-commit.ci Signed-off-by: Bernát Gábor --- .pre-commit-config.yaml | 2 +- docs/changelog/2463.feature.rst | 1 + docs/example/jenkins.rst | 2 +- setup.cfg | 2 +- src/tox/config/__init__.py | 15 +++++---------- tox.ini | 12 ++++++------ 6 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 docs/changelog/2463.feature.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9fd83f586..f4389c044 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/docs/changelog/2463.feature.rst b/docs/changelog/2463.feature.rst new file mode 100644 index 000000000..ac18b0581 --- /dev/null +++ b/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:`gaborbernat`. diff --git a/docs/example/jenkins.rst b/docs/example/jenkins.rst index cdbd589df..bf8e3d426 100644 --- a/docs/example/jenkins.rst +++ b/docs/example/jenkins.rst @@ -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 diff --git a/setup.cfg b/setup.cfg index dbc138e55..35ffc6b8f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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" - toml;python_version<"3.11" + tomli>=2.0.1;python_version<"3.11" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index b51df44d7..3f4980477 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -1,7 +1,6 @@ from __future__ import print_function import argparse -import io import itertools import json import os @@ -22,13 +21,9 @@ import six if sys.version_info >= (3, 11): - import tomllib as toml_loader - toml_mode = "rb" - toml_encoding = None + import tomllib as toml else: - import toml as toml_loader - toml_mode = "r" - toml_encoding = "UTF-8" + import tomli as toml from packaging import requirements from packaging.utils import canonicalize_name @@ -313,9 +308,9 @@ def parseconfig(args, plugins=()): def get_py_project_toml(path): - with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler: - config_data = toml_loader.load(file_handler) - return config_data + with open(str(path), mode="rb") as file_handler: + config_data = toml.load(file_handler) + return config_data def propose_configs(cli_config_file): diff --git a/tox.ini b/tox.ini index 8a8972bcc..c2557528b 100644 --- a/tox.ini +++ b/tox.ini @@ -48,7 +48,7 @@ passenv = basepython = python3.10 skip_install = true deps = - pre-commit>=2.16 + pre-commit>=2.20 extras = lint commands = @@ -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 @@ -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 . @@ -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} From 6b3626389d3ebc457f7f45f72f91d46870409566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Aug 2022 21:28:03 +0200 Subject: [PATCH 05/12] Use toml/tomli/tomlib --- setup.cfg | 3 ++- src/tox/config/__init__.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 35ffc6b8f..e159963ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,7 +42,8 @@ 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>=2.0.1;python_version<"3.11" + tomli>=2.0.1;python_version>="3.5" and python_version<"3.11" + toml;python_version=="2.7" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 3f4980477..31202cdcd 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -21,9 +21,18 @@ import six if sys.version_info >= (3, 11): - import tomllib as toml + import tomllib as toml_loader + toml_mode = "rb" + toml_encoding = None +elif sys.version_info >= (3,): + import tomli as toml_loader + toml_mode = "rb" + toml_encoding = None else: - import tomli as toml + import toml as toml_loader + toml_mode = "r" + toml_encoding = "UTF-8" + from packaging import requirements from packaging.utils import canonicalize_name @@ -308,8 +317,8 @@ def parseconfig(args, plugins=()): def get_py_project_toml(path): - with open(str(path), mode="rb") as file_handler: - config_data = toml.load(file_handler) + with open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler: + config_data = toml_loader.load(file_handler) return config_data From 1869e11dad3c0f8bb2782cf087f0c813108e386e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Aug 2022 21:29:28 +0200 Subject: [PATCH 06/12] Use io.open once again for python 2 --- src/tox/config/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 31202cdcd..99b4becc6 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -1,6 +1,7 @@ from __future__ import print_function import argparse +import io import itertools import json import os @@ -317,7 +318,7 @@ def parseconfig(args, plugins=()): def get_py_project_toml(path): - with open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler: + with io.open(str(path), mode=toml_mode, encoding=toml_encoding) as file_handler: config_data = toml_loader.load(file_handler) return config_data From 89654f9dde6bb0b7edf722750cb89862aeeff1f5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Aug 2022 19:31:17 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.cfg | 2 +- src/tox/config/__init__.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e159963ea..416bb9ffb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,8 +42,8 @@ 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>=2.0.1;python_version>="3.5" and python_version<"3.11" toml;python_version=="2.7" + tomli>=2.0.1;python_version>="3.5" and python_version<"3.11" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 99b4becc6..466dc59e1 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -23,14 +23,17 @@ if sys.version_info >= (3, 11): import tomllib as toml_loader + toml_mode = "rb" toml_encoding = None elif sys.version_info >= (3,): 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 65430edc59fe357cda9f0b21edc6d8d24f93b1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Aug 2022 21:43:24 +0200 Subject: [PATCH 08/12] Make it install on older Python 3.6 --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 416bb9ffb..8abf0f739 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,8 +42,8 @@ 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" - toml;python_version=="2.7" - tomli>=2.0.1;python_version>="3.5" and python_version<"3.11" + toml>=0.9.4;python_version=="2.7" + tomli;python_version>="3.5" and python_version<"3.11" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] From 9ab5f1627c99b0d185d9cb8a0688ea6b6e7d4c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Aug 2022 22:17:38 +0200 Subject: [PATCH 09/12] Use toml on 3.6 as well --- setup.cfg | 4 ++-- src/tox/config/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8abf0f739..6a09987e7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,8 +42,8 @@ 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" - toml>=0.9.4;python_version=="2.7" - tomli;python_version>="3.5" and python_version<"3.11" + toml>=0.9.4;python_version<="3.5" + tomli;python_version>="3.6" and python_version<"3.11" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* [options.packages.find] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 466dc59e1..40d0784f4 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -26,7 +26,7 @@ toml_mode = "rb" toml_encoding = None -elif sys.version_info >= (3,): +elif sys.version_info >= (3, 6): import tomli as toml_loader toml_mode = "rb" From 0985069f5300f9016ce3efc832de5e6a0fd2fc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 22 Aug 2022 15:19:51 -0700 Subject: [PATCH 10/12] Update docs/changelog/2463.feature.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miro Hrončok --- docs/changelog/2463.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/2463.feature.rst b/docs/changelog/2463.feature.rst index ac18b0581..695520754 100644 --- a/docs/changelog/2463.feature.rst +++ b/docs/changelog/2463.feature.rst @@ -1 +1 @@ -Use ``tomllib`` on Python 3.11 or later and ``tomli`` instead of ``toml`` library on lower versions - by :user:`gaborbernat`. +Use ``tomllib`` on Python 3.11 or later and ``tomli`` instead of ``toml`` library on lower versions - by :user:`hroncok`. From c369057645ebe253649f5519309d23ccbedda157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 23 Aug 2022 14:09:41 +0200 Subject: [PATCH 11/12] Pin toml to the latest (and probably last) version (as requested in review) --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 6a09987e7..f60c4093b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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" - toml>=0.9.4;python_version<="3.5" + toml>=0.10.2;python_version<="3.5" tomli;python_version>="3.6" and python_version<"3.11" python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* From 98ae8528de8602a09c938afbff587cfb2194a789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 23 Aug 2022 14:11:37 +0200 Subject: [PATCH 12/12] Use toml on Python 3.6 as well, so we can pin tomli to 2.0.1+ --- setup.cfg | 4 ++-- src/tox/config/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index f60c4093b..37013e356 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,8 +42,8 @@ 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" - toml>=0.10.2;python_version<="3.5" - tomli;python_version>="3.6" and python_version<"3.11" + 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] diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 40d0784f4..75b9ab92f 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -26,7 +26,7 @@ toml_mode = "rb" toml_encoding = None -elif sys.version_info >= (3, 6): +elif sys.version_info >= (3, 7): import tomli as toml_loader toml_mode = "rb"