Interrogate a codebase for docstring coverage.
—
Configuration management for interrogate supporting multiple configuration sources including command-line arguments, pyproject.toml, and setup.cfg files. Provides unified configuration interface with validation and sensible defaults.
Main configuration object that holds all interrogate settings and options.
class InterrogateConfig:
"""Configuration object for interrogate analysis."""
# Class constants
VALID_STYLES: Tuple[str, ...] = ("sphinx", "google")
# Attributes (using attr.s decorator)
color: bool = False # Enable colored output
docstring_style: str = "sphinx" # Docstring style validation
fail_under: float = 80.0 # Coverage threshold
ignore_regex: bool = False # Regex patterns to ignore
ignore_magic: bool = False # Ignore magic methods
ignore_module: bool = False # Ignore module docstrings
ignore_private: bool = False # Ignore private methods
ignore_semiprivate: bool = False # Ignore semiprivate methods
ignore_init_method: bool = False # Ignore __init__ methods
ignore_init_module: bool = False # Ignore __init__.py modules
ignore_nested_classes: bool = False # Ignore nested classes
ignore_nested_functions: bool = False # Ignore nested functions
ignore_property_setters: bool = False # Ignore property setters
ignore_property_decorators: bool = False # Ignore property decorators
ignore_overloaded_functions: bool = False # Ignore @overload functions
include_regex: bool = False # Regex patterns to include
omit_covered_files: bool = False # Omit 100% covered filesFunctions for finding and loading configuration from project files.
def find_project_root(srcs):
"""
Find the project root directory.
Args:
srcs: Source paths to analyze
Returns:
pathlib.Path: Path to project root directory
"""
def find_project_config(path_search_start):
"""
Find project configuration file (pyproject.toml or setup.cfg).
Args:
path_search_start: Directory to start searching from
Returns:
str or None: Path to configuration file, or None if not found
"""Functions for parsing configuration from different file formats.
def parse_pyproject_toml(path_config):
"""
Parse interrogate configuration from pyproject.toml file.
Args:
path_config: Path to pyproject.toml file
Returns:
dict: Configuration values from [tool.interrogate] section
Raises:
FileNotFoundError: If configuration file doesn't exist
tomli.TOMLDecodeError: If TOML file is malformed
"""
def parse_setup_cfg(path_config):
"""
Parse interrogate configuration from setup.cfg file.
Args:
path_config: Path to setup.cfg file
Returns:
dict: Configuration values from [tool:interrogate] section
Raises:
FileNotFoundError: If configuration file doesn't exist
configparser.Error: If configuration file is malformed
"""
def sanitize_list_values(value):
"""
Sanitize configuration list values from strings or lists.
Args:
value: String (comma/space separated) or list of strings
Returns:
list: Cleaned list of values
"""Function for integrating configuration file loading with Click CLI framework.
def read_config_file(ctx, param, value):
"""
Click callback for reading configuration file.
Args:
ctx: Click context
param: Click parameter
value: Configuration file path
Returns:
str: Configuration file path
Raises:
click.BadParameter: If configuration file is invalid
"""from interrogate.config import InterrogateConfig
# Basic configuration
config = InterrogateConfig(
paths=["src/", "tests/"],
fail_under=80.0,
ignore_private=True
)
# Advanced configuration
config = InterrogateConfig(
paths=["src/myproject"],
color=True,
exclude=["migrations", "tests/fixtures"],
ignore_init_method=True,
ignore_magic=True,
ignore_regex=["test_.*", ".*_test"],
fail_under=85.0,
verbose=1,
generate_badge="docs/badge.svg",
badge_style="flat-square"
)from interrogate.config import find_project_config, parse_pyproject_toml
# Find configuration file
config_path = find_project_config(".")
if config_path:
print(f"Found configuration: {config_path}")
# Parse configuration
if config_path.endswith("pyproject.toml"):
config_dict = parse_pyproject_toml(config_path)
print(f"Configuration options: {config_dict}")[tool.interrogate]
ignore-init-method = true
ignore-init-module = true
ignore-magic = true
ignore-nested-functions = true
ignore-private = true
ignore-semiprivate = true
fail-under = 85
exclude = ["tests", "docs", "build"]
ignore-regex = ["^get$", "^post$", "^put$"]
verbose = 1
quiet = 0
whitelist-regex = []
color = true
omit-covered-files = false
generate-badge = "."
badge-format = "svg"
badge-style = "flat"[tool:interrogate]
ignore-init-method = true
ignore-init-module = true
ignore-magic = true
ignore-nested-functions = true
ignore-private = true
ignore-semiprivate = true
fail-under = 85
exclude = tests,docs,build
ignore-regex = ^get$,^post$,^put$
verbose = 1
quiet = 0
color = true
omit-covered-files = false
generate-badge = .
badge-format = svg
badge-style = flatfrom interrogate.config import InterrogateConfig
# Configure regex patterns to ignore
config = InterrogateConfig(
paths=["src/"],
# Ignore test methods, getters, setters
ignore_regex=[
r"test_.*", # Test methods
r"get_.*", # Getter methods
r"set_.*", # Setter methods
r".*_callback$", # Callback functions
r"__.*__" # Magic methods (alternative to ignore_magic)
]
)from interrogate.config import InterrogateConfig, find_project_config, parse_pyproject_toml
def create_config_with_overrides(paths, **overrides):
"""Create configuration with file-based defaults and overrides."""
# Start with defaults
config_kwargs = {
"paths": paths,
"color": True,
"fail_under": 80.0
}
# Load from configuration file if available
config_file = find_project_config(".")
if config_file and config_file.endswith("pyproject.toml"):
file_config = parse_pyproject_toml(config_file)
config_kwargs.update(file_config)
# Apply overrides
config_kwargs.update(overrides)
return InterrogateConfig(**config_kwargs)
# Usage
config = create_config_with_overrides(
paths=["src/"],
verbose=2, # Override verbose level
fail_under=90.0 # Override threshold
)Install with Tessl CLI
npx tessl i tessl/pypi-interrogate