-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d41009
commit c21822a
Showing
18 changed files
with
2,876 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include README.md | ||
include LICENSE | ||
recursive-include repopack *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .packager import pack | ||
from .cli import run_cli | ||
from .version import __version__ | ||
|
||
__all__ = ['pack', 'run_cli', '__version__'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .cli import run_cli | ||
|
||
if __name__ == "__main__": | ||
run_cli() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import argparse | ||
import os | ||
from .packager import pack | ||
from .config import load_config, merge_configs | ||
from .utils.cli_output import print_summary, print_completion | ||
from .utils.logger import logger | ||
from .utils.spinner import Spinner | ||
from .version import __version__ | ||
|
||
|
||
def run_cli(): | ||
parser = argparse.ArgumentParser(description="Repopack - Pack your repository into a single AI-friendly file") | ||
parser.add_argument("directory", nargs="?", default=".", help="Directory to pack") | ||
parser.add_argument("-o", "--output", help="Specify the output file name") | ||
parser.add_argument("-i", "--ignore", help="Additional ignore patterns (comma-separated)") | ||
parser.add_argument("-c", "--config", help="Path to a custom config file") | ||
parser.add_argument("--verbose", action="store_true", help="Enable verbose logging") | ||
parser.add_argument("-v", "--version", action="version", version=f"Repopack v{__version__}") | ||
args = parser.parse_args() | ||
|
||
logger.set_verbose(args.verbose) | ||
|
||
config = load_config(args.config) | ||
cli_config = {} | ||
if args.output: | ||
cli_config["output"] = {"file_path": args.output} | ||
if args.ignore: | ||
cli_config["ignore"] = {"custom_patterns": args.ignore.split(",")} | ||
|
||
merged_config = merge_configs(config, cli_config) | ||
|
||
spinner = Spinner("Packing files...") | ||
try: | ||
spinner.start() | ||
pack_result = pack(os.path.abspath(args.directory), merged_config) | ||
spinner.succeed("Packing completed successfully!") | ||
|
||
print_summary(pack_result['total_files'], pack_result['total_characters'], merged_config['output']['file_path']) | ||
print_completion() | ||
except Exception as e: | ||
spinner.fail(f"Error during packing: {str(e)}") | ||
logger.error(str(e)) | ||
exit(1) | ||
|
||
if __name__ == "__main__": | ||
run_cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
from typing import Dict, Any | ||
|
||
DEFAULT_CONFIG = { | ||
"output": { | ||
"file_path": "repopack-output.txt", | ||
"style": "plain", | ||
"remove_comments": False, | ||
"remove_empty_lines": False, | ||
}, | ||
"ignore": { | ||
"use_gitignore": True, | ||
"use_default_patterns": True, | ||
"custom_patterns": [], | ||
}, | ||
} | ||
|
||
def load_config(config_path: str = None) -> Dict[str, Any]: | ||
if config_path: | ||
with open(config_path, 'r') as f: | ||
return json.load(f) | ||
return {} | ||
|
||
def merge_configs(file_config: Dict[str, Any], cli_config: Dict[str, Any]) -> Dict[str, Any]: | ||
merged = DEFAULT_CONFIG.copy() | ||
merged.update(file_config) | ||
merged.update(cli_config) | ||
return merged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
from datetime import datetime | ||
from typing import Dict, Any, List | ||
from .utils.tree_generator import generate_tree_string | ||
|
||
def generate_output(root_dir: str, config: Dict[str, Any], sanitized_files: List[Dict[str, str]], all_file_paths: List[str]): | ||
output_path = os.path.join(root_dir, config['output']['file_path']) | ||
tree_string = generate_tree_string(all_file_paths) | ||
|
||
with open(output_path, 'w', encoding='utf-8') as f: | ||
f.write("=" * 64 + "\n") | ||
f.write("Repopack Output File\n") | ||
f.write("=" * 64 + "\n\n") | ||
f.write(f"This file was generated by Repopack on: {datetime.now().isoformat()}\n\n") | ||
f.write("Purpose:\n--------\n") | ||
f.write("This file contains a packed representation of the entire repository's contents.\n") | ||
f.write("It is designed to be easily consumable by AI systems for analysis, code review,\n") | ||
f.write("or other automated processes.\n\n") | ||
f.write("Repository Structure:\n---------------------\n") | ||
f.write(tree_string + "\n\n") | ||
f.write("=" * 64 + "\n") | ||
f.write("Repository Files\n") | ||
f.write("=" * 64 + "\n\n") | ||
|
||
for file in sanitized_files: | ||
f.write("=" * 16 + "\n") | ||
f.write(f"File: {file['path']}\n") | ||
f.write("=" * 16 + "\n") | ||
f.write(file['content'] + "\n\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
from typing import Dict, Any | ||
from .utils.file_handler import sanitize_files | ||
from .utils.ignore_utils import get_all_ignore_patterns, create_ignore_filter | ||
from .output_generator import generate_output | ||
|
||
def pack(root_dir: str, config: Dict[str, Any]) -> Dict[str, Any]: | ||
ignore_patterns = get_all_ignore_patterns(root_dir, config) | ||
ignore_filter = create_ignore_filter(ignore_patterns) | ||
|
||
all_file_paths = [] | ||
for root, _, files in os.walk(root_dir): | ||
for file in files: | ||
file_path = os.path.relpath(os.path.join(root, file), root_dir) | ||
if ignore_filter(file_path): | ||
all_file_paths.append(file_path) | ||
|
||
sanitized_files = sanitize_files(all_file_paths, root_dir, config) | ||
|
||
generate_output(root_dir, config, sanitized_files, all_file_paths) | ||
|
||
total_files = len(sanitized_files) | ||
total_characters = sum(len(file['content']) for file in sanitized_files) | ||
|
||
return { | ||
"total_files": total_files, | ||
"total_characters": total_characters, | ||
} |
Oops, something went wrong.