From 2977d5068b878ae0357ec8471e73b126aefdcd00 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 8 Mar 2022 00:51:30 -0800 Subject: [PATCH 1/2] Use tomllib on Python 3.11 --- docs/installation.rst | 4 ++-- setup.cfg | 2 +- src/build/__init__.py | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index e098c61a..563ff576 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -37,8 +37,8 @@ This package can build itself with only the ``toml`` and ``pep517`` dependencies. The ``--skip-dependency-check`` flag should be used in this case. -We have a dependency on tomli_, but toml_ can be used instead, which may make -bootstrapping easier. +On Python 3.10 and older, we have a dependency on tomli_, but toml_ can be +used instead, which may make bootstrapping easier. Compatibility diff --git a/setup.cfg b/setup.cfg index 16d08d04..0c610723 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,9 +28,9 @@ packages = find: install_requires = packaging>=19.0 pep517>=0.9.1 - tomli>=1.0.0 # toml can be used instead -- in case it makes bootstrapping easier colorama;os_name == "nt" # not actually a runtime dependency, only supplied as there is not "recommended dependency" support importlib-metadata>=0.22;python_version < "3.8" + tomli>=1.0.0;python_version < "3.11" # toml can be used instead -- in case it makes bootstrapping easier python_requires = >=3.6 package_dir = =src diff --git a/src/build/__init__.py b/src/build/__init__.py index a1117df9..a5b789cc 100644 --- a/src/build/__init__.py +++ b/src/build/__init__.py @@ -40,13 +40,16 @@ TOMLDecodeError: Type[Exception] toml_loads: Callable[[str], MutableMapping[str, Any]] - try: - from tomli import TOMLDecodeError - from tomli import loads as toml_loads -except ModuleNotFoundError: # pragma: no cover - from toml import TomlDecodeError as TOMLDecodeError # type: ignore - from toml import loads as toml_loads # type: ignore + from tomllib import TOMLDecodeError # type: ignore + from tomllib import loads as toml_loads # type: ignore +except ModuleNotFoundError: + try: + from tomli import TOMLDecodeError + from tomli import loads as toml_loads + except ModuleNotFoundError: # pragma: no cover + from toml import TomlDecodeError as TOMLDecodeError # type: ignore + from toml import loads as toml_loads # type: ignore RunnerType = Callable[[Sequence[str], Optional[str], Optional[Mapping[str, str]]], None] From 0623ad1989071e0c1fb3b825fc2e86418f2475d5 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 8 Mar 2022 13:18:49 -0800 Subject: [PATCH 2/2] use sys.version check --- src/build/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/build/__init__.py b/src/build/__init__.py index a5b789cc..f061c20c 100644 --- a/src/build/__init__.py +++ b/src/build/__init__.py @@ -40,10 +40,10 @@ TOMLDecodeError: Type[Exception] toml_loads: Callable[[str], MutableMapping[str, Any]] -try: - from tomllib import TOMLDecodeError # type: ignore - from tomllib import loads as toml_loads # type: ignore -except ModuleNotFoundError: +if sys.version_info >= (3, 11): + from tomllib import TOMLDecodeError + from tomllib import loads as toml_loads +else: try: from tomli import TOMLDecodeError from tomli import loads as toml_loads