Skip to content

Commit

Permalink
debug #1516
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 28, 2022
1 parent 012a687 commit 2da8c20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions coverage/config.py
Expand Up @@ -291,12 +291,15 @@ def from_file(self, filename: str, warn: Callable[[str], None], our_file: bool)
else:
cp = HandyConfigParser(our_file)

print(f"{cp=}")
self.attempted_config_files.append(filename)

try:
files_read = cp.read(filename)
except (configparser.Error, TomlDecodeError) as err:
print(f"{err=}")
raise ConfigError(f"Couldn't read config file {filename}: {err}") from err
print(f"{files_read=}")
if not files_read:
return False

Expand All @@ -308,6 +311,7 @@ def from_file(self, filename: str, warn: Callable[[str], None], our_file: bool)
was_set = self._set_attr_from_config_option(cp, *option_spec)
if was_set:
any_set = True
print(f"{any_set=} because {option_spec=}")
except ValueError as err:
raise ConfigError(f"Couldn't read config file {filename}: {err}") from err

Expand All @@ -332,20 +336,24 @@ def from_file(self, filename: str, warn: Callable[[str], None], our_file: bool)
for option in cp.options('paths'):
self.paths[option] = cp.getlist('paths', option)
any_set = True
print(f"{any_set=} because paths:{option}")

# plugins can have options
for plugin in self.plugins:
if cp.has_section(plugin):
self.plugin_options[plugin] = cp.get_section(plugin)
any_set = True
print(f"{any_set=} because {plugin=}:{option}")

# Was this file used as a config file? If it's specifically our file,
# then it was used. If we're piggybacking on someone else's file,
# then it was only used if we found some settings in it.
print(f"{our_file=}")
if our_file:
used = True
else:
used = any_set
print(f"{used=}")

if used:
self.config_file = os.path.abspath(filename)
Expand Down Expand Up @@ -591,7 +599,9 @@ def read_coverage_config(
files_to_try = config_files_to_try(config_file)

for fname, our_file, specified_file in files_to_try:
print(f"Reading {fname=}")
config_read = config.from_file(fname, warn, our_file=our_file)
print(f"{config_read=}")
if config_read:
break
if specified_file:
Expand Down
5 changes: 4 additions & 1 deletion coverage/tomlconfig.py
Expand Up @@ -43,12 +43,15 @@ def read(self, filenames):
try:
with open(filename, encoding='utf-8') as fp:
toml_text = fp.read()
except OSError:
except OSError as err:
print(f"OSError {err=}")
return []
print(f"{tomllib=}")
if tomllib is not None:
try:
self.data = tomllib.loads(toml_text)
except tomllib.TOMLDecodeError as err:
print(f"TomlDecodeError {err=}")
raise TomlDecodeError(str(err)) from err
return [filename]
else:
Expand Down

0 comments on commit 2da8c20

Please sign in to comment.