A tool for mapping directory structures
Project description
CLAUDE.md - TreeMapper
Project Overview
treemapper is a Python tool that converts directory structures to YAML format, designed specifically for use with Large Language Models (LLMs). It maps entire codebases into structured YAML files, making it easy to analyze code, document projects, and work with AI tools.
Installation
Requires Python 3.9+:
pip install treemapper
Development Environment
- Python 3.9+ required
- Package dependencies: pathspec, pyyaml
Building and Installation
# Install in development mode
pip install -e .
# Install with development dependencies
pip install -e ".[dev]"
# Build distribution package
python -m build
# Install from PyPI
pip install treemapper
Testing
# Run all tests
pytest
# Run specific test file
pytest tests/test_basic.py
# Run specific test
pytest tests/test_basic.py::test_basic_mapping
# Run tests with coverage
pytest --cov=src/treemapper
# Run tests in verbose mode
pytest -v
Linting and Formatting
# Run flake8 linter
flake8 src/treemapper
# Run black formatter
black src/treemapper
# Run type checking with mypy
mypy src/treemapper
# Run autoflake to remove unused imports
autoflake --remove-all-unused-imports -i src/treemapper/*.py
# Run pre-commit hooks on all files
pre-commit run --all-files
# Run isort (import sorting)
isort src/treemapper tests
Code Quality Tools
The project includes comprehensive code quality checks via CI and pre-commit hooks:
# Complexity analysis
radon cc src/treemapper/ --min B # Cyclomatic complexity
radon mi src/treemapper/ --min B # Maintainability index
# Mutation testing (test effectiveness)
mutmut run --paths-to-mutate=src/treemapper/
# Architecture checks (import contracts)
lint-imports
# Coverage reporting
pytest --cov=src/treemapper --cov-report=html
open htmlcov/index.html
CI/CD Workflows
The project has two CI/CD workflows:
-
Main CI (
.github/workflows/ci.yml): Comprehensive quality checks- Pre-commit hook validation (all hooks)
- Linting and type checking (flake8, black, mypy)
- Cross-platform testing (Linux, macOS, Windows)
- Python version matrix (3.9, 3.10, 3.11, 3.12)
- PyPy compatibility testing (pypy-3.9, pypy-3.10)
- Test coverage with 80% threshold and branch analysis
- Mutation testing (test effectiveness validation)
- Complexity and maintainability metrics (radon)
- Architecture/import contract validation (import-linter)
- SonarCloud quality gate (code quality analysis)
-
CD (Release) (
.github/workflows/cd.yml): Atomic releases- Version bump with git bundles
- Multi-platform binary builds (Linux, macOS, Windows)
- PyPI publishing (optional)
- GitHub release creation with assets
Project Architecture
The codebase is organized as follows:
src/treemapper/: Main packagetreemapper.py: Entry point and main orchestrationcli.py: Command-line argument parsingignore.py: Logic for handling ignore patterns (gitignore, treemapperignore)tree.py: Core tree building functionalitywriter.py: YAML output formatting and file writinglogger.py: Logging configuration
The application flow is:
- Parse command-line arguments (
cli.py) - Set up logging based on verbosity level (
logger.py) - Load ignore patterns from various sources (
ignore.py) - Build the directory tree structure (
tree.py) - Write the tree structure to a YAML file (
writer.py)
Usage
Generate a structured representation of a directory:
# Map current directory to stdout (YAML format)
treemapper .
# Map specific directory to stdout
treemapper /path/to/dir
# Save to a file
treemapper . -o my-tree.yaml
# Use "-" to explicitly output to stdout
treemapper . -o -
# Output in JSON format
treemapper . --format json
# Output in plain text format
treemapper . --format text -o output.txt
# Limit directory traversal depth
treemapper . --max-depth 3
# Skip file contents (structure only)
treemapper . --no-content
# Limit file size for content reading
treemapper . --max-file-bytes 10000
# Custom ignore patterns
treemapper . -i ignore.txt
# Disable all default ignores
treemapper . --no-default-ignores
# Combine multiple options
treemapper . -o tree.json --format json --max-depth 5 --max-file-bytes 50000
# Set verbosity level (0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG)
treemapper . -v 3
Options
treemapper [OPTIONS] [DIRECTORY]
Arguments:
DIRECTORY Directory to analyze (default: current directory)
Options:
-o, --output-file PATH Output file (default: stdout)
Use "-" to force stdout output
--format {yaml,json,text} Output format (default: yaml)
-i, --ignore-file PATH Custom ignore patterns file
--no-default-ignores Disable all default ignores (.gitignore, .treemapperignore, etc.)
--max-depth N Maximum depth to traverse (default: unlimited)
--no-content Skip reading file contents (structure-only mode)
--max-file-bytes N Maximum file size to read in bytes (default: unlimited)
Larger files will show a placeholder
-v, --verbosity [0-3] Logging verbosity (default: 0)
0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG
--version Show version and exit
-h, --help Show this help
Ignore Patterns
By default, treemapper ignores:
- The output file itself (when using
-o) - All
.gitdirectories - Python cache directories (
__pycache__,.pytest_cache,.mypy_cache, etc.) - Python build artifacts (
*.pyc,*.egg-info,dist/,build/, etc.) - Patterns from
.gitignorefiles (in the scanned directory and subdirectories) - Patterns from
.treemapperignorefile (in the scanned root directory) - Symbolic links (always skipped)
Use --no-default-ignores to disable all default ignores and only use patterns from -i/--ignore-file.
Example Output
YAML format (default):
name: my-project
type: directory
children:
- name: src
type: directory
children:
- name: main.py
type: file
content: |
def main():
print("Hello World")
- name: README.md
type: file
content: |
# My Project
Documentation here...
JSON format (--format json):
{
"name": "my-project",
"type": "directory",
"children": [
{
"name": "src",
"type": "directory",
"children": [
{
"name": "main.py",
"type": "file",
"content": "def main():\n print(\"Hello World\")\n"
}
]
},
{
"name": "README.md",
"type": "file",
"content": "# My Project\nDocumentation here...\n"
}
]
}
Text format (--format text):
================================================================================
Directory Tree: my-project
================================================================================
src/ (directory)
main.py (file)
--- BEGIN CONTENT ---
def main():
print("Hello World")
--- END CONTENT ---
README.md (file)
--- BEGIN CONTENT ---
# My Project
Documentation here...
--- END CONTENT ---
Creating a Distribution Package
# Build package
python -m build
# Create executable with PyInstaller
pyinstaller treemapper.spec
License
Apache License 2.0 - see LICENSE 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file treemapper-1.1.1.tar.gz.
File metadata
- Download URL: treemapper-1.1.1.tar.gz
- Upload date:
- Size: 39.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e51585af630ed78ed8579988ed10f02a7e5117bd3982d5aa8fb7dcb50cda462
|
|
| MD5 |
784527356352fc6938c874aa44efddc0
|
|
| BLAKE2b-256 |
e07bf478f1c5bdfb851760e8e9b98c94d50b445ae1757331f6c2d77d0104db6f
|
Provenance
The following attestation bundles were made for treemapper-1.1.1.tar.gz:
Publisher:
cd.yml on nikolay-e/treemapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treemapper-1.1.1.tar.gz -
Subject digest:
7e51585af630ed78ed8579988ed10f02a7e5117bd3982d5aa8fb7dcb50cda462 - Sigstore transparency entry: 731923117
- Sigstore integration time:
-
Permalink:
nikolay-e/treemapper@9e411c8ac7682de0992e947235aad6d713733367 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nikolay-e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@9e411c8ac7682de0992e947235aad6d713733367 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treemapper-1.1.1-py3-none-any.whl.
File metadata
- Download URL: treemapper-1.1.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
358beb671efd5f1833572de2fb5a9b65bb6519d1a09936894778e972ed6777a0
|
|
| MD5 |
726012af9a3ea446ffb81435abcd8cbb
|
|
| BLAKE2b-256 |
bb10eace8d21a49659ca05216589657d32a9e131ecfbf050c6b4daf42d201cb7
|
Provenance
The following attestation bundles were made for treemapper-1.1.1-py3-none-any.whl:
Publisher:
cd.yml on nikolay-e/treemapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treemapper-1.1.1-py3-none-any.whl -
Subject digest:
358beb671efd5f1833572de2fb5a9b65bb6519d1a09936894778e972ed6777a0 - Sigstore transparency entry: 731923118
- Sigstore integration time:
-
Permalink:
nikolay-e/treemapper@9e411c8ac7682de0992e947235aad6d713733367 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nikolay-e
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@9e411c8ac7682de0992e947235aad6d713733367 -
Trigger Event:
workflow_dispatch
-
Statement type: