Skip to main content

Takes a folder path and outputs a text representation of the folders and files, supports ignore files.

Project description

Folder Tree Generator

PyPI version

Test

codecov

Folder Tree Generator is a Python module that generates a text representation of the folders and files in a given directory. It supports ignore files, such as .gitignore, to exclude certain files or folders from the output.

Typical string output:

my_project/
|-- .gitignore
|-- main.py
|-- utils.py
|-- data/
|   |-- input.txt
|   |-- output.txt

Why?

This tool was created to generate folder structures in a standard text format that could be copied and pasted into an LLM without including all the build artifacts, e.g., repository structures for code analysis. If you want to create your own ignore file, it should be a simple adaptation of a .gitignore file. In 90% of use cases, the existing repo's .gitignore file is sufficient.

Installation

You can install the module from PyPI using pip:

pip install folder-tree-generator

or via Poetry:

poetry add folder-tree-generator

Usage

You can use the module as a command-line tool or import it in your Python script.

Command-line usage

python folder_tree_generator /path/to/your/folder --report_file_path report.txt --ignore_file_path /path/to/your/ignore_folder/.gitignore

Python script usage

from folder_tree_generator import generate_tree

output_text = generate_tree("/path/to/your/folder", ignore_file_path="/path/to/your/ignore_folder/.gitignore")
print(output_text)

Configuration

You can change the ignore file name by passing an optional argument to the generate_tree function:

output_text = generate_tree("/path/to/your/folder", ignore_file_path="/path/to/your/folder/.myignore")

Optional Parameters

  • --report_file_path: The name of the report file. Defaults to report.txt if not provided.
  • --ignore_file_path: The path to the ignore file. If provided, the script will parse the ignore patterns from the file and exclude the matching files and folders from the report.

Development

To set up the development environment, clone the repository and install the required dependencies using Poetry:

git clone https://github.com/seandearnaley/folder-tree-generator.git
cd folder-tree-generator
poetry install

To run the tests, use the following command:

poetry run pytest

Checking Test Coverage

This project uses the pytest-cov package to generate test coverage reports. Here's how to use it:

  1. First, you need to install the pytest-cov package if it's not already installed.
pip install pytest-cov

or

poetry add pytest-cov

If you're using Poetry, you can also add pytest-cov to your pyproject.toml file and run poetry install to install it.

  1. After installing pytest-cov, you can use it to run your tests and collect coverage data. If you're using pytest for testing, you can use the following command:
pytest --cov=folder_tree_generator

This command tells pytest to collect coverage data for the folder_tree_generator module during the test run.

  1. Once you've collected coverage data, you can generate a report by running:
coverage report

This will print a coverage report to the terminal, showing the code coverage for each module in your project.

  1. If you want a more detailed view, you can generate an HTML report using:
coverage html

This will generate an htmlcov directory in your project directory. Inside this directory, you'll find an index.html file. You can open this file in a web browser to view a detailed coverage report that shows which lines of each file were covered by the tests.

  1. If you're finished checking coverage and want to clear the collected data, you can use the command:
coverage erase

This will delete the .coverage data file, clearing the collected coverage data.

Remember that code coverage is a useful tool for finding untested parts of your code, but achieving 100% code coverage doesn't necessarily mean your testing is perfect. It's important to write meaningful tests and not just strive for high coverage percentages.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.

License

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

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

folder_tree_generator-0.1.14.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

folder_tree_generator-0.1.14-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file folder_tree_generator-0.1.14.tar.gz.

File metadata

  • Download URL: folder_tree_generator-0.1.14.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.10 Darwin/22.5.0

File hashes

Hashes for folder_tree_generator-0.1.14.tar.gz
Algorithm Hash digest
SHA256 77cc16fad78c0fd20f5cbf604040ce3452c970ebb5f060e88bd9215866125cfe
MD5 9b1ed7c00886fa6f3ac310dda9a532a9
BLAKE2b-256 71758dce6dc573a74ac0d78add99c6043a285f90c0413047d18594d34cb0d275

See more details on using hashes here.

File details

Details for the file folder_tree_generator-0.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for folder_tree_generator-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8cd9c80f6f1dd14e922d4876ace9da23c7ad15c225889250bcfaadb06f5ccc
MD5 4ab2c3e3670940bb8fa789e661d06de8
BLAKE2b-256 6b41cc84695c02ca616d4e2e5bee16f7a09798eb74e974263cc2f411646f6c0e

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