todonotifier.driver

This module provides a sample driver method to setup and run TODO Notifier

 1"""This module provides a sample driver method to setup and run TODO Notifier
 2"""
 3
 4import logging
 5import os
 6import tempfile
 7from typing import TypeVar
 8
 9from todonotifier.config import BaseConfig, default_config
10from todonotifier.connect import Connect
11from todonotifier.todo_notifier import parse_files_for_todo_items
12from todonotifier.utils import generate_summary, get_files_in_dir, store_html
13
14P = TypeVar("P")
15
16# logging configuration
17logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(process)d - %(name)s - %(levelname)s - %(message)s")
18logger = logging.getLogger(__name__)
19
20
21class TODOException(Exception):
22    """Exception raised if any issue in `driver` module"""
23
24    pass
25
26
27def run(connect: Connect, config: BaseConfig = default_config) -> None:
28    """Main run method that would get triggered to generate summary and alerts
29
30    This method can be imported and run accordingly on demand or as a scheduled task etc.
31
32    Args:
33        connect (Connect): Object of type `Connect` to allow pulling the repository
34        config (BaseConfig, optional): Configuration to be used. Defaults to `default_config`
35    """
36    try:
37        with tempfile.TemporaryDirectory() as temp_dir:
38            project_dir_name = connect.project_dir_name
39            project_dir = os.path.join(temp_dir, project_dir_name)
40
41            # Pull the respective repository into a temporary directory
42            logger.info(f"Pulling the repository into temporary directory: {project_dir} using connect instance: {connect}")
43            connect.pull_repository(target_dir=project_dir)
44
45            all_files_in_project_dir = get_files_in_dir(
46                dir_path=project_dir, extension="py", exclude_subdirs=config.exclude_dirs, exclude_files=config.exclude_files
47            )
48
49            ignore_todo_case = config.ignore_todo_case
50            all_todos_items = parse_files_for_todo_items(temp_dir, all_files_in_project_dir, ignore_todo_case)
51
52            summary_generators = config.summary_generators
53
54        # Generate summaries
55        generate_summary(all_todos_items, summary_generators, config.generate_html)
56
57        # Store generated summaries
58        if config.generate_html and config.save_html_reports:
59            [store_html(summary_generator.html, summary_generator.name) for summary_generator in summary_generators]
60
61        if config.notifier:
62            config.notifier.notify([(summary_generator.name, summary_generator.html) for summary_generator in summary_generators])
63
64    except Exception:
65        logger.exception("Error in TODO application")
66        raise TODOException("Error in TODO application")
logger = <Logger todonotifier.driver (INFO)>
class TODOException(builtins.Exception):
22class TODOException(Exception):
23    """Exception raised if any issue in `driver` module"""
24
25    pass

Exception raised if any issue in driver module

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
add_note
args
def run( connect: todonotifier.connect.Connect, config: todonotifier.config.BaseConfig = <todonotifier.config.DefaultConfig object>) -> None:
28def run(connect: Connect, config: BaseConfig = default_config) -> None:
29    """Main run method that would get triggered to generate summary and alerts
30
31    This method can be imported and run accordingly on demand or as a scheduled task etc.
32
33    Args:
34        connect (Connect): Object of type `Connect` to allow pulling the repository
35        config (BaseConfig, optional): Configuration to be used. Defaults to `default_config`
36    """
37    try:
38        with tempfile.TemporaryDirectory() as temp_dir:
39            project_dir_name = connect.project_dir_name
40            project_dir = os.path.join(temp_dir, project_dir_name)
41
42            # Pull the respective repository into a temporary directory
43            logger.info(f"Pulling the repository into temporary directory: {project_dir} using connect instance: {connect}")
44            connect.pull_repository(target_dir=project_dir)
45
46            all_files_in_project_dir = get_files_in_dir(
47                dir_path=project_dir, extension="py", exclude_subdirs=config.exclude_dirs, exclude_files=config.exclude_files
48            )
49
50            ignore_todo_case = config.ignore_todo_case
51            all_todos_items = parse_files_for_todo_items(temp_dir, all_files_in_project_dir, ignore_todo_case)
52
53            summary_generators = config.summary_generators
54
55        # Generate summaries
56        generate_summary(all_todos_items, summary_generators, config.generate_html)
57
58        # Store generated summaries
59        if config.generate_html and config.save_html_reports:
60            [store_html(summary_generator.html, summary_generator.name) for summary_generator in summary_generators]
61
62        if config.notifier:
63            config.notifier.notify([(summary_generator.name, summary_generator.html) for summary_generator in summary_generators])
64
65    except Exception:
66        logger.exception("Error in TODO application")
67        raise TODOException("Error in TODO application")

Main run method that would get triggered to generate summary and alerts

This method can be imported and run accordingly on demand or as a scheduled task etc.

Arguments:
  • connect (Connect): Object of type Connect to allow pulling the repository
  • config (BaseConfig, optional): Configuration to be used. Defaults to default_config