--- a/eric7/DebugClients/Python/coverage/config.py Fri Nov 19 19:28:47 2021 +0100 +++ b/eric7/DebugClients/Python/coverage/config.py Sat Nov 20 16:47:38 2021 +0100 @@ -4,15 +4,14 @@ """Config file for coverage.py""" import collections +import configparser import copy import os import os.path import re -from coverage import env -from coverage.backward import configparser, iitems, string_class -from coverage.misc import contract, CoverageException, isolate_module -from coverage.misc import substitute_variables +from coverage.exceptions import CoverageException +from coverage.misc import contract, isolate_module, substitute_variables from coverage.tomlconfig import TomlConfigParser, TomlDecodeError @@ -35,12 +34,9 @@ if our_file: self.section_prefixes.append("") - def read(self, filenames, encoding=None): + def read(self, filenames, encoding_unused=None): """Read a file name as UTF-8 configuration data.""" - kwargs = {} - if env.PYVERSION >= (3, 2): - kwargs['encoding'] = encoding or "utf-8" - return configparser.RawConfigParser.read(self, filenames, **kwargs) + return configparser.RawConfigParser.read(self, filenames, encoding="utf-8") def has_option(self, section, option): for section_prefix in self.section_prefixes: @@ -128,8 +124,8 @@ re.compile(value) except re.error as e: raise CoverageException( - "Invalid [%s].%s value %r: %s" % (section, option, value, e) - ) + f"Invalid [{section}].{option} value {value!r}: {e}" + ) from e if value: value_list.append(value) return value_list @@ -154,7 +150,7 @@ ] -class CoverageConfig(object): +class CoverageConfig: """Coverage.py configuration. The attributes of this class are the various settings that control the @@ -245,14 +241,14 @@ def from_args(self, **kwargs): """Read config values from `kwargs`.""" - for k, v in iitems(kwargs): + for k, v in kwargs.items(): if v is not None: - if k in self.MUST_BE_LIST and isinstance(v, string_class): + if k in self.MUST_BE_LIST and isinstance(v, str): v = [v] setattr(self, k, v) @contract(filename=str) - def from_file(self, filename, our_file): + def from_file(self, filename, warn, our_file): """Read configuration from a .rc file. `filename` is a file name to read. @@ -276,7 +272,7 @@ try: files_read = cp.read(filename) except (configparser.Error, TomlDecodeError) as err: - raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) + raise CoverageException(f"Couldn't read config file {filename}: {err}") from err if not files_read: return False @@ -289,7 +285,7 @@ if was_set: any_set = True except ValueError as err: - raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) + raise CoverageException(f"Couldn't read config file {filename}: {err}") from err # Check that there are no unrecognized options. all_options = collections.defaultdict(set) @@ -297,12 +293,12 @@ section, option = option_spec[1].split(":") all_options[section].add(option) - for section, options in iitems(all_options): + for section, options in all_options.items(): real_section = cp.has_section(section) if real_section: for unknown in set(cp.options(section)) - options: - raise CoverageException( - "Unrecognized option '[%s] %s=' in config file %s" % ( + warn( + "Unrecognized option '[{}] {}=' in config file {}".format( real_section, unknown, filename ) ) @@ -447,7 +443,7 @@ return # If we get here, we didn't find the option. - raise CoverageException("No such option: %r" % option_name) + raise CoverageException(f"No such option: {option_name!r}") def get_option(self, option_name): """Get an option from the configuration. @@ -475,7 +471,7 @@ return self.plugin_options.get(plugin_name, {}).get(key) # If we get here, we didn't find the option. - raise CoverageException("No such option: %r" % option_name) + raise CoverageException(f"No such option: {option_name!r}") def post_process_file(self, path): """Make final adjustments to a file path to make it usable.""" @@ -521,12 +517,13 @@ return files_to_try -def read_coverage_config(config_file, **kwargs): +def read_coverage_config(config_file, warn, **kwargs): """Read the coverage.py configuration. Arguments: config_file: a boolean or string, see the `Coverage` class for the tricky details. + warn: a function to issue warnings. all others: keyword arguments from the `Coverage` class, used for setting values in the configuration. @@ -545,11 +542,11 @@ files_to_try = config_files_to_try(config_file) for fname, our_file, specified_file in files_to_try: - config_read = config.from_file(fname, our_file=our_file) + config_read = config.from_file(fname, warn, our_file=our_file) if config_read: break if specified_file: - raise CoverageException("Couldn't read '%s' as a config file" % fname) + raise CoverageException(f"Couldn't read {fname!r} as a config file") # $set_env.py: COVERAGE_DEBUG - Options for --debug. # 3) from environment variables: