Skip to content

Commit

Permalink
build: drop toml fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Jan 25, 2023
1 parent 01523ac commit 89675e8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 42 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies = [
# not actually a runtime dependency, only supplied as there is not "recommended dependency" support
'colorama; os_name == "nt"',
'importlib-metadata >= 0.22; python_version < "3.8"',
# toml can be used instead -- in case it makes bootstrapping easier
'tomli >= 1.1.0; python_version < "3.11"',
]

Expand All @@ -54,7 +53,6 @@ test = [
"pytest-mock >= 2",
"pytest-rerunfailures >= 9.1",
"pytest-xdist >= 1.34",
"toml >= 0.10.0",
"wheel >= 0.36.0",
'setuptools >= 42.0.0; python_version < "3.10"',
'setuptools >= 56.0.0; python_version >= "3.10"',
Expand Down
17 changes: 4 additions & 13 deletions src/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,10 @@
from ._util import check_dependency, parse_wheel_filename


TOMLDecodeError: type[Exception]
toml_loads: Callable[[str], Mapping[str, Any]]

if sys.version_info >= (3, 11):
from tomllib import TOMLDecodeError
from tomllib import loads as toml_loads
import tomllib
else:
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[import,no-redef]
from toml import loads as toml_loads # type: ignore[no-redef]
import tomli as tomllib


RunnerType = Callable[[Sequence[str], Optional[str], Optional[Mapping[str, str]]], None]
Expand Down Expand Up @@ -86,12 +77,12 @@ def _validate_source_directory(source_dir: PathType) -> None:
def _read_pyproject_toml(path: PathType) -> Mapping[str, Any]:
try:
with open(path, 'rb') as f:
return toml_loads(f.read().decode())
return tomllib.loads(f.read().decode())
except FileNotFoundError:
return {}
except PermissionError as e:
raise BuildException(f"{e.strerror}: '{e.filename}' ") # noqa: B904 # use raise from
except TOMLDecodeError as e:
except tomllib.TOMLDecodeError as e:
raise BuildException(f'Failed to parse {path}: {e} ') # noqa: B904 # use raise from


Expand Down
1 change: 0 additions & 1 deletion tests/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ packaging==19.0
pyproject_hooks==1.0
setuptools==42.0.0; python_version < "3.10"
setuptools==56.0.0; python_version >= "3.10"
toml==0.10.0
tomli==1.1.0
virtualenv==20.0.35
wheel==0.36.0
26 changes: 0 additions & 26 deletions tests/test_projectbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import copy
import importlib
import logging
import os
import sys
Expand Down Expand Up @@ -540,31 +539,6 @@ def test_metadata_invalid_wheel(tmp_dir, package_test_bad_wheel):
builder.metadata_path(tmp_dir)


@pytest.fixture
def mock_tomli_not_available(mocker):
loads = mocker.patch('tomli.loads')
mocker.patch.dict(sys.modules, {'tomli': None})
importlib.reload(build)
try:
yield
finally:
loads.assert_not_called()
mocker.stopall()
importlib.reload(build)


@pytest.mark.skipif(sys.version_info >= (3, 11), reason='No need to test old toml support on 3.11+')
def test_toml_instead_of_tomli(mocker, mock_tomli_not_available, tmp_dir, package_test_flit):
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.build_sdist.return_value = 'dist.tar.gz'

builder.build('sdist', '.')

builder._hook.build_sdist.assert_called_with(os.path.abspath('.'), None)


def test_log(mocker, caplog, package_test_flit):
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)
mocker.patch('build.ProjectBuilder._call_backend', return_value='some_path')
Expand Down

0 comments on commit 89675e8

Please # to comment.