Skip to content

Commit

Permalink
restructure project v 0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelmansuy committed Jun 29, 2024
1 parent 063483b commit 2f62f92
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 63 deletions.
56 changes: 6 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
Empty file added code2prompt/core/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -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


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions code2prompt/main.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "code2prompt"
version = "0.6.2"
version = "0.6.3"
description = ""
authors = ["Raphael MANSUY <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_create_template_directory.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2f62f92

Please sign in to comment.