5 |
5 |
6 import configparser |
6 import configparser |
7 import os |
7 import os |
8 import re |
8 import re |
9 |
9 |
10 from coverage.exceptions import CoverageException |
10 from coverage.exceptions import ConfigError |
11 from coverage.misc import import_third_party, substitute_variables |
11 from coverage.misc import import_third_party, substitute_variables |
12 |
12 |
13 # TOML support is an install-time extra option. (Import typing is here because |
13 # TOML support is an install-time extra option. (Import typing is here because |
14 # import_third_party will unload any module that wasn't already imported. |
14 # import_third_party will unload any module that wasn't already imported. |
15 # tomli imports typing, and if we unload it, later it's imported again, and on |
15 # tomli imports typing, and if we unload it, later it's imported again, and on |
55 else: |
55 else: |
56 has_toml = re.search(r"^\[tool\.coverage\.", toml_text, flags=re.MULTILINE) |
56 has_toml = re.search(r"^\[tool\.coverage\.", toml_text, flags=re.MULTILINE) |
57 if self.our_file or has_toml: |
57 if self.our_file or has_toml: |
58 # Looks like they meant to read TOML, but we can't read it. |
58 # Looks like they meant to read TOML, but we can't read it. |
59 msg = "Can't read {!r} without TOML support. Install with [toml] extra" |
59 msg = "Can't read {!r} without TOML support. Install with [toml] extra" |
60 raise CoverageException(msg.format(filename)) |
60 raise ConfigError(msg.format(filename)) |
61 return [] |
61 return [] |
62 |
62 |
63 def _get_section(self, section): |
63 def _get_section(self, section): |
64 """Get a section from the data. |
64 """Get a section from the data. |
65 |
65 |
146 for value in values: |
146 for value in values: |
147 value = value.strip() |
147 value = value.strip() |
148 try: |
148 try: |
149 re.compile(value) |
149 re.compile(value) |
150 except re.error as e: |
150 except re.error as e: |
151 raise CoverageException(f"Invalid [{name}].{option} value {value!r}: {e}") from e |
151 raise ConfigError(f"Invalid [{name}].{option} value {value!r}: {e}") from e |
152 return values |
152 return values |
153 |
153 |
154 def getint(self, section, option): |
154 def getint(self, section, option): |
155 name, value = self._get(section, option) |
155 name, value = self._get(section, option) |
156 self._check_type(name, option, value, int, "an integer") |
156 self._check_type(name, option, value, int, "an integer") |