summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-11-03 09:59:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2019-11-03 21:27:42 -0500
commita44e6e48abfdab8f5a7e457ae1e481005f7bdbe5 (patch)
tree56b56b992c9e5bc7f526322ddc0555a97431b226
parentf97d0750a91e53bec387528344c1ca3bf86e1d08 (diff)
downloadpython-coveragepy-git-a44e6e48abfdab8f5a7e457ae1e481005f7bdbe5.tar.gz
Cleanups for TOML code
-rw-r--r--CHANGES.rst12
-rw-r--r--coverage/tomlconfig.py24
-rw-r--r--doc/config.rst6
-rw-r--r--setup.py2
-rw-r--r--tox.ini3
5 files changed, 34 insertions, 13 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 595c02b3..a02fe5b1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -23,6 +23,12 @@ Unreleased
- The HTML and textual reports now have a ``--skip-empty`` option that skips
files with no statements (notably, ``__init__.py`` files). Thanks, Reya B.
+- Configuration can now be read from `TOML`_ files. This requires installing
+ coverage.py with the ``[toml]`` extra. The standard "pyproject.toml" file
+ will be read automatically if no other configuration file is found, with
+ settings in the ``[tool.coverage.]`` namespace. Thanks to Frazer McLean for
+ implementation and persistence. Finishes `issue 664`_.
+
- The HTML report has been reimplemented (no more table around the source
code). This allowed for a better presentation of the context information,
hopefully resolving `issue 855`_.
@@ -33,6 +39,8 @@ Unreleased
``coverage html --show-contexts``) will issue a warning if there were no
contexts measured (`issue 851`_).
+.. _TOML: https://github.com/toml-lang/toml#toml
+.. _issue 664: https://github.com/nedbat/coveragepy/issues/664
.. _issue 851: https://github.com/nedbat/coveragepy/issues/851
.. _issue 855: https://github.com/nedbat/coveragepy/issues/855
@@ -79,15 +87,11 @@ Version 5.0a7 --- 2019-09-21
- ``debug=plugin`` didn't properly support configuration or dynamic context
plugins, but now it does, closing `issue 834`_.
-
-- Added TOML configuration support, including pyproject.toml `issue 664`_.
-
.. _issue 720: https://github.com/nedbat/coveragepy/issues/720
.. _issue 822: https://github.com/nedbat/coveragepy/issues/822
.. _issue 834: https://github.com/nedbat/coveragepy/issues/834
.. _issue 829: https://github.com/nedbat/coveragepy/issues/829
.. _issue 846: https://github.com/nedbat/coveragepy/issues/846
-.. _issue 664: https://github.com/nedbat/coveragepy/issues/664
.. _changes_50a6:
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py
index 0d084603..b6499ec4 100644
--- a/coverage/tomlconfig.py
+++ b/coverage/tomlconfig.py
@@ -1,3 +1,8 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+"""TOML configuration support for coverage.py"""
+
import io
import os
import re
@@ -9,9 +14,16 @@ from coverage.misc import CoverageException, substitute_variables
class TomlDecodeError(Exception):
"""An exception class that exists even when toml isn't installed."""
+ pass
class TomlConfigParser:
+ """TOML file reading with the interface of HandyConfigParser."""
+
+ # This class has the same interface as config.HandyConfigParser, no
+ # need for docstrings.
+ # pylint: disable=missing-function-docstring
+
def __init__(self, our_file):
self.getters = [lambda obj: obj['tool']['coverage']]
if our_file:
@@ -101,7 +113,8 @@ class TomlConfigParser:
if not isinstance(value, bool):
raise ValueError(
'Option {!r} in section {!r} is not a boolean: {!r}'
- .format(option, section, value))
+ .format(option, section, value)
+ )
return value
def getlist(self, section, option):
@@ -109,7 +122,8 @@ class TomlConfigParser:
if not isinstance(values, list):
raise ValueError(
'Option {!r} in section {!r} is not a list: {!r}'
- .format(option, section, values))
+ .format(option, section, values)
+ )
for i, value in enumerate(values):
if isinstance(value, string_class):
values[i] = substitute_variables(value, os.environ)
@@ -132,7 +146,8 @@ class TomlConfigParser:
if not isinstance(value, int):
raise ValueError(
'Option {!r} in section {!r} is not an integer: {!r}'
- .format(option, section, value))
+ .format(option, section, value)
+ )
return value
def getfloat(self, section, option):
@@ -142,5 +157,6 @@ class TomlConfigParser:
if not isinstance(value, float):
raise ValueError(
'Option {!r} in section {!r} is not a float: {!r}'
- .format(option, section, value))
+ .format(option, section, value)
+ )
return value
diff --git a/doc/config.rst b/doc/config.rst
index b8a3d328..f7483d06 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -29,10 +29,10 @@ Coverage.py will read settings from other usual configuration files if no other
configuration file is used. It will automatically read from "setup.cfg" or
"tox.ini" if they exist. In this case, the section names have "coverage:"
prefixed, so the ``[run]`` options described below will be found in the
-``[coverage:run]`` section of the file. If Coverage.py is installed with the
+``[coverage:run]`` section of the file. If coverage.py is installed with the
``toml`` extra (``pip install coverage[toml]``), it will automatically read
-from "pyproject.toml". Configuration must be within the `[tool.coverage]`
-section, e.g. ``[tool.coverage.run]`.
+from "pyproject.toml". Configuration must be within the ``[tool.coverage]``
+section, for example, ``[tool.coverage.run]``.
Syntax
diff --git a/setup.py b/setup.py
index cd6619b3..10973740 100644
--- a/setup.py
+++ b/setup.py
@@ -94,7 +94,7 @@ setup_args = dict(
},
extras_require={
- # Enable pyproject.toml support
+ # Enable pyproject.toml support.
'toml': ['toml'],
},
diff --git a/tox.ini b/tox.ini
index 1305f2e4..935c88dd 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,6 +8,8 @@ toxworkdir = {env:TOXWORKDIR:.tox}
[testenv]
usedevelop = True
+extras =
+ toml
deps =
# Check here for what might be out of date:
@@ -15,7 +17,6 @@ deps =
-r requirements/pytest.pip
pip==19.3.1
setuptools==41.4.0
- toml
# gevent 1.3 causes a failure: https://github.com/nedbat/coveragepy/issues/663
py{27,35,36}: gevent==1.2.2
py{27,35,36,37,38}: eventlet==0.25.1