This code can make documentation for your project
Project description
Quick-Doc-Py Documentation
Overview
Quick-Doc-Py is a Python utility designed to automatically generate documentation for Python projects. It uses AI to interpret the code structure and content, then writes documentation in Markdown format following Google Style. The tool supports multiple languages for documentation generation, making it versatile for international development teams.
Features
- Multi-Language Support: Generate documentation in English, Russian, Ukrainian, Chinese (Simplified), Spanish, and Polish.
- AI-Driven Documentation: Utilizes AI to analyze Python code and generate descriptive documentation.
- Customizable: Users can specify which files to ignore during documentation generation and set the project name.
- Command Line Interface: Facilitates easy integration into development workflows or CI/CD pipelines.
- File Structure Analysis: Recursively processes directories to document all relevant Python files.
Structure
./config.py: Contains configuration settings like supported languages and their mappings.language_type: A dictionary mapping language codes to integer values.
./main.py: The core logic for documentation generation.ReqHendler: Handles requests for file discovery and code reading.GptHandler: Manages interactions with the AI provider for document generation.AnswerHandler: Processes and saves the generated documentation.AutoDock: Orchestrates the entire documentation process from start to finish.
./providers_test.py: Utility to test various AI providers for compatibility and performance../utilities.py: Helper functions for progress tracking, text styling, and time management.
Usage
Command Line Arguments
--name_project: The name of the project for which documentation is being generated.--root_dir: The root directory where the Python project resides.--ignore: A list of files or directories to ignore during documentation generation (passed as a string that will be evaluated).--languages: List of languages in which documentation should be generated (passed as a string that will be evaluated).
Example Usage
python main.py --name_project "My Awesome Project" --root_dir "/path/to/project" --ignore "['__init__.py', 'tests/']" --languages "['en', 'ru']"
This command would initiate the documentation process for "My Awesome Project" located in /path/to/project, ignoring __init__.py and the tests directory, generating documentation in both English and Russian.
Notes
- Ensure you have the necessary dependencies installed, like
g4ffor AI model interactions. - Adjust the
providerinGptHandlerif you're using a different AI service provider. - The script outputs documentation files named with the language code (e.g.,
README.en.mdfor English).# Usage
The config.py file contains utilities for generating prompts for different languages. Here's how each component should be used:
language_type Dictionary
-
Usage: This dictionary maps language codes to their respective integer indices. It is used to enumerate and reference languages by their codes in a consistent manner.
language_type = { "en": 0, "ru": 1, "ua": 2, "chs": 3, # китайский "es": 4, # испанский "pl": 5 # польский }
Example:
print(language_type["ru"]) # Output: 1
GenerateLanguagePrompt Class
__init__(self, languages: dict[str, int]) -> None
-
Usage: Initializes the
GenerateLanguagePromptinstance with a dictionary of languages.- Parameters:
languages(dict): A dictionary where keys are language codes and values are their respective indices.
Example:
GLP = GenerateLanguagePrompt(language_type)
- Parameters:
generate(self) -> dict
-
Usage: Generates a dictionary where keys are indices and values are lists of prompts for documentation generation in different languages.
- Returns: A dictionary where each key is an integer (language index), and the value is a list of strings representing prompts for generating documentation in that language.
Example:
language_prompt = GLP.generate() print(language_prompt[0]) # Output: List of prompts for English
gen_prompt(self, language: str) -> list[str]
-
Usage: Generates a base prompt for documentation in a specified language.
- Parameters:
language(str): The language code for which to generate the prompt.
- Returns: A list of strings where each string is part of the prompt for generating documentation in the specified language.
Example:
prompt = GLP.gen_prompt("en") print(prompt) # Output: List of prompts for English documentation
- Parameters:
These components are used together to dynamically generate documentation prompts for multiple languages based on the language_type dictionary. The GenerateLanguagePrompt class provides an interface to create these prompts, which can be used in automated documentation generation tools or scripts.# AutoDock Documentation
Usage
The AutoDock module is designed to automatically generate documentation for Python projects by interfating with a GPT-like AI model. Here's how to use each component of the system:
ReqHendler
Class: ReqHendler
-
Constructor:
def __init__(self, root_dir: str, language: str = "en", ignore_file: list[str] = None, project_name: str = "Python Project") -> None
root_dir: The root directory of the project to scan for files.language: The language for which documentation should be generated (default is English).ignore_file: A list of file paths or patterns to ignore during the scan.project_name: The name of the project.
-
Methods:
-
get_files_from_directory(self, current_path: str = "") -> None- Recursively scans the
root_dirand collects all file paths, excluding those specified inignore_file.
- Recursively scans the
-
is_ignored(self, path: str) -> bool- Checks if the given file path should be ignored based on the
ignore_filelist.
- Checks if the given file path should be ignored based on the
-
get_code_from_file(self) -> None- Reads the content of all collected files and stores them in a dictionary
self.codes.
- Reads the content of all collected files and stores them in a dictionary
-
make_prompt(self) -> str- Constructs a prompt string that includes the project name, start prompt, and all file contents for AI processing.
-
GptHandler
Class: GptHandler
-
Constructor:
def __init__(self, provider: str = "DarkAI") -> None
provider: The AI model provider to use for generating documentation.
-
Methods:
get_answer(self, prompt: str) -> str- Sends the prompt to the AI provider and returns the generated documentation.
AnswerHandler
Class: AnswerHandler
-
Constructor:
def __init__(self, answer: str) -> None
answer: Initial documentation string to start with.
-
Methods:
-
save_documentation(self, name: str = "README.md") -> None- Saves the documentation to a file with the given name.
-
combine_response(self, new_response: str) -> None- Appends a new response to the existing documentation.
-
make_start_req_form(cls, prompt: str) -> list- Creates a message structure for the AI model with the role and content.
-
AutoDock
Class: AutoDock
-
Constructor:
def __init__(self, root_dir: str, language: str = "en", ignore_file: list[str] = None, project_name: str = "Python Project") -> None
- Similar parameters as
ReqHendler.
- Similar parameters as
-
Methods:
-
get_response(self, codes: dict) -> AnswerHandler- Generates documentation by creating prompts for each file and collecting AI responses.
-
get_part_of_response(self, prompt: str, answer_handler: AnswerHandler = None) -> AnswerHandler- Handles the interaction with the AI model, including retries if there are issues.
-
save_dock(self, answer_handler: AnswerHandler, name: str = "README") -> None- Saves the generated documentation in a language-specific file.
-
Main Function
Function: main()
- Parses command line arguments for project details and language specifications.
- Initializes
AutoDockfor each specified language, generates documentation, and saves it.
This script is designed to be run from the command line with arguments specifying the project name, root directory, files or directories to ignore, and the target languages for documentation.# Provider Testing Documentation
This module provides functionality to test various providers for a given model name, ensuring they can respond to a simple query within a specified timeout. Below is a detailed description of each method used in the ProviderTest class:
Usage
-
Run the script:
python ./providers_test.py --name_model <model_name>
Replace
<model_name>with the desired model name likegpt-3.5-turboorgpt-4. -
Output: The script will output a progress bar as it tests each provider, followed by a dictionary of providers that successfully responded, along with their responses.
Methods
ProviderTest.__init__(model_name: str) -> None
- Parameters:
model_name(str): The name of the model to test with.
- Description: Initializes the
ProviderTestwith the model name which will be used in testing.
ProviderTest.get_providers() -> None
- Description: Retrieves all available provider names from the
g4f.Providermodule, excluding any names starting with "__". It also initializes aProgressBarfor visual feedback during testing.
ProviderTest.test_provioder(provider_name: str) -> tuple[bool, str]
- Parameters:
provider_name(str): The name of the provider to test.
- Returns: A tuple where the first element is a boolean indicating if the provider worked (
Trueif it did,Falseotherwise), and the second element is either the response string orNoneif there was an error. - Description: Attempts to use the provider with the given name to get a response from the model. Uses
test_provider_timeoutfor the actual test with a timeout.
ProviderTest.test_provider_timeout(provider) -> str
- Parameters:
provider: The provider object to test.
- Returns: The response string if successful,
Noneif an error occurred or if timed out. - Description: Tries to create a chat completion with the provider. This method is wrapped with
timeout_controldecorator to ensure it doesn't hang indefinitely.
ProviderTest.test_providers() -> dict
- Returns: A dictionary where keys are provider names that worked, and values are their respective responses.
- Description: Iterates through all providers, testing each one, and returns a dictionary of those that successfully responded within the timeout period.
Decorator: timeout_control(timeout: int)
- Parameters:
timeout(int): The number of seconds before the operation times out.
- Description: A decorator function that wraps another function to enforce a timeout. If the wrapped function does not complete within the specified timeout, it will return
None.
Helper Classes:
- TextStyle: Provides methods to colorize text output for better readability.
- ProgressBar: Manages a visual progress bar to show the testing progress of providers.
This documentation covers the usage of the script for testing providers along with a brief description of each method's role in the process. Remember, this is not an exhaustive documentation; for more in-depth information, refer to the full source code or additional documentation.## utilities.py Usage Guide
TextStyle Class
This class is designed to format text with different colors using the colorama library.
-
Constructor:
def __init__(self) -> None
Initializes the
coloramalibrary. -
Method:
def get_text(self, text: str, color: any = "", back: any = "") -> str
- Parameters:
text(str): The text to be styled.color(any): The foreground color for the text. Default is an empty string which means no color change.back(any): The background color for the text. Default is an empty string which means no background color change.
- Returns: A string with applied color styles. The text is returned with the specified foreground and background colors, followed by a reset of all styles.
- Parameters:
ProgressBar Class
A utility for displaying progress bars in the console.
-
Constructor:
def __init__(self, part) -> None
- Parameters:
part(int): Affects the total number of steps for the progress bar.
- Parameters:
-
Method:
def progress(self, name)
Updates and prints the progress bar.
- Parameters:
name(str): The name or description to display with the progress bar.
- Parameters:
Global Variables
bar: ProgressBar: A global instance ofProgressBarused for tracking progress across functions.
Functions
-
Function:
def start(part)
Initializes the global progress bar.
- Parameters:
part(int): The number used to determine the total steps of the progress bar.
- Parameters:
-
Decorator:
def time_manager(func)
A decorator to wrap functions, timing their execution and updating the progress bar.
- Parameters:
func(callable): The function to be timed.
- Usage:
@time_manager def some_function(): # Function body
- The decorator will print the start and end of the function execution along with the time taken. It updates the progress bar with this information.
- Parameters:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quick_doc_py-0.8.0.tar.gz.
File metadata
- Download URL: quick_doc_py-0.8.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8f63d0495619bd5ff3f084ef8149290d14e71964349e9e827a93caadd7a32f4
|
|
| MD5 |
216a5f0a87846d26e10587be142dff2a
|
|
| BLAKE2b-256 |
0c95ece7bfbfa4c31cd28a925d6122ffecfad3b043d456bf7a21b6a64a347f0c
|
File details
Details for the file quick_doc_py-0.8.0-py3-none-any.whl.
File metadata
- Download URL: quick_doc_py-0.8.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
295719faef68b27e838de663fb86efc8fcd9b0faba507d7d80b6b6f47b6bec84
|
|
| MD5 |
02d34efd7e91ab9ad1c654131727913b
|
|
| BLAKE2b-256 |
8f1fe11740ace55a9eacb5f2189970ec3c7dce64b7fb25fdd54f3aab14ce9956
|