Skip to content

This Python project is a comprehensive toolkit for analyzing and inspecting Python code and projects.

License

Notifications You must be signed in to change notification settings

ilitia-technologies/readmate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“° Readmate

Disclaimer

This README was generated with the assistance of this Artificial Intelligence (AI) tool and is intended for demonstration purposes only. While reasonable efforts have been made to ensure accuracy, the developers do not guarantee that it is error-free. Please use this information with caution and consult professional advice as necessary.

Project Abstract

This Python project is a comprehensive toolkit for analyzing and inspecting Python code and projects. It provides functionalities for reading and manipulating various file formats, analyzing code structure and dependencies, generating README files, and extracting relevant information from projects. The project aims to streamline the process of understanding and documenting Python projects, making it easier for developers to navigate and collaborate on codebases.

Python langchain langgraph langchain-openai python-dotenv fastapi uvicorn tiktoken langchainhub rich tenacity toml nbformat typer

πŸ“‘Table of Contents

✨ Features

Feature Description
File Analysis This project provides functionalities for analyzing Python files. It includes methods for parsing files, analyzing their contents, and extracting key code segments. The analysis results are stored in a structured format for further processing and understanding.
Folder Inspection The project offers tools for inspecting project directories. It includes functionalities for detecting various types of files, such as requirements files, deployment files, license files, and README files. The inspection results provide valuable information about the project's structure and contents.
Token Tracking The project includes a token usage tracker that keeps track of the usage of tokens and the associated cost. It provides methods for logging token usage, logging cost, retrieving the total token usage, and retrieving the total cost. This feature helps monitor and manage token usage and cost throughout the application.
Code Extraction The project provides functionalities for extracting key code segments from Python files. It includes methods for extracting functions, classes, and top-level statements. The extracted code segments can be used for further analysis or documentation purposes.
Tree Generation The project includes a tree generator that can generate a tree structure for a given directory. It provides methods for initializing the class, building the tree structure, and generating and formatting the tree structure as a string. This feature helps visualize the directory structure and facilitates navigation within the project.
Markdown Generation The project offers tools for generating descriptive Markdown sections. It includes functionalities for generating Markdown descriptions of files, modules, and top-level code. This feature helps document and communicate the project's functionality and structure effectively.
CLI Functionality The project includes a CLI module that provides a command-line interface for interacting with the project's functionalities. It allows developers to perform operations such as file parsing, data extraction, and project inspection through simple command-line commands.
Exception Handling The project includes functionalities for handling exceptions. It provides methods for reading and analyzing files, tracking token counts, and handling exceptions gracefully. This feature ensures the robustness and reliability of the project's functionalities.

πŸ“ Project Tree

Here is the visual representation of the project's directory structure:

β”œβ”€ app.py
β”œβ”€ cli.py
β”œβ”€ review_and_check.py
β”œβ”€ readmate
β”‚  β”œβ”€ agents_and_tools
β”‚  β”œβ”€ chains
β”‚  β”œβ”€ configs
β”‚  β”œβ”€ generators
β”‚  β”œβ”€ json_output
β”‚  β”œβ”€ modules
β”‚  β”œβ”€ prompts
β”‚  β”œβ”€ toolkit
β”‚  └─ utils
└─ tests

This representation shows the main directories and their subdirectories and files. Each directory is indicated by β”œβ”€ and each file is indicated by └─. The indentation is used to show the level of each directory and file.

πŸ› οΈ Requirements

Poetry

Pyproject.toml

Instructions

Prerequisites: None

Python Version: This project is compatible with Python 3.9 or higher.

Libraries and Dependencies:

  • langchain (version 0.1.11): This library provides functionality for working with language chains, which are sequences of words that form coherent sentences.
  • langgraph (version 0.0.26): This library allows for the creation and manipulation of language graphs, which represent the relationships between words in a language.
  • langchain-openai (version 0.0.8): This library integrates with the OpenAI GPT-3.5 language model to generate language chains.
  • python-dotenv (version 1.0.1): This library enables the use of environment variables in the project, making it easier to manage configuration settings.
  • fastapi (version 0.110.0): This library is a modern, fast (high-performance) web framework for building APIs with Python.
  • uvicorn (version 0.28.0): This library is a lightning-fast ASGI server implementation, used to run the FastAPI application.
  • tiktoken (version 0.6.0): This library provides a tokenizer for splitting text into tokens, which is useful for language processing tasks.
  • langchainhub (version 0.1.15): This library is a hub for language chains, providing a centralized repository for sharing and accessing language chain data.
  • rich (version 13.7.1): This library is used for rich text and beautiful formatting in the command line interface.
  • tenacity (version 8.2.3): This library provides a framework for retrying operations with configurable retry policies.
  • toml (version 0.10.2): This library is used for parsing TOML configuration files.
  • nbformat (version 5.10.3): This library provides a way to read, write, and manipulate Jupyter Notebook files.
  • typer (version 0.12.3): This library is used for building command-line interfaces with Python.

Please ensure that you have Python 3.9 or higher installed, and install the required libraries and dependencies using the following command:

pip install -r requirements.txt

For more information on how to use this project, please refer to the README.md file.

πŸš€ Deployment

No details were found relating deployment

πŸ“¦ Main_modules

Main Modules

cli.py

The cli.py module provides a command-line interface (CLI) for interacting with the Python project. It utilizes the typer library to define and handle command-line commands and options. This module contains the main function that parses the command-line arguments and executes the corresponding commands.

# Example code snippet from the module
def main(
    output_dir: str = typer.Option(
        "readmate/json_output",
        "--output-dir",
        "-o",
        help="The path of the directory where we save the experiments",
    ),
    input_dir: str = typer.Option(
        "",
        "--input-dir",
        "-id",
        help="The path of the folder or zip file where the project is located",
    ),
    readme_only: bool = typer.Option(
        False,
        "--readme-only",
        help="Only generate the README file",
    ),
    token_count: int = typer.Option(
        0, 
        "--token-count", 
        "-tc", 
        help="The number of tokens to use")

):
    # This is the main function
    # It takes several command line arguments for customization
    
    # The 'output_dir' argument specifies the path of the directory where we save the experiments
    # The 'input_dir' argument specifies the path of the folder or zip file where the project is located
    # The 'readme_only' argument is a boolean flag indicating whether to only generate the README file
    
    # The function has several steps:
    # Step 1: Parse the command line arguments
    # Step 2: Set up the necessary configurations
    # Step 3: Perform the core functionality of the application
    # Step 4: Generate the README file
    
    # ...

Modules

readmate

__init__.py

This module serves as the initialization file for the readmate package. It is empty and does not contain any code.

readmate_agent.py

The readmate_agent.py module contains the implementation of the ReadmateAgent class. This class represents the main agent responsible for coordinating the various components of the Readmate project. It acts as the central hub for handling user interactions, managing data flow, and orchestrating the execution of different tasks.

# Example code snippet from the module
class ReadmateAgent:
    def __init__(self):
        # Initialize the ReadmateAgent object
        pass
    
    def run(self):
        # Run the ReadmateAgent
        pass

readmate.chains

chat_message_chain.py

The chat_message_chain.py module contains the implementation of the ChatMessageChain class. This class represents a message chain used for conducting chat-based conversations. It handles the processing and generation of messages, as well as the interaction with external chat APIs or models.

# Example code snippet from the module
class ChatMessageChain:
    def __init__(self):
        # Initialize the ChatMessageChain object
        pass
    
    def add_message(self, message):
        # Add a message to the chain
        pass
    
    def generate_response(self):
        # Generate a response based on the current chain
        pass

Generators

markdown.py

The markdown.py module provides functionality for generating Markdown text. It contains functions for converting various data structures or formats into Markdown-compatible text.

# Example code snippet from the module
def convert_to_variable(name):
    # First try to get the variable from globals
    if name in globals():
        return globals()[name]
    # Then try to get the variable from locals
    elif name in locals():
        return locals()[name]
    # If the variable is not found, return None
    return None

review_and_check.py

