Skip to main content

Convert a directory structure and its contents into a single text file, including the tree output and file contents in markdown code blocks. It may be useful to chat with LLM about your code.

Project description

Repository to Text Conversion: repo-to-text command

repo-to-text is an open-source project that converts the structure and contents of a directory (repository) into a single text file. By executing a simple command in the terminal, this tool generates a text representation of the directory, including the output of the tree command and the contents of each file, formatted for easy reading and sharing. This can be very useful for development and debugging with LLM.

Example of Repository to Text Conversion

Example Output

The generated text file will include the directory structure and contents of each file. For a full example, see the example output for this repository.

The same text will appear in your clipboard. You can paste it into a dialog with the LLM and start communicating.

Features

  • Generates a text representation of a directory's structure.
  • Includes the output of the tree command.
  • Saves the contents of each file, encapsulated in markdown code blocks.
  • Copies the generated text representation to the clipboard for easy sharing.
  • Easy to install and use via pip.

Installation

Using pip

To install repo-to-text via pip, run the following command:

pip install repo-to-text

To upgrade to the latest version, use the following command:

pip install --upgrade repo-to-text

Usage

After installation, you can use the repo-to-text command in your terminal. Navigate to the directory you want to convert and run:

repo-to-text

or

flatten

This will create a file named repo-to-text_YYYY-MM-DD-HH-MM-SS-UTC.txt in the current directory with the text representation of the repository. The contents of this file will also be copied to your clipboard for easy sharing.

Options

You can customize the behavior of repo-to-text with the following options:

  • --output-dir <path>: Specify an output directory where the generated text file will be saved. For example:

    repo-to-text --output-dir /path/to/output
    

    This will save the file in the specified output directory instead of the current directory.

  • --create-settings or --init: Create a default .repo-to-text-settings.yaml file with predefined settings. This is useful if you want to start with a template settings file and customize it according to your needs. To create the default settings file, run the following command in your terminal:

    repo-to-text --create-settings
    

    or

    repo-to-text --init
    

    This will create a file named .repo-to-text-settings.yaml in the current directory. If the file already exists, an error will be raised to prevent overwriting.

  • --debug: Enable DEBUG logging. By default, repo-to-text runs with INFO logging level. To enable DEBUG logging, use the --debug flag:

    repo-to-text --debug
    

    or to save the debug log to a file:

    repo-to-text --debug > debug_log.txt 2>&1
    
  • input_dir: Specify the directory to process. If not provided, the current directory (.) will be used. For example:

    repo-to-text /path/to/input_dir
    
  • --stdout: Output the generated text to stdout instead of a file. This is useful for piping the output to another command or saving it to a file using shell redirection. For example:

    repo-to-text --stdout > myfile.txt
    

    This will write the output directly to myfile.txt instead of creating a timestamped file.

Settings

repo-to-text also supports configuration via a .repo-to-text-settings.yaml file. By default, the tool works without this file, but you can use it to customize what gets included in the final text file.

Creating the Settings File

To create a settings file, add a file named .repo-to-text-settings.yaml at the root of your project with the following content:

# Syntax: gitignore rules

# Ignore files and directories for all sections from gitignore file
# Default: True
gitignore-import-and-ignore: True

# Ignore files and directories for tree
# and "Contents of ..." sections
ignore-tree-and-content:
  - ".repo-to-text-settings.yaml"
  - "examples/"
  - "MANIFEST.in"
  - "setup.py"

# Ignore files and directories for "Contents of ..." section
ignore-content:
  - "README.md"
  - "LICENSE"
  - "tests/"

You can copy this file from the existing example in the project and adjust it to your needs. This file allows you to specify rules for what should be ignored when creating the text representation of the repository.

Configuration Options

  • gitignore-import-and-ignore: Ignore files and directories specified in .gitignore for all sections.
  • ignore-tree-and-content: Ignore files and directories for the tree and "Contents of ..." sections.
  • ignore-content: Ignore files and directories only for the "Contents of ..." section.

Using these settings, you can control which files and directories are included or excluded from the final text file.

Wildcards and Inclusions

Using Wildcard Patterns

  • *.ext: Matches any file ending with .ext in any directory.
  • dir/*.ext: Matches files ending with .ext in the specified directory dir/.
  • **/*.ext: Matches files ending with .ext in any subdirectory (recursive).

If you want to include certain files that would otherwise be ignored, use the ! pattern:

ignore-tree-and-content:
  - "*.txt"
  - "!README.txt"

gitignore Rule to Ignore generated files

To ignore the generated text files, add the following lines to your .gitignore file:

repo-to-text_*.txt

Install Locally

To install repo-to-text locally for development, follow these steps:

  1. Clone the repository:

    git clone https://github.com/kirill-markin/repo-to-text
    cd repo-to-text
    
  2. Install the package with development dependencies:

    pip install -e .[dev]
    

Requirements

  • Python >= 3.6
  • Core dependencies:
    • setuptools >= 70.0.0
    • pathspec >= 0.12.1
    • argparse >= 1.4.0
    • PyYAML >= 6.0.1

Development Dependencies

For development, additional packages are required:

  • pytest >= 8.2.2
  • black
  • mypy
  • isort
  • build
  • twine

Running Tests

To run the tests, use the following command:

pytest

Uninstall

To uninstall the package, run the following command from the directory where the repository is located:

pip uninstall repo-to-text

Contributing

Contributions are welcome! If you have any suggestions or find a bug, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

This project is maintained by Kirill Markin. For any inquiries or feedback, please contact markinkirill@gmail.com.

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

repo_to_text-0.5.2.tar.gz (123.6 kB view details)

Uploaded Source

Built Distribution

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

repo_to_text-0.5.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file repo_to_text-0.5.2.tar.gz.

File metadata

  • Download URL: repo_to_text-0.5.2.tar.gz
  • Upload date:
  • Size: 123.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for repo_to_text-0.5.2.tar.gz
Algorithm Hash digest
SHA256 a7cad1d4eff17ab8e7025156070c3d92a6645516f6c9b4cb5fb273d8af02018b
MD5 fb905a6f232925f41fb35079e9d5e15d
BLAKE2b-256 9474642aaaa71726e53916e4a7bbc71f34f4c5d16f34edc528db8adabdca31b3

See more details on using hashes here.

File details

Details for the file repo_to_text-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: repo_to_text-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for repo_to_text-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 76311e920093f873dfeea86ea5204ea3907a71836efcd0e1ad2c568c31fdde84
MD5 54bff44ba85645aaaf225a3203a72547
BLAKE2b-256 bd17723deff415dcbb2ca11a48aabc596beabb80d2166f41de9089aaf11a5e3a

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