CodeFusion is a Python tool that combines code files from a specified directory into a single text file. It includes or excludes files based on file extensions and respects .gitignore
patterns in the directory to skip certain files and directories.
- Python 3.6 or later
- Basic command-line knowledge
If you’re starting with a fresh setup:
git clone <repository_url>
cd CodeFusion
Or if you’re already in the project folder:
cd /path/to/CodeFusion
Setting up a virtual environment ensures dependencies are isolated to this project.
To use python
instead of python3
for virtual environment commands, follow these steps:
-
Option 1: Temporary Alias
Create an alias in your terminal:alias python=python3
To make this permanent, add
alias python=python3
to your shell config file (~/.bashrc
for bash or~/.zshrc
for zsh), then reload it with:source ~/.bashrc # for bash source ~/.zshrc # for zsh
-
Option 2: Create a Permanent Symlink
You can create a system-wide symlink:sudo ln -s $(which python3) /usr/local/bin/python
Now you can use python
commands instead of python3
.
-
Create the virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
You should see (venv)
at the beginning of your command prompt, indicating the virtual environment is active.
With the virtual environment active, install the necessary packages:
python -m pip install -r requirements.txt
If requirements.txt
does not exist, manually install pathspec
(used for handling .gitignore
patterns):
python -m pip install pathspec
Make sure you have a target directory that contains the files you want to combine. Let’s assume it’s called data
within the CodeFusion
directory. You can create sample files in this directory for testing.
If you want CodeFusion to skip certain files or directories, create a .gitignore
file in the target directory (data
) and add patterns to it. Here’s an example:
# Ignore all log files
*.log
# Ignore temporary or compiled files
*.tmp
*.pyc
# Ignore a specific directory
node_modules/
Now that everything is set up, you can run CodeFusion with the following command:
python codefusion/main.py data -o combined_code.txt
CodeFusion offers several command-line options:
root_dir
: The root directory to scan for files (e.g.,data
).-o
or--output
: The name of the output file. Default iscombined_code.txt
.-t
or--types
: Specify file extensions to include. If omitted, CodeFusion will include all files by default.
-
Combine all files in the
data
directory:python codefusion/main.py data -o combined_code.txt
-
Combine only Python and JavaScript files:
python codefusion/main.py data -o combined_code.txt -t .py .js
-
Respect
.gitignore
rules:CodeFusion automatically respects
.gitignore
rules in the specified directory. Any patterns in.gitignore
will be used to skip files and directories.
After running CodeFusion, you should see a file named combined_code.txt
(or whatever output file name you specified) in the CodeFusion
directory. This file will contain the combined contents of all included files, separated by headers showing each file’s path.
Example output format:
# ==== File: /path/to/data/file1.py ====
# Content of file1.py
# ==== End of /path/to/data/file1.py ====
# ==== File: /path/to/data/subdir/file2.js ====
# Content of file2.js
# ==== End of /path/to/data/subdir/file2.js ====
When you’re done, deactivate the virtual environment by running:
deactivate
pathspec
Module Not Found: Ensurepathspec
is installed withpython -m pip install pathspec
.- Virtual Environment Not Activated: If you don’t see
(venv)
in your prompt, ensure you’ve activated the environment. - Ignored Files Not Skipping: Double-check your
.gitignore
file, ensure it’s placed in the root directory (data
), and follows proper.gitignore
syntax.
-
Navigate to the directory:
cd /path/to/CodeFusion
-
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # macOS/Linux # or venv\Scripts\activate # Windows
-
Install dependencies:
python -m pip install -r requirements.txt
-
Run CodeFusion:
python codefusion/main.py data -o combined_code.txt
-
Deactivate the virtual environment:
deactivate
This guide should help you set up and use CodeFusion from scratch. Let me know if you need any further clarification!