The review_and_check.py module is responsible for reviewing and checking the Python project. It contains various functions and methods for analyzing the project's files, detecting specific patterns or structures, and generating reports or summaries. This module plays a critical role in ensuring the quality and correctness of the project.

# Example code snippet from the module
class ReviewAndCheck:
    def __init__(self, folder_path: str, project_extensions_path) -> None:
        # The '__init__' method initializes the ReviewAndCheck object
        # It takes two parameters: 'folder_path' (the path to the folder containing the Python files)
        # and 'project_extensions_path' (the path to the project extensions file)
        
        # The method initializes various attributes of the object, including 'project_extensions_path',
        # 'read_token_counter', and 'total_token_counter'
        
        # ...
    
    def list_all_files_recursively(self, folder_path):
        """Generator that yields file paths in the given folder and its subfolders."""
        # The 'list_all_files_recursively' method is a generator function that lists and then
        # yields file paths in the given folder and its subfolders
        
        # It utilizes the 'os.walk' function to traverse the directory structure
        
        # The method uses a nested loop to iterate over the directories and files in each
        
        # ...
    
    def max_files_exception(self):
        if self.file_counter > FILE_COUNTER:
            exception_message = "Max total files reached: {}".format(self.file_counter)
            # The 'max_files_exception' method checks if the total number of files exceeds a predefined limit
            
            # If the limit is exceeded, it generates an exception with an appropriate error message
            
            # The method returns a tuple with a boolean value indicating whether the limit is exceeded
            # and the exception message
            
            # ...
    
    def max_token_exception(self):
        if self.read_token_counter > TOKEN_LIMITER:
            exception_message = "Max read token reached: {}".format(
                self.read_token_counter
            )
            return False, exception_message
            # The 'max_token_exception' method checks if the total number of read tokens exceeds a predefined limit
            
            # If the limit is exceeded, it generates an exception with an appropriate error message
            
            # The method returns a tuple with a boolean value indicating whether the limit is exceeded
            # and the exception message
            
            # Currently, the check for the total number of tokens is commented out
            
            # ...
    
    def python_exception(self):
        # The 'python_exception' method is a placeholder for handling specific exceptions related to Python
        
        # It is likely intended to handle and log exceptions that occur during the execution of the project
        
        # ...
    
    def read_all_files_in_folder(self):
        extension_support = load_toml(self.project_extensions_path)

        supported_list_extensions = list(extension_support["extensions"].keys())
        """Lists and then reads the content of all files in the specified folder."""
        # The 'read_all_files_in_folder' method lists and then reads the content of all files in the specified folder
        
        # It first loads the supported extensions from a TOML file
        
        # The supported extensions are extracted from the loaded data
        
        # The method then iterates over the file paths obtained from 'list_all_files_recursively'
        
        # For each file, the method calls the 'read_file' method to read its content
        
        # If the 'read_file' method returns a status indicating an error, an error message is logged
        
        # ...
    
    def read_file(self, file_path, supported_list_extensions):
        """Reads and prints the content of the given file."""
        _, file_extension = os.path.splitext(file_path)

        if file_extension[1:] == LANGUAGE_KEY_EXTENSION:
            self.python_flag = True
        # The 'read_file' method reads and prints the content of the given file
        
        # It takes two parameters: 'file_path' (the path to the file) and 'supported_list_extensions'
        
        # The method uses 'os.path.splitext' to split the file path into the base name and extension
        
        # If the file extension matches the 'LANGUAGE_KEY_EXTENSION', the 'python_flag' attribute is set to True
        
        # The method then checks if the file extension is in the list of supported extensions
        
        # If it is, the method attempts to open the file and read its content
        
        # The content is then passed to the 'num_tokens_from' method to count the number of tokens
        
        # ...

tree.py

The tree.py module provides functionality for generating a tree structure representation of a given directory. It is used to visualize the directory structure of the project. The module contains a Tree class with methods for building the tree structure and formatting it for display.

