From 2f62f923a4adcbf4e13a33f4ca0bd04216d69489 Mon Sep 17 00:00:00 2001 From: Raphael MANSUY Date: Sat, 29 Jun 2024 08:15:19 +0800 Subject: [PATCH] restructure project v 0.6.3 --- README.md | 56 ++----------------- code2prompt/core/__init__.py | 0 code2prompt/{ => core}/generate_content.py | 2 +- code2prompt/{ => core}/process_file.py | 0 code2prompt/{ => core}/process_files.py | 6 +- code2prompt/{ => core}/template_processor.py | 0 code2prompt/{ => core}/write_output.py | 0 code2prompt/main.py | 13 ++--- code2prompt/{ => utils}/count_tokens.py | 0 .../{ => utils}/create_template_directory.py | 0 .../{ => utils}/get_gitignore_patterns.py | 0 .../{ => utils}/should_process_file.py | 0 pyproject.toml | 2 +- tests/test_create_template_directory.py | 2 +- 14 files changed, 18 insertions(+), 63 deletions(-) create mode 100644 code2prompt/core/__init__.py rename code2prompt/{ => core}/generate_content.py (92%) rename code2prompt/{ => core}/process_file.py (100%) rename code2prompt/{ => core}/process_files.py (89%) rename code2prompt/{ => core}/template_processor.py (100%) rename code2prompt/{ => core}/write_output.py (100%) rename code2prompt/{ => utils}/count_tokens.py (100%) rename code2prompt/{ => utils}/create_template_directory.py (100%) rename code2prompt/{ => utils}/get_gitignore_patterns.py (100%) rename code2prompt/{ => utils}/should_process_file.py (100%) diff --git a/README.md b/README.md index 8532e95..a17f3c0 100644 --- a/README.md +++ b/README.md @@ -20,56 +20,6 @@ With Code2Prompt, you can easily create a well-structured and informative docume - Supports custom Jinja2 templates for flexible output formatting - Offers token counting functionality for generated prompts -## How It Works - -The following diagram illustrates the high-level workflow of Code2Prompt: - -Diagram - -1. The tool starts by parsing the command-line options provided by the user. -2. It then parses the .gitignore file (if specified) to obtain a set of patterns for excluding files and directories. -3. The tool traverses the specified directory and its subdirectories, processing each file encountered. -4. For each file, it checks if the file is ignored based on the .gitignore patterns. If ignored, it skips the file and moves to the next one. -5. If the file is not ignored, it checks if the file matches the filter pattern (if provided). If the file doesn't match the filter, it skips the file and moves to the next one. -6. If the file matches the filter pattern, it checks if the file is a binary file. If it is, it skips the file and moves to the next one. -7. If the file is not a binary file, the tool extracts the file metadata (extension, size, creation time, modification time). -8. It then reads the file content and generates a file summary and code block. -9. The file summary, code block, and metadata are appended to the Markdown content. -10. Steps 4-9 are repeated for each file in the directory and its subdirectories. -11. After processing all files, the tool generates a table of contents based on the file paths. -12. If a custom template is provided, the tool processes the template with the collected data. -13. If token counting is enabled, the tool counts the tokens in the generated content. -14. If an output file is specified, the generated Markdown content is written to the file. Otherwise, it is printed to the console. -15. The tool ends its execution. - -## Project Structure - -The Code2Prompt project is organized as follows: - -- `code2prompt/`: Main package directory - - `__init__.py`: Package initialization - - `main.py`: Entry point of the application - - `process_file.py`: File processing logic - - `template_processor.py`: Custom template processing - - `write_output.py`: Output writing functionality - - `utils/`: Utility functions - - `add_line_numbers.py`: Function to add line numbers to code - - `generate_markdown_content.py`: Markdown content generation - - `is_binary.py`: Binary file detection - - `is_filtered.py`: File filtering logic - - `is_ignored.py`: Gitignore pattern matching - - `language_inference.py`: Programming language inference - - `parse_gitignore.py`: Gitignore file parsing - - `comment_stripper/`: Comment removal functionality - - `__init__.py`: Subpackage initialization - - `strip_comments.py`: Main comment stripping logic - - `c_style.py`: C-style comment removal - - `html_style.py`: HTML-style comment removal - - `python_style.py`: Python-style comment removal - - `r_style.py`: R-style comment removal - - `shell_style.py`: Shell-style comment removal - - `sql_style.py`: SQL-style comment removal - - `matlab_style.py`: MATLAB-style comment removal ## Installation @@ -114,6 +64,12 @@ Alternatively, you can install Code2Prompt using pipx, a tool for installing and pipx install git+https://github.com/raphaelmansuy/code2prompt.git ``` + Or + + ``` + pipx install code2prompt + ``` + This command will clone the Code2Prompt repository and install it in an isolated environment managed by pipx. 3. After installation, you can run Code2Prompt using the `code2prompt` command: diff --git a/code2prompt/core/__init__.py b/code2prompt/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code2prompt/generate_content.py b/code2prompt/core/generate_content.py similarity index 92% rename from code2prompt/generate_content.py rename to code2prompt/core/generate_content.py index dc4eba2..584f9cb 100644 --- a/code2prompt/generate_content.py +++ b/code2prompt/core/generate_content.py @@ -1,4 +1,4 @@ -from code2prompt.template_processor import get_user_inputs, load_template, process_template +from code2prompt.core.template_processor import get_user_inputs, load_template, process_template from code2prompt.utils.generate_markdown_content import generate_markdown_content diff --git a/code2prompt/process_file.py b/code2prompt/core/process_file.py similarity index 100% rename from code2prompt/process_file.py rename to code2prompt/core/process_file.py diff --git a/code2prompt/process_files.py b/code2prompt/core/process_files.py similarity index 89% rename from code2prompt/process_files.py rename to code2prompt/core/process_files.py index 88615aa..f463bc3 100644 --- a/code2prompt/process_files.py +++ b/code2prompt/core/process_files.py @@ -1,7 +1,7 @@ from pathlib import Path -from code2prompt.get_gitignore_patterns import get_gitignore_patterns -from code2prompt.process_file import process_file -from code2prompt.should_process_file import should_process_file +from code2prompt.utils.get_gitignore_patterns import get_gitignore_patterns +from code2prompt.core.process_file import process_file +from code2prompt.utils.should_process_file import should_process_file def process_files(options): """ diff --git a/code2prompt/template_processor.py b/code2prompt/core/template_processor.py similarity index 100% rename from code2prompt/template_processor.py rename to code2prompt/core/template_processor.py diff --git a/code2prompt/write_output.py b/code2prompt/core/write_output.py similarity index 100% rename from code2prompt/write_output.py rename to code2prompt/core/write_output.py diff --git a/code2prompt/main.py b/code2prompt/main.py index 7ca2a75..b788a82 100644 --- a/code2prompt/main.py +++ b/code2prompt/main.py @@ -1,12 +1,11 @@ import click -from pathlib import Path -from code2prompt.count_tokens import count_tokens -from code2prompt.generate_content import generate_content -from code2prompt.process_files import process_files -from code2prompt.write_output import write_output -from code2prompt.create_template_directory import create_templates_directory +from code2prompt.utils.count_tokens import count_tokens +from code2prompt.core.generate_content import generate_content +from code2prompt.core.process_files import process_files +from code2prompt.core.write_output import write_output +from code2prompt.utils.create_template_directory import create_templates_directory -VERSION = "0.6.2" # Define the version of the CLI tool +VERSION = "0.6.3" # Define the version of the CLI tool @click.command() @click.version_option( diff --git a/code2prompt/count_tokens.py b/code2prompt/utils/count_tokens.py similarity index 100% rename from code2prompt/count_tokens.py rename to code2prompt/utils/count_tokens.py diff --git a/code2prompt/create_template_directory.py b/code2prompt/utils/create_template_directory.py similarity index 100% rename from code2prompt/create_template_directory.py rename to code2prompt/utils/create_template_directory.py diff --git a/code2prompt/get_gitignore_patterns.py b/code2prompt/utils/get_gitignore_patterns.py similarity index 100% rename from code2prompt/get_gitignore_patterns.py rename to code2prompt/utils/get_gitignore_patterns.py diff --git a/code2prompt/should_process_file.py b/code2prompt/utils/should_process_file.py similarity index 100% rename from code2prompt/should_process_file.py rename to code2prompt/utils/should_process_file.py diff --git a/pyproject.toml b/pyproject.toml index ef2a304..fa751f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "code2prompt" -version = "0.6.2" +version = "0.6.3" description = "" authors = ["Raphael MANSUY "] readme = "README.md" diff --git a/tests/test_create_template_directory.py b/tests/test_create_template_directory.py index 9db16fd..f799ba5 100644 --- a/tests/test_create_template_directory.py +++ b/tests/test_create_template_directory.py @@ -1,7 +1,7 @@ import pytest import os from pathlib import Path -from code2prompt.create_template_directory import create_templates_directory +from code2prompt.utils.create_template_directory import create_templates_directory @pytest.fixture