Skip to content

Commit c3340b6

Browse files
graingerthukkin
andcommitted
Support TOML v1.0.0 syntax in pyproject.toml
fixes #1180 Co-authored-by: Taneli Hukkinen <[email protected]>
1 parent 809cccb commit c3340b6

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

coverage/tomlconfig.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
# TOML support is an install-time extra option.
1414
try:
15-
import toml
15+
import tomli
1616
except ImportError: # pragma: not covered
17-
toml = None
17+
tomli = None
1818

1919

2020
class TomlDecodeError(Exception):
@@ -44,12 +44,12 @@ def read(self, filenames):
4444
toml_text = fp.read()
4545
except OSError:
4646
return []
47-
if toml:
47+
if tomli is not None:
4848
toml_text = substitute_variables(toml_text, os.environ)
4949
try:
50-
self.data = toml.loads(toml_text)
51-
except toml.TomlDecodeError as err:
52-
raise TomlDecodeError(*err.args)
50+
self.data = tomli.loads(toml_text)
51+
except tomli.TOMLDecodeError as err:
52+
raise TomlDecodeError(str(err))
5353
return [filename]
5454
else:
5555
has_toml = re.search(r"^\[tool\.coverage\.", toml_text, flags=re.MULTILINE)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def better_set_verbosity(v):
107107

108108
extras_require={
109109
# Enable pyproject.toml support.
110-
'toml': ['toml'],
110+
'toml': ['tomli'],
111111
},
112112

113113
# We need to get HTML assets from our htmlfiles directory.

tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def without_module(using_module, missing_module_name):
242242
Use this in a test function to make an optional module unavailable during
243243
the test::
244244
245-
with without_module(product.something, 'toml'):
245+
with without_module(product.something, 'tomli'):
246246
use_toml_somehow()
247247
248248
Arguments:

tests/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,15 @@ def test_note_is_obsolete(self):
715715

716716
def test_no_toml_installed_no_toml(self):
717717
# Can't read a toml file that doesn't exist.
718-
with without_module(coverage.tomlconfig, 'toml'):
718+
with without_module(coverage.tomlconfig, 'tomli'):
719719
msg = "Couldn't read 'cov.toml' as a config file"
720720
with pytest.raises(CoverageException, match=msg):
721721
coverage.Coverage(config_file="cov.toml")
722722

723723
def test_no_toml_installed_explicit_toml(self):
724724
# Can't specify a toml config file if toml isn't installed.
725725
self.make_file("cov.toml", "# A toml file!")
726-
with without_module(coverage.tomlconfig, 'toml'):
726+
with without_module(coverage.tomlconfig, 'tomli'):
727727
msg = "Can't read 'cov.toml' without TOML support"
728728
with pytest.raises(CoverageException, match=msg):
729729
coverage.Coverage(config_file="cov.toml")
@@ -735,7 +735,7 @@ def test_no_toml_installed_pyproject_toml(self):
735735
[tool.coverage.run]
736736
xyzzy = 17
737737
""")
738-
with without_module(coverage.tomlconfig, 'toml'):
738+
with without_module(coverage.tomlconfig, 'tomli'):
739739
msg = "Can't read 'pyproject.toml' without TOML support"
740740
with pytest.raises(CoverageException, match=msg):
741741
coverage.Coverage()
@@ -747,7 +747,7 @@ def test_no_toml_installed_pyproject_no_coverage(self):
747747
[tool.something]
748748
xyzzy = 17
749749
""")
750-
with without_module(coverage.tomlconfig, 'toml'):
750+
with without_module(coverage.tomlconfig, 'tomli'):
751751
cov = coverage.Coverage()
752752
# We get default settings:
753753
assert not cov.config.timid

tests/test_testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _same_python_executable(e1, e2):
348348

349349
def test_without_module():
350350
toml1 = tomlconfig.toml
351-
with without_module(tomlconfig, 'toml'):
351+
with without_module(tomlconfig, 'tomli'):
352352
toml2 = tomlconfig.toml
353353
toml3 = tomlconfig.toml
354354

0 commit comments

Comments
 (0)