Skip to main content

Generate an ASCII folder structure of a directory

Project description

Branchify Documentation ๐Ÿ“‚

Branchify generates an ASCII folder structure from any directory. Works for Python>=3.8

Documentation : Check out the documentation here: https://pypi.org/project/branchify/

Features

โœ… Command-line Interface (CLI) & Python API
โœ… Smart Ignoring of common directories and file types
โœ… Explicit Inclusions and Exclusions for directories or file patterns
โœ… Configurable File Limit (Depth) of the tree


Installation

pip install branchify

CLI Usage

1๏ธโƒฃ Generate a Folder Structure (Default)

branchify

2๏ธโƒฃ Specify a Directory

branchify --path my_project

3๏ธโƒฃ Ignore Specific Directories and Files

branchify --ignore node_modules venv --ignore-patterns '*.wav'

OR

branchify --i node_modules venv -ip '*.wav'

4๏ธโƒฃ Explicitly Include Some Directories or Files

branchify --include-dir logs --include-pattern '*.json'

OR

branchify -ind logs -inp '*.json'

5๏ธโƒฃ Set a Custom File Limit

branchify --depth 5

OR

branchify -d 5

6๏ธโƒฃ Save Output to a File

branchify --output structure.txt

OR

branchify -o structure.txt

7๏ธโƒฃ Update Branchify to the latest version

branchify --update

Python API Usage

from branchify.generator import FolderStructureGenerator

# Define customization options for the generator
ignores = {
    'directories': ['node_modules', 'venv', '.git', '__pycache__'],  # Custom directories to ignore
    'ignore_patterns': ['*.log', '*.tmp', '*.bak'],  # Custom file patterns to ignore
}

includes = {
    'directories': ['src', 'assets'],  # Directories to explicitly include
    'patterns': ['*.py', '*.js'],  # File patterns to explicitly include
}

# Custom file limit
file_limit = 25

# Initialize the FolderStructureGenerator with custom parameters
generator = FolderStructureGenerator(
    root_dir="/path/to/root",  # Set the root directory to start from
    ignores=ignores,  # Pass the custom ignores
    includes=includes,  # Pass the custom includes
)

# Override the default file limit
generator.file_limit = file_limit

# Generate and display the folder structure
print(generator.generate())

Default Ignored Files and Directories

The FolderStructureGenerator class comes with predefined settings that ignore certain files and directories when generating the folder structure. These settings can be customized by passing specific arguments during instantiation, but the default ignores are as follows:

Ignored Directories

The following directories are ignored by default:

  • node_modules: A directory commonly found in JavaScript projects, containing installed packages.
  • venv: A directory for Python virtual environments, which typically contains installed dependencies.
  • .git: The Git version control directory, containing internal Git configurations and histories.
  • __pycache__: A directory that stores Python bytecode files.
  • env: Another directory often used for Python virtual environments.
  • .vscode: The Visual Studio Code workspace settings folder.
  • .idea: The directory used by JetBrains IDEs (such as IntelliJ IDEA, PyCharm) for project-specific settings.
  • .svn: The Subversion version control directory, used for managing source code versions.
  • .DS_Store: A system file used by macOS to store folder-specific settings, typically hidden.
  • .mypy_cache: A directory used by MyPy (a static type checker for Python) to store cached information.
  • .pytest_cache: A directory used by pytest to cache results of tests to speed up repeated test runs.
  • __snapshots__: A directory often used for storing test snapshots in JavaScript or other testing frameworks.

Ignored File Patterns

The following file patterns are ignored by default:

  • *.pyc: Compiled Python files.
  • *.swp and *.swo: Temporary swap files created by text editors (like Vim).
  • *.toml: TOML files, typically used for configuration (e.g., pyproject.toml).
  • *.lock: Lock files, used by package managers (e.g., package-lock.json, Pipfile.lock).
  • *.log: Log files, often generated for debugging or runtime information.
  • *.yaml: YAML files, often used for configuration (e.g., docker-compose.yaml).
  • *.rst: ReStructuredText files, used for documentation.
  • *.ini: Configuration files using the INI format.
  • *.cfg: Another configuration file type.
  • *.out: Output files, often generated during builds or testing.
  • *.git and *.gitignore: Git-related files and directories used for version control management.

file_limit and Its Functionality

The file_limit is a setting within the FolderStructureGenerator class that restricts the number of files shown in the generated folder structure for a given directory. It can be modified within the cli with the --depth flag.

By default, the file_limit is set to 15. This means that if a directory contains more than 15 files, only the first 15 files will be displayed, and the rest will be represented by an ellipsis (...) at the end of the list.

This limit is applied as follows:

  • If a directory contains 15 or fewer files, all files will be shown.
  • If a directory contains more than 15 files, only the first 15 will be displayed, and the rest will be omitted to keep the output concise.

Sample Usage

Branchify Demo


Example Output

Pneumonia_Detection/
โ”œโ”€โ”€ .devcontainer/
โ”‚   โ””โ”€โ”€ devcontainer.json
โ”œโ”€โ”€ app/
โ”‚   โ””โ”€โ”€ app.py
โ”œโ”€โ”€ images_test/
โ”‚   โ”œโ”€โ”€ IM-0368-0001.jpeg
โ”‚   โ”œโ”€โ”€ NORMAL2-IM-0401-0001.jpeg
โ”‚   โ”œโ”€โ”€ NORMAL2-IM-0775-0001.jpeg
โ”‚   โ”œโ”€โ”€ NORMAL2-IM-1319-0001.jpeg
โ”‚   โ”œโ”€โ”€ NORMAL2-IM-1326-0001.jpeg
โ”‚   โ”œโ”€โ”€ person1712_bacteria_4529.jpeg
โ”‚   โ”œโ”€โ”€ person1729_bacteria_4557.jpeg
โ”‚   โ”œโ”€โ”€ person466_bacteria_1987.jpeg
โ”‚   โ”œโ”€โ”€ person630_bacteria_2512.jpeg
โ”‚   โ””โ”€โ”€ person896_virus_1548.jpeg
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ cnn_model.h5
โ”‚   โ”œโ”€โ”€ logistic_regression_model.pkl
โ”‚   โ””โ”€โ”€ pca_transformer.pkl
โ”œโ”€โ”€ notebooks/
โ”‚   โ””โ”€โ”€ pneumonia_detection.ipynb
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ requirements.txt

LICENSE

This project is licensed under the BSD License


Contributing

If you'd like to contribute to Branchify, please open an issue or a pull request at the repository, and if you find it helpful, do consider starring the repository!

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

branchify-1.0.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

branchify-1.0.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file branchify-1.0.3.tar.gz.

File metadata

  • Download URL: branchify-1.0.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for branchify-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b0c48004064eeeb88a81892ff5421c71698c48a012d277bd7007b95974590736
MD5 af55fbee71c1c5b85172bf866c949bb5
BLAKE2b-256 550c033f29d98d73d986daf2fca5b50bceb6a35f0d8ef7de816b1e9faf856f4e

See more details on using hashes here.

File details

Details for the file branchify-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: branchify-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for branchify-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3942e9c5def239bad908576c635f4070f389347e9244903d8cab984445dfe1d8
MD5 2da7b5f1b8493fb05e394b64c90786fc
BLAKE2b-256 b90e0fc0ade8c91c75b32bf4d22403cd2468328fd747fb81f1fc77b04f65ce1f

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