Prospector is a tool to analyse Python code by aggregating the result of other tools.
—
Comprehensive configuration system that handles command-line arguments, profiles, tool settings, and environment detection. The ProspectorConfig class is the central configuration management system for Prospector.
Main configuration class that aggregates settings from command-line arguments, configuration files, and profiles.
class ProspectorConfig:
def __init__(self, workdir: Optional[Path] = None) -> NoneCreates a new configuration instance by processing command-line arguments and loading profiles.
Parameters:
workdir: Optional[Path] - Working directory for analysis (defaults to current directory)Properties:
paths: list[Path] - Paths to analyze (files or directories)workdir: Path - Working directory for the analysisprofile: ProspectorProfile - Active configuration profiletools_to_run: list[str] - List of tool names to executelibraries: list[str] - Detected/configured libraries (Django, Flask, etc.)messages: list[Message] - Configuration-related messages and warningsexplicit_file_mode: bool - True if analyzing specific files rather than directoriesignores: list[re.Pattern[str]] - Compiled regex patterns for ignoring files/pathsconfigured_by: dict[str, Optional[Union[str, Path]]] - Track how each tool was configureddef get_tools(self, found_files: FileFinder) -> list[tools.ToolBase]Creates and configures all enabled analysis tools.
Parameters:
found_files: FileFinder - File discovery object for tool configurationReturns:
list[tools.ToolBase] - List of configured and ready-to-run toolsSide Effects:
configured_by dictionary with tool configuration sourcesmessages listdef replace_deprecated_tool_names(self) -> list[str]Replaces deprecated tool names (pep8→pycodestyle, pep257→pydocstyle) with current names.
Returns:
list[str] - List of deprecated tool names that were found and replaceddef make_exclusion_filter(self) -> Callable[[Path], bool]Creates a filter function for excluding files and directories from analysis.
Returns:
Callable[[Path], bool] - Filter function that returns True if path should be excludedThe filter checks against:
def get_output_report(self) -> list[tuple[str, list[str]]]Gets the configured output format and target files.
Returns:
list[tuple[str, list[str]]] - List of (format_name, target_files) tuplesDefaults to ("grouped", []) if no specific format is configured.
def get_summary_information(self) -> dict[str, Any]Gets summary information about the configuration for reporting.
Returns:
dict[str, Any] - Dictionary containing:
libraries: list[str] - Detected librariesstrictness: Optional[str] - Strictness levelprofiles: str - Comma-separated profile namestools: list[str] - Tools to be rundef get_disabled_messages(self, tool_name: str) -> list[str]Gets list of message codes disabled for a specific tool.
Parameters:
tool_name: str - Name of the toolReturns:
list[str] - List of disabled message codesdef get_enabled_messages(self, tool_name: str) -> list[str]Gets list of message codes enabled for a specific tool.
Parameters:
tool_name: str - Name of the toolReturns:
list[str] - List of enabled message codesdef tool_options(self, tool_name: str) -> dict[str, Any]Gets tool-specific configuration options.
Parameters:
tool_name: str - Name of the toolReturns:
dict[str, Any] - Tool-specific options dictionarydef external_config_location(self, tool_name: str) -> Optional[Path]Gets the path to external configuration file for a tool.
Parameters:
tool_name: str - Name of the toolReturns:
Optional[Path] - Path to external config file, or None if not configureddef use_external_config(self, _: Any) -> boolDetermines whether to use external configuration files for tools.
Returns:
bool - True if external config should be useddef exit_with_zero_on_success(self) -> boolDetermines whether to exit with code 0 even when issues are found.
Returns:
bool - True if --zero-exit flag was providedThe ProspectorConfig class provides numerous boolean and scalar properties for accessing configuration settings:
@property
def die_on_tool_error(self) -> boolWhether to exit immediately if a tool encounters an error.
@property
def summary_only(self) -> boolWhether to output only summary information.
@property
def messages_only(self) -> boolWhether to output only messages (no summary).
@property
def quiet(self) -> boolWhether to suppress normal output.
@property
def blending(self) -> boolWhether to blend/deduplicate similar messages from different tools.
@property
def absolute_paths(self) -> boolWhether to use absolute paths in output.
@property
def max_line_length(self) -> intMaximum line length setting for tools that support it.
@property
def include_tool_stdout(self) -> boolWhether to include tool stdout/stderr in messages.
@property
def direct_tool_stdout(self) -> boolWhether to pass tool output directly to console.
@property
def show_profile(self) -> boolWhether to include profile information in output.
@property
def legacy_tool_names(self) -> boolWhether to use legacy tool names in output.
from prospector.config import ProspectorConfig
from pathlib import Path
# Default configuration using current directory
config = ProspectorConfig()
# Configuration with specific working directory
config = ProspectorConfig(workdir=Path("/path/to/project"))
# Access configuration properties
print(f"Tools to run: {config.tools_to_run}")
print(f"Libraries detected: {config.libraries}")
print(f"Blending enabled: {config.blending}")from prospector.config import ProspectorConfig
from prospector.finder import FileFinder
from pathlib import Path
config = ProspectorConfig()
# Discover files
paths = [Path(".")]
found_files = FileFinder(*paths, exclusion_filters=[config.make_exclusion_filter()])
# Get configured tools
tools = config.get_tools(found_files)
# Check how tools were configured
for tool_name, config_source in config.configured_by.items():
if config_source:
print(f"{tool_name} configured from: {config_source}")
else:
print(f"{tool_name} using default configuration")from prospector.config import ProspectorConfig
config = ProspectorConfig()
# Get tool options
pylint_options = config.tool_options("pylint")
print(f"Pylint options: {pylint_options}")
# Check disabled messages
disabled = config.get_disabled_messages("pylint")
print(f"Disabled pylint messages: {disabled}")
# Check if external config should be used
if config.use_external_config("pylint"):
external_config = config.external_config_location("pylint")
if external_config:
print(f"Using external pylint config: {external_config}")from prospector.config import ProspectorConfig
from pathlib import Path
config = ProspectorConfig()
# Create exclusion filter
exclusion_filter = config.make_exclusion_filter()
# Test paths
test_paths = [
Path("src/main.py"),
Path("migrations/0001_initial.py"),
Path("__pycache__/cache.py"),
Path(".git/config")
]
for path in test_paths:
if exclusion_filter(path):
print(f"Excluding: {path}")
else:
print(f"Including: {path}")Install with Tessl CLI
npx tessl i tessl/pypi-prospector