Skip to main content

A library to combine multiple code files into one for easier AI context and error analysis

Project description

CodeUnify: Combine Multiple Code Files into One

Introduction

CodeUnify is a Python library that helps developers combine multiple source code files from a directory into a single output file. It supports various programming languages and preserves the structure by marking the start and end of each file with appropriate comment styles.

This tool is particularly useful for AI-assisted development tools, enabling better context-aware debugging, analysis, and assistance by providing a unified file containing all necessary code components with clear section markers.

Features

  • Combines files from multiple languages: Supports .py, .js, .cpp, .c, .java, .ts, .go, .cs, .html, .xml, .txt, and more.
  • Per-file comment styles: Each file retains its own comment style (#, //, <!-- -->, etc.), ensuring readability.
  • Indentation for clarity: The contents of each file are indented under its respective section headers for easy visual distinction.
  • Command-line integration: Run directly from the terminal with flexible options.
  • Excludes metadata and binary files: Ignores .git, __pycache__, .idea, .vscode, and skips non-text files.

Installation

  1. Clone the repository:

    git clone https://github.com/takuphilchan/codeunify.git
    cd codeunify
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Ensure Python 3.x is installed:

    python --version
    

Usage

1. Combine Files with Default Settings

To combine all code files from a directory into a single output file, run:

codeunify /path/to/code/files output_combined.txt

2. Combine Specific File Types

To only include certain file extensions (e.g., .py and .js):

codeunify /path/to/code/files output_combined.txt --file_types .py .js

3. Customize Indentation

The --block_indent flag allows adjusting how much each file's content is indented:

codeunify /path/to/code/files output_combined.txt --block_indent "    "

(Default indentation is a tab \t.)

Example

Given Input Files:

app.py:

def main():
    print("Hello, World!")

utils.js:

function greet() {
    console.log("Hello from JS!");
}

index.html:

<html>
    <body>
        <h1>Welcome to my website</h1>
    </body>
</html>

Running:

codeunify /projects/code/ combined_output.txt

Correct Output:

# >>>>> START: app.py <<<<<

	 def main():
	     print("Hello, World!")

# <<<<< END: app.py >>>>>

// >>>>> START: utils.js <<<<<

	 function greet() {
	     console.log("Hello from JS!");
	 }

// <<<<< END: utils.js >>>>>

<!-- >>>>> START: index.html <<<<< -->

	 <html>
	     <body>
	         <h1>Welcome to my website</h1>
	     </body>
	 </html>

<!-- <<<<< END: index.html >>>>> -->

How It Helps AI-Assisted Development

  • Improved Code Context: AI tools can analyze code with clear section markers instead of handling separate files.
  • Enhanced Debugging: AI-powered debugging can trace issues across multiple files more effectively.
  • Better Code Completions: By knowing the entire project's structure, AI can provide better auto-suggestions.

Contributing

We welcome contributions! Feel free to fork the repository, make changes, and submit a pull request.

License

This library is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeunify-0.2.6.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeunify-0.2.6-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file codeunify-0.2.6.tar.gz.

File metadata

  • Download URL: codeunify-0.2.6.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for codeunify-0.2.6.tar.gz
Algorithm Hash digest
SHA256 802e09fefacd468ba9e1ec5ceb0d958696b75d4ee5b42a27c0138cab649b36ee
MD5 a390a673faeab269d01408f6ce49751e
BLAKE2b-256 4ff45fe50a415ab39771949c4e623862fba6bad47d7122dda5e610c21e42d46c

See more details on using hashes here.

File details

Details for the file codeunify-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: codeunify-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for codeunify-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bd9fa9398863a3b10bb3099e9c1a43e3e636ddf57e8c65704859bb8b1072a0e8
MD5 ab6f713933a11eec7ae1d64d101ed486
BLAKE2b-256 901b5f577d7af05b1b54eede3de94d138a353cc32f531d4b7507235fd52b3087

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page