diff --git a/penify_hook/api_client.py b/penify_hook/api_client.py index 6c527eb..a3d71b9 100644 --- a/penify_hook/api_client.py +++ b/penify_hook/api_client.py @@ -5,33 +5,52 @@ class APIClient: def __init__(self, api_url, api_token: str = None, bearer_token: str = None): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ self.api_url = api_url self.AUTH_TOKEN = api_token self.BEARER_TOKEN = bearer_token def send_file_for_docstring_generation(self, file_name, content, line_numbers, repo_details = None): - """Send file content and modified lines to the API and return modified - content. - - This function constructs a payload containing the file path, content, - and modified line numbers, and sends it to a specified API endpoint for - processing. It handles the response from the API, returning the modified - content if the request is successful. If the request fails, it logs the - error details and returns the original content. - - Args: - file_name (str): The path to the file being sent. - content (str): The content of the file to be processed. - line_numbers (list): A list of line numbers that have been modified. - repo_details (str?): Additional repository details if applicable. Defaults to None. - - Returns: - str: The modified content returned by the API, or the original content if the - request fails. - - Raises: - Exception: If there is an error in processing the file and no specific error - message is provided. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ payload = { 'file_path': file_name, @@ -53,25 +72,26 @@ def send_file_for_docstring_generation(self, file_name, content, line_numbers, r raise Exception(f"API Error: {error_message}") def generate_commit_summary(self, git_diff, instruction: str = "", repo_details = None, jira_context: dict = None): - """Generate a commit summary by sending a POST request to the API endpoint. - - This function constructs a payload containing the git diff and any - additional instructions provided. It then sends this payload to a - specified API endpoint to generate a summary of the commit. If the - request is successful, it returns the response from the API; otherwise, - it returns None. - - Args: - git_diff (str): The git diff of the commit. - instruction (str??): Additional instruction for the commit. Defaults to "". - repo_details (dict??): Details of the git repository. Defaults to None. - jira_context (dict??): JIRA issue details to enhance the commit summary. Defaults to None. - - Returns: - dict: The response from the API if the request is successful, None otherwise. - - Raises: - Exception: If there is an error during the API request. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ payload = { 'git_diff': git_diff, @@ -100,18 +120,28 @@ def generate_commit_summary(self, git_diff, instruction: str = "", repo_details return None def get_supported_file_types(self) -> list[str]: - """Retrieve the supported file types from the API. - - This function sends a request to the API endpoint - `/v1/file/supported_languages` to obtain a list of supported file types. - If the API call is successful (status code 200), it parses the JSON - response and returns the list of supported file types. If the API call - fails, it returns a default list of common file types. - Returns: - list[str]: A list of supported file types, either from the API or a default set. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - url = self.api_url+"/v1/file/supported_languages" response = requests.get(url) if response.status_code == 200: @@ -121,20 +151,26 @@ def get_supported_file_types(self) -> list[str]: return ["py", "js", "ts", "java", "kt", "cs", "c"] def generate_commit_summary_with_llm(self, diff, message, generate_description: bool, repo_details, llm_client : LLMClient, jira_context=None): - """Generates a commit summary using a local LLM client. If an error occurs - during the generation process, - it falls back to using the API. - - Args: - diff (str): The Git diff of changes. - message (str): User-provided commit message or instructions. - generate_description (bool): Flag indicating whether to generate a description for the commit. - repo_details (dict): Details about the repository. - llm_client (LLMClient): An instance of LLMClient used to generate the summary. - jira_context (JIRAContext?): Optional JIRA issue context to enhance the summary. - - Returns: - dict: A dictionary containing the title and description for the commit. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ try: return llm_client.generate_commit_summary(diff, message, generate_description, repo_details, jira_context) @@ -144,17 +180,29 @@ def generate_commit_summary_with_llm(self, diff, message, generate_description: return self.generate_commit_summary(diff, message, repo_details, jira_context) def get_api_key(self): - """Fetch an API key from a specified URL. - This function sends a GET request to retrieve an API token using a - Bearer token in the headers. It handles the response and returns the API - key if the request is successful, or `None` otherwise. - Returns: - str: The API key if the request is successful, `None` otherwise. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - - url = self.api_url+"/v1/apiToken/get" response = requests.get(url, headers={"Authorization": f"Bearer {self.BEARER_TOKEN}"}, timeout=60*10) if response.status_code == 200: diff --git a/penify_hook/base_analyzer.py b/penify_hook/base_analyzer.py index f1cda81..55814fe 100644 --- a/penify_hook/base_analyzer.py +++ b/penify_hook/base_analyzer.py @@ -7,6 +7,27 @@ class BaseAnalyzer: def __init__(self, folder_path: str, api_client: APIClient): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ self.folder_path = folder_path self.repo_path = recursive_search_git_folder(folder_path) self.repo = None diff --git a/penify_hook/commands/commit_commands.py b/penify_hook/commands/commit_commands.py index a9d93f8..a60d9a0 100644 --- a/penify_hook/commands/commit_commands.py +++ b/penify_hook/commands/commit_commands.py @@ -8,29 +8,28 @@ def commit_code(api_url, token, message, open_terminal, generate_description, llm_model=None, llm_api_base=None, llm_api_key=None, jira_url=None, jira_user=None, jira_api_token=None): - """Enhance Git commits with AI-powered commit messages. - - This function allows for the generation of enhanced commit messages - using natural language processing models and optionally integrates with - JIRA for additional context. It processes the current Git folder to find - relevant files and generates a detailed commit message based on the - provided parameters. - - Args: - api_url (str): URL of the API endpoint. - token (str): Authentication token for the API. - message (str): Initial commit message provided by the user. - open_terminal (bool): Whether to open the terminal after committing. - generate_description (bool): Whether to generate a detailed description in the commit message. - llm_model (str?): The language model to use for generating the commit message. Defaults to - None. - llm_api_base (str?): Base URL of the LLM API. Defaults to None. - llm_api_key (str?): API key for accessing the LLM service. Defaults to None. - jira_url (str?): URL of the JIRA instance. Defaults to None. - jira_user (str?): Username for authenticating with JIRA. Defaults to None. - jira_api_token (str?): API token for accessing JIRA. Defaults to None. - """ + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ from penify_hook.ui_utils import print_error from penify_hook.utils import recursive_search_git_folder from ..commit_analyzer import CommitDocGenHook @@ -98,18 +97,28 @@ def commit_code(api_url, token, message, open_terminal, generate_description, def setup_commit_parser(parser): - """Generates a parser for setting up a command to generate smart commit - messages. - - This function sets up an argument parser that can be used to generate - commit messages with contextual information. It allows users to specify - options such as including a message, opening an edit terminal before - committing, and generating a detailed commit message. - Args: - parser (argparse.ArgumentParser): The ArgumentParser object to be configured. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - commit_parser_description = """ It generates smart commit messages. By default, it will just generate just the Title of the commit message. 1. If you have not configured LLM, it will give an error. You either need to configure LLM or use the API key. @@ -126,19 +135,28 @@ def setup_commit_parser(parser): parser.add_argument("-d", "--description", action="store_false", help="It will generate commit message with title and description.", default=False) def handle_commit(args): - """Handle the commit functionality by processing arguments and invoking the - appropriate commands. - - This function processes the provided command-line arguments to configure - settings for commit operations, including LLM (Language Model) and Jira - configurations. It then calls the `commit_code` function with these - configurations to perform the actual commit operation. - Args: - args (argparse.Namespace): The parsed command-line arguments containing options like terminal, - description, message, etc. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - from penify_hook.commands.commit_commands import commit_code from penify_hook.commands.config_commands import get_jira_config, get_llm_config, get_token from penify_hook.constants import API_URL diff --git a/penify_hook/commands/doc_commands.py b/penify_hook/commands/doc_commands.py index 5fb3273..b959438 100644 --- a/penify_hook/commands/doc_commands.py +++ b/penify_hook/commands/doc_commands.py @@ -4,22 +4,28 @@ import os def generate_doc(api_url, token, location=None): - """Generates documentation based on the given parameters. - This function initializes an API client using the provided API URL and - token. It then generates documentation by analyzing the specified - location, which can be a folder, a file, or the current working - directory if no location is provided. The function handles different - types of analysis based on the input location and reports any errors - encountered during the process. - - Args: - api_url (str): The URL of the API to connect to for documentation generation. - token (str): The authentication token for accessing the API. - location (str?): The path to a specific file or folder to analyze. If not provided, the - current working directory is used. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - import os import sys from ..folder_analyzer import FolderAnalyzerGenHook @@ -80,19 +86,29 @@ def generate_doc(api_url, token, location=None): """ def setup_docgen_parser(parser): - """Set up and configure a parser for documentation generation using Git - commands. - - This function configures a parser with various subcommands and arguments - necessary for generating documentation for Git diffs, files, or folders. - It also installs and uninstalls commit hooks to automate documentation - generation on commits. - - Args: - parser (argparse.ArgumentParser): The parser to configure. - """ # We don't need to create a new docgen_parser since it's passed as a parameter + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ docgen_parser_description = """ It generates Documentation for the Git diff, file or folder. 1. By default, it will git diff documentation - visit https://penify.wiki/dcdc for more details. @@ -122,19 +138,29 @@ def setup_docgen_parser(parser): default=os.getcwd()) def handle_docgen(args): - """Handle various subcommands related to document generation and hook - management. - - This function processes different subcommands such as installing or - uninstalling git hooks, and directly generating documentation based on - provided arguments. - - Args: - args (Namespace): Parsed command-line arguments containing the subcommand and location - details. - """ # Only import dependencies needed for docgen functionality here + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ from penify_hook.commands.config_commands import get_token import sys from penify_hook.commands.doc_commands import generate_doc diff --git a/penify_hook/commands/hook_commands.py b/penify_hook/commands/hook_commands.py index 1a49bfe..3f9cfd6 100644 --- a/penify_hook/commands/hook_commands.py +++ b/penify_hook/commands/hook_commands.py @@ -10,14 +10,26 @@ """ def install_git_hook(location, token): - """Install a post-commit hook in the specified location that generates - documentation - for changed files after each commit. - - Args: - location (str): The path to the Git repository where the hook should be installed. - token (str): The authentication token required to access the documentation generation - service. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ hooks_dir = Path(location) / ".git/hooks" hook_path = hooks_dir / HOOK_FILENAME @@ -34,15 +46,26 @@ def install_git_hook(location, token): print(f"Documentation will now be automatically generated after each commit.") def uninstall_git_hook(location): - """Uninstalls the post-commit hook from the specified location. - - This function attempts to remove a post-commit git hook located at the - given path. It constructs the path to the hook and checks if it exists. - If the hook is found, it is deleted, and a confirmation message is - printed. If no hook is found, a message indicating this is also printed. - - Args: - location (Path): The base directory where the .git/hooks directory is located. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ hook_path = Path(location) / ".git/hooks" / HOOK_FILENAME diff --git a/penify_hook/commit_analyzer.py b/penify_hook/commit_analyzer.py index 31ab46b..d6c3220 100644 --- a/penify_hook/commit_analyzer.py +++ b/penify_hook/commit_analyzer.py @@ -13,34 +13,53 @@ class CommitDocGenHook(BaseAnalyzer): def __init__(self, repo_path: str, api_client: APIClient, llm_client=None, jira_client=None): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ super().__init__(repo_path, api_client) self.llm_client = llm_client # Add LLM client as an optional parameter self.jira_client: JiraClient = jira_client # Add JIRA client as an optional parameter def get_summary(self, instruction: str, generate_description: bool) -> dict: - """Generate a summary for the commit based on the staged changes. - - This function retrieves the differences of the staged changes in the - repository and generates a commit summary using the provided - instruction. If there are no changes staged for commit, an exception is - raised. If a JIRA client is connected, it will attempt to extract issue - keys from the current branch and use them to fetch context. The summary - can be generated either with a Language Model (LLM) client or through - the API client. - - Args: - instruction (str): A string containing instructions for generating the commit summary. - generate_description (bool): Whether to include detailed descriptions in the summary. - - Returns: - dict: The generated commit summary based on the staged changes, provided - instruction, and any relevant JIRA context. The dictionary contains keys - such as 'summary', 'description', etc., depending on whether a - description was requested. - - Raises: - ValueError: If there are no changes staged for commit. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ diff = self.repo.git.diff('--cached') if not diff: @@ -71,22 +90,26 @@ def get_summary(self, instruction: str, generate_description: bool) -> dict: def run(self, msg: Optional[str], edit_commit_message: bool, generate_description: bool): - """Run the post-commit hook. - - This method processes the modified files from the last commit, stages - them, and creates an auto-commit with an optional message. It also - handles JIRA integration if available. If there is an error generating - the commit summary, an exception is raised. - - Args: - msg (Optional[str]): An optional message to include in the commit. - edit_commit_message (bool): A flag indicating whether to open the git commit edit terminal after - committing. - generate_description (bool): A flag indicating whether to include a description in the commit - message. - - Raises: - Exception: If there is an error generating the commit summary. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ summary: dict = self.get_summary(msg, True) if not summary: @@ -111,18 +134,28 @@ def run(self, msg: Optional[str], edit_commit_message: bool, generate_descriptio self._amend_commit() def process_jira_integration(self, title: str, description: str, msg: str) -> tuple: - """Process JIRA integration for the commit message. - - Args: - title (str): Generated commit title. - description (str): Generated commit description. - msg (str): Original user message that might contain JIRA references. - - Returns: - tuple: A tuple containing the updated commit title and description with - included JIRA information. - """ # Look for JIRA issue keys in commit message, title, description and user message + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ issue_keys = [] if self.jira_client: # Extract from message content @@ -160,12 +193,26 @@ def process_jira_integration(self, title: str, description: str, msg: str) -> tu return title, description def _amend_commit(self): - """Open the default git editor for editing the commit message. - - This function changes the current working directory to the repository - path, runs the git command to amend the last commit, and opens the - default editor for the user to modify the commit message. After the - operation, it returns to the original directory. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ try: # Change to the repository directory diff --git a/penify_hook/config_command.py b/penify_hook/config_command.py index 1d9a6ab..8e7301f 100644 --- a/penify_hook/config_command.py +++ b/penify_hook/config_command.py @@ -2,19 +2,29 @@ def setup_config_parser(parent_parser): - """Set up a configuration parser with subparsers for different types of - configurations. - - This function configures and adds subcommands to the parent parser. Each - subcommand corresponds to a specific type of configuration, such as LLM - (Language Model) or JIRA. It allows users to configure settings for - these systems through command-line arguments. - - Args: - parent_parser (argparse.ArgumentParser): The parent parser to which the config subparsers will be added. - """ # Config subcommand: Create subparsers for config types + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ parser = parent_parser.add_subparsers(title="config_type", dest="config_type") # Config subcommand: llm @@ -39,20 +49,29 @@ def setup_config_parser(parent_parser): # Add all other necessary arguments for config command def handle_config(args): - """Handle configuration settings based on the specified config type. - - This function processes different types of configurations such as LLM - (Language Model) and JIRA. It saves configurations, sets up web-based - configurations, and verifies JIRA connections. - - Args: - args (argparse.Namespace): Command-line arguments containing the type of configuration to handle. - - Returns: - int: Exit code indicating success or failure. - """ # Only import dependencies needed for config functionality here + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ from penify_hook.commands.config_commands import save_llm_config from penify_hook.jira_client import JiraClient # Import moved here from penify_hook.commands.config_commands import config_jira_web, config_llm_web, save_jira_config diff --git a/penify_hook/file_analyzer.py b/penify_hook/file_analyzer.py index c161afc..76689da 100644 --- a/penify_hook/file_analyzer.py +++ b/penify_hook/file_analyzer.py @@ -19,26 +19,53 @@ class FileAnalyzerGenHook(BaseAnalyzer): def __init__(self, file_path: str, api_client: APIClient): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ self.file_path = file_path super().__init__(file_path, api_client) def process_file(self, file_path, pbar): - """Process a file by reading its content and sending it to an API for - processing. - - This function validates the provided file extension, reads the content - of the file, and sends it to an API client for further processing. If - the API responds successfully, the original file content is replaced - with the response. - - Args: - file_path (str): The relative path to the file that needs to be processed. - pbar (tqdm): Progress bar to update during processing. - - Returns: - bool: True if the file was processed successfully, False otherwise. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ file_abs_path = os.path.join(os.getcwd(), file_path) file_extension = os.path.splitext(file_path)[1].lower() @@ -103,29 +130,54 @@ def process_file(self, file_path, pbar): return False def print_processing(self, file_path): - """Print a processing message for a file. - - Args: - file_path (str): The path to the file being processed. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ formatted_path = format_file_path(file_path) print(f"\n{format_highlight(f'Processing file: {formatted_path}')}") def run(self): - """Run the post-commit hook. - - This method executes the post-commit hook by processing a specified - file. It attempts to process the file located at `self.file_path`. If an - error occurs during the processing, it catches the exception and prints - an error message indicating that the file was not processed. The method - displays a progress bar and colored output to provide visual feedback on - the processing status. - - Args: - self (PostCommitHook): An instance of the PostCommitHook class. - """ # Create a progress bar with appropriate stages + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ stages = ["Validating", "Reading content", "Documenting", "Writing changes", "Completed"] pbar, _ = create_stage_progress_bar(stages, f"Starting documenting") diff --git a/penify_hook/folder_analyzer.py b/penify_hook/folder_analyzer.py index 15ec20f..cf56fa0 100644 --- a/penify_hook/folder_analyzer.py +++ b/penify_hook/folder_analyzer.py @@ -8,26 +8,53 @@ class FolderAnalyzerGenHook(BaseAnalyzer): def __init__(self, dir_path: str, api_client: APIClient): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ self.dir_path = dir_path super().__init__(dir_path, api_client) def list_all_files_in_dir(self, dir_path: str): - """List all non-hidden files in a directory and its subdirectories. - - This function recursively traverses the specified directory and its - subdirectories, collecting paths of all non-hidden files. It filters out - hidden directories and files (those starting with a dot) to ensure only - visible files are returned. - Args: - dir_path (str): The path to the directory whose files and subdirectory files need to be - listed. - - Returns: - list: A list containing the full paths of all non-hidden files within the - specified directory and its subdirectories. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - files = [] for dirpath, dirnames, filenames in os.walk(dir_path): dirnames[:] = [d for d in dirnames if not d.startswith(".")] @@ -38,16 +65,26 @@ def list_all_files_in_dir(self, dir_path: str): return files def run(self): - """Run the post-commit hook. - - This function processes all files in a specified directory using a - progress bar. It lists all files, initializes a `FileAnalyzerGenHook` - for each file, and runs it. Errors during processing of individual files - are caught and logged, but do not stop the processing of other files. A - progress bar is displayed indicating the number of files processed. - - Args: - self (PostCommitHook): The instance of the post-commit hook class. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ try: file_list = self.list_all_files_in_dir(self.dir_path) diff --git a/penify_hook/git_analyzer.py b/penify_hook/git_analyzer.py index f9e7127..2f7ebe0 100644 --- a/penify_hook/git_analyzer.py +++ b/penify_hook/git_analyzer.py @@ -18,19 +18,50 @@ class GitDocGenHook(BaseAnalyzer): def __init__(self, repo_path: str, api_client: APIClient): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ super().__init__(repo_path, api_client) def get_modified_files_in_last_commit(self): - """Get the list of files modified in the last commit. - - This function retrieves the files that were modified in the most recent - commit of the repository. It accesses the last commit and iterates - through the differences to compile a list of unique file paths that were - changed. The function returns this list for further processing or - analysis. - - Returns: - list: A list of file paths that were modified in the last commit. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ last_commit = self.repo.head.commit modified_files = [] @@ -40,19 +71,26 @@ def get_modified_files_in_last_commit(self): return modified_files def get_modified_lines(self, diff_text): - """Extract modified line numbers from a diff text. - - This function processes a diff text to identify and extract the line - numbers that have been modified. It distinguishes between added and - deleted lines and keeps track of the current line number as it parses - through the diff. The function handles hunk headers and ensures that any - deletions at the end of the file are also captured. - - Args: - diff_text (str): A string containing the diff text to be processed. - - Returns: - list: A sorted list of unique line numbers that have been modified. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ modified_lines = [] current_line = 0 @@ -89,23 +127,26 @@ def get_modified_lines(self, diff_text): return sorted(set(modified_lines)) # Remove duplicates and sort def process_file(self, file_path): - """Process a file by checking its type, reading its content, and sending it - to an API. - - This method constructs the absolute path of the specified file and - verifies if the file has a valid extension. If the file type is - supported, it reads the content of the file and retrieves the - differences from the last commit in the repository. If changes are - detected, it sends the file content along with the modified lines to an - API for further processing. If the API response indicates no changes, - the original file will not be overwritten. - - Args: - file_path (str): The relative path to the file to be processed. - - Returns: - bool: True if the file was successfully processed and updated, False - otherwise. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ file_abs_path = os.path.join(self.repo_path, file_path) file_extension = os.path.splitext(file_path)[1].lower() @@ -150,16 +191,26 @@ def process_file(self, file_path): return True def run(self): - """Run the post-commit hook. - - This method retrieves the list of modified files from the last commit - and processes each file. It stages any files that have been modified - during processing and creates an auto-commit if changes were made. A - progress bar is displayed to indicate the processing status of each - file. The method handles any exceptions that occur during file - processing, printing an error message for each file that fails to - process. If any modifications are made to the files, an auto-commit is - created to save those changes. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ logger.info("Starting doc_gen_hook processing") print_info("Starting doc_gen_hook processing") diff --git a/penify_hook/jira_client.py b/penify_hook/jira_client.py index 56d2e22..a863aa6 100644 --- a/penify_hook/jira_client.py +++ b/penify_hook/jira_client.py @@ -15,13 +15,26 @@ class JiraClient: """ def __init__(self, jira_url: str = None, jira_user: str = None, jira_api_token: str = None): - """ - Initialize the JIRA client. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. - Args: - jira_url: Base URL for JIRA instance (e.g., "https://your-domain.atlassian.net") - jira_user: JIRA username or email - jira_api_token: JIRA API token + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ self.jira_url = jira_url self.jira_user = jira_user @@ -44,37 +57,52 @@ def __init__(self, jira_url: str = None, jira_user: str = None, jira_api_token: self.jira_client = None def is_connected(self) -> bool: - """Check if the JIRA client is connected. - - This function verifies whether the JIRA client has successfully - established a connection. It returns `True` if the client is connected, - and `False` otherwise. - - Returns: - bool: True if the JIRA client is connected, False otherwise + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return self.jira_client is not None def extract_issue_keys_from_branch(self, branch_name: str) -> List[str]: - """Extracts JIRA issue keys from a branch name. - - This function searches through a given git branch name to find and - return any JIRA issue keys that match the pattern. Common conventions - for JIRA issue keys in branch names include: - - feature/PROJECT-123-description - bugfix/PROJECT-123-fix-something - - hotfix/PROJECT-123/short-desc - - Args: - branch_name (str): The name of the git branch to search for JIRA issue keys. - - Returns: - List[str]: A list of unique JIRA issue keys found in the branch name. - - Examples: - extract_issue_keys_from_branch("feature/PROJ-456-add-new-feature") - # Output: ['PROJ-456'] - """ # Common JIRA issue key pattern: PROJECT-123 + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ pattern = r'[A-Z][A-Z0-9_]+-[0-9]+' matches = re.findall(pattern, branch_name) if matches: @@ -82,44 +110,53 @@ def extract_issue_keys_from_branch(self, branch_name: str) -> List[str]: return list(set(matches)) # Remove duplicates def extract_issue_keys(self, text: str) -> List[str]: - """Extract JIRA issue keys from a given text. - - This function searches through the provided text to find and return all - unique JIRA issue keys. A JIRA issue key typically follows the pattern - of PROJECT-123, where PROJECT is alphanumeric and consists of at least - one uppercase letter followed by one or more alphanumeric characters, - and 123 is a numeric sequence. - - Args: - text (str): The text in which to search for JIRA issue keys. - - Returns: - List[str]: A list of unique JIRA issue keys found in the text. - """ # Common JIRA issue key pattern: PROJECT-123 + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ pattern = r'[A-Z][A-Z0-9_]+-[0-9]+' matches = re.findall(pattern, text) return list(set(matches)) # Remove duplicates def get_issue_details(self, issue_key: str) -> Optional[Dict[str, Any]]: - """Retrieve details of a JIRA issue based on its key. - - This function fetches detailed information about a specified JIRA issue - using the provided issue key. It checks if the JIRA client is connected - before attempting to retrieve the issue. If the client is not connected, - it logs a warning and returns `None`. The function then attempts to - fetch the issue from the JIRA server and constructs a dictionary - containing various details about the issue such as its key, summary, - status, description, assignee, reporter, type, priority, and URL. If any - errors occur during this process, they are logged, and `None` is - returned. - - Args: - issue_key (str): The JIRA issue key (e.g., "PROJECT-123"). - - Returns: - Dict[str, Any] or None: A dictionary containing the details of the JIRA - issue if found, otherwise `None`. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not self.is_connected(): logging.warning("JIRA client not connected") @@ -143,14 +180,26 @@ def get_issue_details(self, issue_key: str) -> Optional[Dict[str, Any]]: return None def add_comment(self, issue_key: str, comment: str) -> bool: - """Add a comment to a JIRA issue. - - Args: - issue_key (str): JIRA issue key (e.g., "PROJECT-123") - comment (str): Comment text to add - - Returns: - bool: True if the comment was added successfully, False otherwise + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not self.is_connected(): logging.warning("JIRA client not connected") @@ -165,14 +214,26 @@ def add_comment(self, issue_key: str, comment: str) -> bool: return False def update_issue_status(self, issue_key: str, transition_name: str) -> bool: - """Update the status of a JIRA issue. - - Args: - issue_key (str): The key of the JIRA issue to be updated. - transition_name (str): The name of the desired transition. - - Returns: - bool: True if the status was successfully updated, False otherwise. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not self.is_connected(): logging.warning("JIRA client not connected") @@ -202,20 +263,28 @@ def update_issue_status(self, issue_key: str, transition_name: str) -> bool: return False def format_commit_message_with_jira_info(self, commit_title: str, commit_description: str, issue_keys: List[str] = None) -> tuple: - """Format commit message with JIRA issue information. - - Args: - commit_title (str): The original commit title. - commit_description (str): The original commit description. - issue_keys (List[str]?): A list of JIRA issue keys to include in the commit message. If not - provided, issue keys will be extracted from both the title and the - description. - - Returns: - tuple: A tuple containing the updated commit title and description with JIRA - information included. - """ # If no issue keys provided, extract them from title and description + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ if not issue_keys: title_keys = self.extract_issue_keys(commit_title) desc_keys = self.extract_issue_keys(commit_description) @@ -252,21 +321,26 @@ def format_commit_message_with_jira_info(self, commit_title: str, commit_descrip return updated_title, updated_description def get_detailed_issue_context(self, issue_key: str) -> Dict[str, Any]: - """Retrieve comprehensive details about a JIRA issue including context for - better commit messages. - - This function fetches detailed information from a specified JIRA issue - and constructs a dictionary containing various context fields such as - the issue summary, description, type, status, priority, comments, URL, - and additional custom fields like acceptance criteria and sprint - information. If any errors occur during the fetching process, - appropriate warnings or errors are logged. - - Args: - issue_key (str): The JIRA issue key (e.g., "PROJECT-123"). - - Returns: - Dict[str, Any]: A dictionary containing business and technical context from the issue. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not self.is_connected(): logging.warning("JIRA client not connected") @@ -336,21 +410,26 @@ def get_detailed_issue_context(self, issue_key: str) -> Dict[str, Any]: return {} def get_commit_context_from_issues(self, issue_keys: List[str]) -> Dict[str, Any]: - """Gather contextual information from JIRA issues to improve commit - messages. - - This function processes a list of JIRA issue keys, retrieves detailed - context for each issue, and aggregates it into a dictionary that can be - used to enhance commit messages. It first retrieves the primary issue - (the first key in the list) and then gathers basic details for any - related issues. The resulting context includes information from both the - primary and related issues, along with all issue keys. - - Args: - issue_keys: List of JIRA issue keys to gather information from - - Returns: - Dict containing business and technical context from the issues + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not issue_keys or not self.is_connected(): return {} @@ -375,17 +454,26 @@ def get_commit_context_from_issues(self, issue_keys: List[str]) -> Dict[str, Any return context def enhance_commit_message(self, title: str, description: str, issue_keys: List[str]) -> tuple: - """Enhance a commit message with business and technical context from JIRA - issues. - - Args: - title (str): Original commit title. - description (str): Original commit description. - issue_keys (List[str]): List of JIRA issue keys to include in the enhanced commit message. - - Returns: - tuple: A tuple containing the enhanced commit title and description with added - context from JIRA issues. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not issue_keys or not self.is_connected(): return title, description diff --git a/penify_hook/llm_client.py b/penify_hook/llm_client.py index e5fe2b2..8f7e7fa 100644 --- a/penify_hook/llm_client.py +++ b/penify_hook/llm_client.py @@ -10,15 +10,28 @@ class LLMClient: """ def __init__(self, model: str = None, api_base: str = None, api_key: str = None): - """ - Initialize the LLM client. - - Args: - model: LLM model to use (e.g., "gpt-4", "ollama/llama2", etc.) - api_base: Base URL for API requests (e.g., "http://localhost:11434" for Ollama) - api_key: API key for the LLM service - """ # Configure litellm if parameters are provided + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ self.model = model if api_base: os.environ["OPENAI_API_BASE"] = api_base @@ -26,30 +39,26 @@ def __init__(self, model: str = None, api_base: str = None, api_key: str = None) os.environ["OPENAI_API_KEY"] = api_key def generate_commit_summary(self, diff: str, message: str, generate_description: bool, repo_details: Dict, jira_context: Dict = None) -> Dict: - """Generate a commit summary using the LLM. - - This function generates a concise and descriptive commit summary based - on the provided Git diff, user instructions, repository details, and - optional JIRA context. It constructs a prompt for the LLM to produce a - commit title and an optional detailed description, adhering to Semantic - Commit Messages guidelines. If the JIRA context is provided, it enriches - the prompt with relevant issue information. - - Args: - diff (str): Git diff of changes. - message (str): User-provided commit message or instructions. - generate_description (bool): Flag indicating whether to include a detailed description in the - summary. - repo_details (Dict): Details about the repository. - jira_context (Dict?): Optional JIRA issue context to enhance the summary. - - Returns: - Dict: A dictionary containing the title and description for the commit. If - generate_description is False, - the 'description' key may be absent. - - Raises: - ValueError: If the LLM model is not configured. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if not self.model: raise ValueError("LLM model not configured. Please provide a model when initializing LLMClient.") diff --git a/penify_hook/login_command.py b/penify_hook/login_command.py index 2d97cc3..d9874a5 100644 --- a/penify_hook/login_command.py +++ b/penify_hook/login_command.py @@ -1,22 +1,51 @@ def setup_login_parser(parser): + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ parser.add_argument("--token", help="Specify API token directly") # Add all other necessary arguments for login command def handle_login(args): - """Handle the login command. - - Initiates a user login process by calling the `login` function from the - `penify_hook.commands.auth_commands` module using predefined constants - `API_URL` and `DASHBOARD_URL` from the `penify_hook.constants` module. - Args: - args (argparse.Namespace): Parsed arguments containing necessary parameters for the login command. - - Returns: - None: This function does not return any value; it is expected to handle the - login process internally. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - from penify_hook.constants import API_URL, DASHBOARD_URL from penify_hook.commands.auth_commands import login diff --git a/penify_hook/main.py b/penify_hook/main.py index 2f4312f..c8e7b7c 100644 --- a/penify_hook/main.py +++ b/penify_hook/main.py @@ -4,19 +4,28 @@ def main(): - """Main function to handle command-line interface (CLI) interactions with - Penify services. - This tool provides a command-line interface for generating smart commit - messages, configuring local-LLM and JIRA, and generating code - documentation. It supports basic commands that do not require login and - advanced commands that require user authentication. The `--version` flag - can be used to display the version information. - - Returns: - int: Exit status of the program (0 for success, 1 for error). + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ - parser = argparse.ArgumentParser( description="""Penify CLI tool for: 1. AI commit message generation with JIRA integration to enhance commit messages. diff --git a/penify_hook/ui_utils.py b/penify_hook/ui_utils.py index 5fce269..6bb2d8d 100644 --- a/penify_hook/ui_utils.py +++ b/penify_hook/ui_utils.py @@ -26,157 +26,291 @@ PROCESSING_SYMBOL = "⟳" def format_info(message): - """Format an informational message with appropriate color. - - Args: - message (str): The text of the informational message to be formatted. - - Returns: - str: The formatted informational message with the specified color. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{INFO_COLOR}{message}{Style.RESET_ALL}" def format_success(message): - """Format a success message with appropriate color. - - This function takes a message as input and wraps it in ANSI escape codes - to display it in green, indicating a successful operation. The - Style.RESET_ALL is applied at the end to ensure that any subsequent text - is displayed in the default style. - - Args: - message (str): The message to be formatted as a success message. - - Returns: - str: The formatted success message with green color and reset style. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{SUCCESS_COLOR}{message}{Style.RESET_ALL}" def format_warning(message): - """Format a warning message with appropriate color. - - Args: - message (str): The warning message to be formatted. - - Returns: - str: The formatted warning message with the specified color. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{WARNING_COLOR}{message}{Style.RESET_ALL}" def format_error(message): - """Format an error message with appropriate color. - - This function takes a plain error message and wraps it in ANSI escape - codes to apply the specified error color, ensuring that the error - message is visually distinct when output. The function supports various - error colors defined by constants like `ERROR_COLOR`. - - Args: - message (str): The plain text error message to be formatted. - - Returns: - str: The formatted error message with the error color applied. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{ERROR_COLOR}{message}{Style.RESET_ALL}" def format_highlight(message): - """Format a highlighted message with appropriate color. - - Args: - message (str): The message to be formatted and highlighted. - - Returns: - str: The formatted message with applied highlight style. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{HIGHLIGHT_COLOR}{message}{Style.RESET_ALL}" def format_file_path(file_path): - """Format a file path with appropriate color. - - This function takes a file path as input and wraps it in ANSI escape - codes to apply a warning color. The original file path is then reset to - default style using Style.RESET_ALL. - - Args: - file_path (str): The file path to be formatted. - - Returns: - str: The formatted file path with the warning color applied. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return f"{WARNING_COLOR}{file_path}{Style.RESET_ALL}" def print_info(message): - """Print an informational message with appropriate formatting. - - This function takes a string message as input and prints it in a - formatted manner. It utilizes the `format_info` function to apply any - necessary formatting before printing. - - Args: - message (str): The message to be printed. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ print(format_info(message)) def print_success(message): - """Print a formatted success message. - - This function takes a string `message` and prints it as a formatted - success message. The formatting includes adding a prefix "Success: " to - the message and enclosing it within asterisks for emphasis. - - Args: - message (str): The message to be printed as a success message. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ print(format_success(message)) def print_warning(message): - """Print a warning message with appropriate formatting. - - This function takes a warning message as input and prints it with - formatted output. The formatting may include color, timestamp, or other - styles to emphasize that it is a warning. - - Args: - message (str): The warning message to be printed. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ print(format_warning(message)) def print_error(message): - """Print an error message with appropriate formatting. - - This function takes a string message, formats it as an error message, - and then prints it. The formatting typically includes prefixing the - message with "Error: " to clearly indicate that it is an error. - - Args: - message (str): The error message to be printed. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ print(format_error(message)) def print_processing(file_path): - """Print a processing message for a specified file. - - This function takes a file path, formats it using `format_file_path`, - and then prints a formatted message indicating that the file is being - processed. The formatted path is highlighted using `format_highlight`. - - Args: - file_path (str): The path of the file to be processed. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ formatted_path = format_file_path(file_path) print(f"\n{format_highlight(f'Processing file: {formatted_path}')}") def print_status(status, message): - """Print a status message with an appropriate symbol. - - This function takes a status and a message, then prints them with a - colored symbol that corresponds to the given status. The available - statuses are 'success', 'warning', 'error', and any other value will - default to a processing indicator. - - Args: - status (str): The status type ('success', 'warning', 'error') or another string. - message (str): The message to be displayed along with the symbol. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ if status == 'success': print(f" {SUCCESS_COLOR}{SUCCESS_SYMBOL} {message}{Style.RESET_ALL}") @@ -188,15 +322,26 @@ def print_status(status, message): print(f" {PROCESSING_SYMBOL} {message}") def create_progress_bar(total, desc="Processing", unit="item"): - """Create a tqdm progress bar with consistent styling. - - Args: - total (int): Total number of items to process. - desc (str): Description for the progress bar. Defaults to "Processing". - unit (str): Unit label for the progress items. Defaults to "item". - - Returns: - tqdm: A configured tqdm progress bar instance. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ return tqdm( total=total, @@ -207,19 +352,26 @@ def create_progress_bar(total, desc="Processing", unit="item"): ) def create_stage_progress_bar(stages, desc="Processing"): - """Create a tqdm progress bar for processing stages with consistent - styling. - - This function initializes and returns a tqdm progress bar object for - tracking the progress through a series of stages. It also provides a - description for the progress bar to enhance its usability. - - Args: - stages (list): A list of strings representing individual stages in the process. - desc (str?): A description for the progress bar. Defaults to "Processing". - - Returns: - tuple: A tuple containing the tqdm progress bar object and the list of stages. + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } """ pbar = tqdm( total=len(stages), @@ -231,18 +383,28 @@ def create_stage_progress_bar(stages, desc="Processing"): return pbar, stages def update_stage(pbar, stage_name): - """Update the progress bar with a new stage name. - - This function updates the provided tqdm progress bar to reflect the - current stage of a process. It clears any existing postfix and sets a - new description based on the provided stage name. The display is then - refreshed to ensure that the update is visible immediately. - - Args: - pbar (tqdm): The progress bar object to be updated. - stage_name (str): A string representing the current stage of the process. - """ # Force refresh with a custom description and ensure it's visible + """Save the processed files map to a JSON file. + + Function parameters should be documented in the ``Args`` section. The name of each parameter is required. The type and + description of each parameter is optional, but should be included if not obvious. + + @type dictionary: dict + @param dictionary: The processed files map. + @rtype: bool + @return: True if successful, False otherwise. + @return: The return type is optional and may be specified at the beginning of + @return: the ``Returns`` section followed by a colon. + @return: The ``Returns`` section may span multiple lines and paragraphs. + @return: Following lines should be indented to match the first line. + @return: The ``Returns`` section supports any reStructuredText formatting, + @return: including literal blocks:: + + { + 'param1': param1, + 'param2': param2 + } + """ pbar.set_postfix_str("") # Clear any existing postfix pbar.set_description_str(f"{format_info(stage_name)}") pbar.refresh() # Force refresh the display