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 on Python 3.11 #443

Merged
merged 3 commits into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/installation.rst
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/build/__init__.py
Expand Up @@ -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
henryiii marked this conversation as resolved.
Show resolved Hide resolved
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]
Expand Down