# Example code snippet from the module
class Tree:
    def __init__(self, repo_name: str, root_dir: Path, max_depth: int):
        self.repo_name = repo_name
        self.root_dir = root_dir
        self.max_depth = max_depth
        # This is the '__init__' method of the Tree class
        # It initializes the class with the repository name, root directory, and maximum depth
        
        # The 'repo_name' parameter is a string representing the name of the repository
        # The 'root_dir' parameter is a Path object representing the root directory of the project
        # The 'max_depth' parameter is an integer representing the maximum depth of the tree structure
        
        # The method assigns the input values to the corresponding attributes
        
        # ...
    
    def _build_tree(
        self,
        directory: Path,
        prefix: str = "",
        is_last: bool = True,
        depth: int = 0,
    ) -> str:
        """Generates a tree structure for a given directory."""
        if depth > self.max_depth:
            return ""
        # This is the '_build_tree' method of the Tree class
        # It generates a tree structure for a given directory
        
        # The 'directory' parameter is a Path object representing the current directory being processed
        # The 'prefix' parameter is an optional string representing the prefix for each line in the tree structure
        # The 'is_last' parameter is an optional boolean indicating if the current directory is the last sibling
        # The 'depth' parameter is an optional integer representing the current depth in the tree structure
 
    
    def tree(self) -> str:
        """Generates and formats a tree structure."""
        # This is the 'tree' method of the Tree class
        # It generates and formats a tree structure for the project's directory
        
        # The method does not take any parameters
        
        # The method calls the '_build_tree' method with the root directory as the starting point
        
        # The generated tree structure is assigned to the 'tree_structure' variable
        
        # The method returns the generated tree structure
        
        # ...

generators.markdown

markdown.py

The markdown.py module provides functionality for generating Markdown text. It contains functions for converting various data structures or formats into Markdown-compatible text.

# Example code snippet from the module
def convert_to_variable(name):
    # First try to get the variable from globals
    if name in globals():
        return globals()[name]
    # Then try to get the variable from locals
    elif name in locals():
        return locals()[name]
    # If the variable is not found, return None
    return None

python_analyzer.py

Name & Purpose: The python_analyzer.py module analyzes Python files within the project. It extracts information about classes, functions, and top-level code, providing insights into the project's structure and dynamics.

Functions & Code Snippets:

# Main class for analyzing Python files
class PythonAnalyzer:
    # Key implementation details
    pass

project_inspector.py

Name & Purpose: The project_inspector.py module inspects the Python project's directory and gathers information about its structure, files, and dependencies. It provides functionality for detecting various aspects of the project.

Functions & Code Snippets:

# Main class for inspecting the project
class ProjectInspector:
    # Key implementation details
    pass

utils_tools.py

Name & Purpose: The utils_tools.py module provides utility functions and tools for various tasks within the project. It includes functions for file manipulation, data loading, and other common operations.

Functions & Code Snippets:

# Utility function for copying a project folder
def copy_project_folder(src, dst):
    # Key implementation details
    pass

# Utility function for loading JSON data from a file
def load_json_from_path(file_path):
    # Key implementation details
    pass

# Utility function for checking if a directory is a zip file
def is_zip_file(input_dir):
    # Key implementation details
    pass

logger.py

Name & Purpose: The logger.py module provides logging functionality for the Python project. It sets up the logger and defines logging configurations.

Functions & Code Snippets:

# Function for setting up the logger
def set_logger():
    # Key implementation details
    pass

setup_env.py

Name & Purpose: The setup_env.py module handles the setup of environmental variables for the Python project. It loads environmental variables from a .env file and checks for required variables.

Functions & Code Snippets:

# Function for loading environmental variables
def load_environment_variables():
    # Key implementation details
    pass

general_utils.py

Name & Purpose: The general_utils.py module provides general utility functions for various tasks within the project. It includes functions for string manipulation, file reading, and other common operations.

Functions & Code Snippets:

# Function for truncating a string to a specified number of tokens
def truncate_strings_in_dict(data, max_tokens=8000, encoding_name="cl100k_base"):
    # Key implementation details
    pass

# Function for reading the content of a text file
def read_text_file(file_path, token):
    # Key implementation details
    pass

🧩 Recommended_modules

