Skip to content

Commit

Permalink
build: switch to tomli for TOML v1 compliant parser
Browse files Browse the repository at this point in the history
Fixes #308

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Aug 1, 2021
1 parent e6a82a1 commit 99f717c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
- Improved output (`PR #333`_, Fixes `#142`_)
- The CLI now honnors `NO_COLOR`_ (`PR #333`_)
- Added logging to ``build`` and ``build.env`` (`PR #333`_)
- Switch to a TOML v1 compliant parser (`PR #336`_, Fixes `#308`_)


Breaking Changes
Expand All @@ -17,7 +18,9 @@ Breaking Changes
- Dropped support for Python 2 and 3.5.

.. _PR #333: https://github.com/pypa/build/pull/333
.. _PR #336: https://github.com/pypa/build/pull/336
.. _#142: https://github.com/pypa/build/issues/142
.. _#308: https://github.com/pypa/build/issues/308
.. _NO_COLOR: https://no-color.org


Expand Down
6 changes: 6 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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
bootstraping easier.


Compatibility
=============
Expand Down Expand Up @@ -66,6 +69,9 @@ versions:
.. _git tag: https://github.com/pypa/build/tags
.. _project page: https://pypi.org/project/build/

.. _tomli: https://github.com/hukkin/tomli
.. _toml: https://github.com/uiri/toml


.. |3DCE51D60930EBA47858BA4146F633CBB0EB4BF2| replace:: ``3DCE51D60930EBA47858BA4146F633CBB0EB4BF2``
.. _3DCE51D60930EBA47858BA4146F633CBB0EB4BF2: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3dce51d60930eba47858ba4146f633cbb0eb4bf2
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ packages = find:
install_requires =
packaging>=19.0
pep517>=0.9.1
toml>=0.10.0
tomli>=1.0.0 # toml can be used instead
colorama;os_name == "nt" # not actually a runtime dependency, only supplied as there is not "recomended dependency" support
importlib-metadata>=0.22;python_version < "3.8"
python_requires = >=3.6
Expand Down
14 changes: 12 additions & 2 deletions src/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
from typing import AbstractSet, Any, Callable, Dict, Iterator, Mapping, Optional, Sequence, Set, Tuple, Type, Union

import pep517.wrappers
import toml


try:
import tomli as toml

TOMLDecodeError: Type[Exception] = toml.TOMLDecodeError
except ModuleNotFoundError: # pragma: no cover
import toml as _toml

toml = _toml # type: ignore
TOMLDecodeError = _toml.TomlDecodeError


RunnerType = Callable[[Sequence[str], Optional[str], Optional[Mapping[str, str]]], None]
Expand Down Expand Up @@ -191,7 +201,7 @@ def __init__(
spec = {}
except PermissionError as e:
raise BuildException(f"{e.strerror}: '{e.filename}' ")
except toml.TomlDecodeError as e:
except TOMLDecodeError as e:
raise BuildException(f'Failed to parse {spec_file}: {e} ')

build_system = spec.get('build-system')
Expand Down

0 comments on commit 99f717c

Please sign in to comment.