Skip to main content

Create directory trees from a tree specification

Project description

mktree

Create directory trees from a simple text specification. Quickly scaffold project structures, create nested directories, and generate files with comments—all from a single tree description.

Installation

pip install modularizer mktree

Quick Start

Command-Line Usage (recommended)

Just run mktree and you will get prompted to input the tree, or you can pass it in as the first arg

mktree

Python

from mktree import TreePath

if __name__ == "__main__":
    t = TreePath.from_tree("""
    my_project/
        src/
            my_project/
                __init__.py  # This
                __main__.py  # This runs when you call `python -m src.%my_project%`
                my_project.py
                cli.py
    """, my_project="soup").mktree()

Command-Line Options

  • --dst PATH: Set the root path for the tree (relabels the root)
  • --parent PATH: Wrap the tree in a parent directory
  • -y, --yes: Automatically use default path without prompting
  • --indent-size N: Set indentation size (default: 2)
  • --mode MODE: Set file permissions in octal (default: 777)
  • --no-parents: Don't create parent directories
  • --no-exist-ok: Don't ignore existing directories
  • NOTE: If neither --dst nor --parent is specified, mktree will prompt you for where to create the folder, showing a default based on the first root in your tree, unless you specify -y

From Command Line

mktree "my_project/
  src/
    __init__.py
  tests/
    test_main.py"

From File

mktree < tree.txt

Tree Specification Format

The tree specification supports multiple formats. mktree automatically detects the format based on the input:

Format 1: Indentation-Based (Default)

my_project/
  src/
    __init__.py
    main.py              # This comment will be written as a docstring at the top of main.py
  tests/
    __init__.py
    test_main.py         # Unit tests
  README.md              # Project documentation
  setup.py

Format 2: Unicode Box-Drawing Characters

├── my_project/
│   ├── src/
│   │   ├── __init__.py
│   │   └── main.py              # This comment will be written as a docstring at the top of main.py
│   └── tests/
│       ├── __init__.py
│       └── test_main.py         # Unit tests
├── README.md                     # Project documentation
└── setup.py

Format 3: ASCII Box-Drawing Characters

+-- my_project/
|   +-- src/
|   |   +-- __init__.py
|   |   \-- main.py
|   \-- tests/
|       \-- test_main.py
\-- README.md

Format 4: Prefix Markers

+ my_project/
+ src/
  - __init__.py
  - main.py              # Main entry point
+ tests/
  - __init__.py
  - test_main.py         # Unit tests
- README.md              # Project documentation
- setup.py

Format 5: JSON

{
  "my_project/": {
    "src/": {
      "__init__.py": null,
      "main.py": null
    },
    "tests/": {
      "__init__.py": null,
      "test_main.py": null
    },
    "README.md": null,
    "setup.py": null
  }
}

Format 6: Git ls-tree Format

Git tree format (like git ls-tree -r --name-only):

040000 tree my_project/
040000 tree my_project/src/
100644 blob my_project/src/__init__.py
100644 blob my_project/src/main.py
040000 tree my_project/tests/
100644 blob my_project/tests/__init__.py
100644 blob my_project/tests/test_main.py
100644 blob my_project/README.md
100644 blob my_project/setup.py

Note: mktree automatically detects the format based on the input. You can mix formats in different files, but each individual input should use a single format.

This creates:

my_project/
├── src/
│   ├── __init__.py
│   └── main.py
├── tests/
│   ├── __init__.py
│   └── test_main.py
├── README.md
└── setup.py

Examples

Example 1: Simple Project Structure

mktree "project/
  src/
    __init__.py
    app.py
  tests/
    test_app.py
  README.md"

Interactive Mode

Run without arguments to enter interactive mode:

$ mktree
Enter tree specification (end with Ctrl+D or empty line):
my_project/
  src/
    main.py
  tests/
    test_main.py
^D
Make at path: [./my_project] 
Created tree at: ./my_project

Requirements

  • Python 3.8 or higher
  • No external dependencies

License

Unlicense (Public Domain)

Contributing

Contributions welcome! Please feel free to submit issues or pull requests.

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

modularizer_mktree-0.2.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

modularizer_mktree-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file modularizer_mktree-0.2.0.tar.gz.

File metadata

  • Download URL: modularizer_mktree-0.2.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modularizer_mktree-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b62b0e2fdc9fd8177c3264d1df23266e119e1e8ad67e4ddad3c37daf5d3bb13e
MD5 5d68ef08f4888dcf9c675cc52234e650
BLAKE2b-256 8a9e319a9af157df42d3c6a094df0ba83aa36f2da9c1700ed7613f1b35a5bdcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularizer_mktree-0.2.0.tar.gz:

Publisher: publish.yml on modularizer/mktree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularizer_mktree-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modularizer_mktree-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7caab09a2cdc9b1e306f97d0b31ac16869bcb21658930c5c6bbf372042670593
MD5 d2af2a09a266b4f205516b471d63de73
BLAKE2b-256 80001ea1077706f1ae85b7cd1f13e1f8a111b8d6ffcbf9ad1c393f86bb27762b

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularizer_mktree-0.2.0-py3-none-any.whl:

Publisher: publish.yml on modularizer/mktree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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