Based on the provided information, the additional modules or libraries that enhance the functionality of the Python project but are not mandatory are as follows:

  1. langgraph: This module provides prebuilt tools for graph-based analysis of programming languages. It enhances the project's functionality by allowing advanced analysis of code structure and relationships between different elements.

  2. langchainhub: This module provides a hub for executing tools and agents in a language chain. It facilitates the development process by providing a centralized platform for managing and executing various tools and agents.

  3. langchain_core: This module provides the core functionality for creating agents and handling agent actions and messages. It improves the project's performance by providing a standardized framework for agent-based communication and coordination.

  4. langchain_openai: This module integrates OpenAI's chat capabilities into the project. It enhances the project's functionality by enabling chat-based interactions and responses using OpenAI's powerful language models.

  5. readmate: This module provides various utilities and prompts for generating Markdown sections for README files. It facilitates the development process by automating the generation of README sections based on code analysis and project structure.

These recommended modules can improve performance by providing efficient and optimized implementations for specific tasks. They can add features by integrating external services or tools into the project. Additionally, they can facilitate development by providing prebuilt functionalities and utilities that save time and effort in implementing common tasks.

⬇️ Installation

To install the Python project, follow these steps:

  1. Clone the project repository from GitHub:

    git clone <repository_url>
    
  2. Change into the project directory:

    cd <project_directory>
    
  3. Create a virtual environment (optional but recommended):

    • For Windows:
      python -m venv venv
      venv\Scripts\activate
      
    • For macOS and Linux:
      python3 -m venv venv
      source venv/bin/activate
      
  4. Install the project dependencies:

    pip install -r requirements.txt
    
  5. Run any necessary setup scripts or commands:

    • If there are any specific setup scripts or commands mentioned in the project documentation, follow those instructions.
  6. The project is now installed and ready to use.

Note: The installation process should be the same across different operating systems and environments as long as Python and pip are properly installed. However, it's always recommended to refer to the project's documentation or README file for any specific instructions or requirements.

βš™οΈ Configuration

Configuration and Setup

To configure the Python project for first-time use, follow these steps:

  1. Environment Variables: Check if the project requires any environment variables to be set. These variables may include API keys, database credentials, or other sensitive information. If necessary, create a .env file in the project's root directory and add the required variables in the format KEY=VALUE.

  2. Configuration Files: Review the project's configuration files to customize the behavior according to your needs. These files may be located in a config or settings directory. Open the relevant configuration file(s) and modify the settings as required. Make sure to follow the provided instructions or comments within the file to understand the purpose of each setting.

  3. Dependencies: Install the required dependencies for the project. Check if the project provides a requirements.txt file or a Pipfile for managing dependencies. Use the appropriate package manager (pip or pipenv) to install the dependencies by running the following command in the project's root directory:

    pip install -r requirements.txt

    or

    pipenv install
  4. Database Setup: If the project uses a database, follow the provided instructions to set up the database. This may involve creating a new database, running migrations, or configuring the connection settings. Refer to the project's documentation or README file for specific instructions.

  5. Customization: If the project allows for customization, review the available options and modify the necessary files or settings to tailor the project to your requirements. This may include changing default values, enabling or disabling certain features, or configuring integrations with external services.

  6. Testing: Before using the project, it is recommended to run the provided tests to ensure everything is functioning correctly. Refer to the project's documentation or README file for instructions on running the tests.

Once you have completed these steps, the Python project should be configured and ready for use according to your specific needs. Make sure to consult the project's documentation or README file for any additional setup instructions or specific details related to your use case.

❓ Troubleshooting_faq

Details for this sections are WIP (work in progress)

πŸ‘©β€πŸ’Ό πŸ‘¨β€πŸ’Ό Maintainers

Details for this sections are WIP (work in progress)

πŸ” License

No details were found relating license

🀝 Contributions

Details for this sections are WIP (work in progress)

πŸ“‹ Examples

Details for this sections are WIP (work in progress)

πŸ§ͺ Testing

Details for this sections are WIP (work in progress)

About

This Python project is a comprehensive toolkit for analyzing and inspecting Python code and projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages