Takes a folder path and outputs a text representation of the folders and files, supports ignore files.
Project description
Folder Tree Generator
Folder Tree Generator is a Python module that takes a folder path and outputs a text representation of the folders and files. 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?
I needed a way to generate folder structures in a standard text format that I could copy and paste into GPT without including all the build artifacts, eg. repository structures for code analysis. If you wanted to make your own ignore file it should be a simple adapation of a gitignore file, in 90% of my use cases, the gitignore 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 -m folder_tree_generator/folder_tree_generator /path/to/your/folder
Python script usage
from folder_tree_generator import generate_tree
output_text = generate_tree("/path/to/your/folder")
print(output_text)
Configuration
By default, the module looks for a .gitignore
file in the root folder to determine which files and folders to ignore. 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_name=".myignore")
Optional Parameters
--report_file_path
: The name of the report file. Defaults toreport.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 coverage
package to generate test coverage reports. Here's how to use it:
- First, you need to install the
coverage
package if it's not already installed.
pip install coverage
or
poetry add coverage
If you're using Poetry, you can also add coverage
to your pyproject.toml
file and run poetry install
to install it.
- After installing
coverage
, you can use it to run your tests and collect coverage data. If you're usingpytest
for testing, you can use the following command:
coverage run -m pytest
This command tells coverage
to run pytest
as a module (hence the -m
flag), and coverage
collects data about which parts of your code were executed during the test run.
- 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.
- 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.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for folder_tree_generator-0.1.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ede51df0a21deacf4ee6fdc525105cf7a169431c62f409826a07588a6bd1f69d |
|
MD5 | 13554d987bc0c351cd85057782f52b8f |
|
BLAKE2b-256 | f0f0b9d85d76b4d3769ae284bdfa85435fcfa98fb52f50a53a4eca0ec7063401 |
Hashes for folder_tree_generator-0.1.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 566592f7e60e771be33f0141ddd437d40549d053cd22416b183dfefd831bfd1f |
|
MD5 | f23f5bd15877ad8b309836ae9034fb69 |
|
BLAKE2b-256 | 6008c953fa0c252914e87ce12d8b223d6f9ea86826cbaa44534354c654a85a6b |