Skip to main content

A small library for rendering blueprints of projects

Project description

Hecto(graph)

A small library for rendering blueprints of projects.

  • Works with local paths and git URLs.
  • Your project can include any file and Hecto can dynamically replace values in any kind of text files.
  • It generates a beautiful output and take care of not overwrite existing files, unless instructed to do so.

How to use

pip install hecto
from hecto import render_blueprint

# Create a project from a local path
render_blueprint('path/to/project/template', 'path/to/destination', context={"foo": "bar"})

# Or from a git URL.
# You can also use "gh:" as a shortcut of "https://github.com/"
# Or "gl:"  as a shortcut of "https://gitlab.com/"
render_blueprint('https://github.com/jpsca/base36.git', 'path/to/destination')
render_blueprint('gh:jpsca/base36.git', 'path/to/destination')
render_blueprint('gl:jpsca/base36.git', 'path/to/destination')

# You can also specify a subfolder inside the repo using `#` as a separator:
render_blueprint('gh:jpsca/base36.git#blueprint/new', 'path/to/destination')

How does it works

For each file, if the file has a .tt, .append, or .prepend extension, even if the extension is not the last one, like *.tt.py, it will be treated as a template file and rendered with the provided context.

  • .tt files will be rendered and saved to its destinations.
  • .append files will be rendered and appended to its destinations.
  • .prepend files will be rendered and prepended to its destinations.
  • Other files will be copied as-is.

To be able to work with regular Jinja files, the files are rendered using [[ and ]] instead of {{ and }}; and [% and %] instead of {% and %}. You can also use these delimiters in your file names.

If the files already exists and force is False, you will be asked for confirmation before overwriting them.

API

render_blueprint(...)

def render_blueprint(
    src: str | Path,
    dst: str | Path,
    context: dict[str, t.Any] | None = None,
    *,
    ignore: Sequence[str] = IGNORE,
    envops: dict | None = None,
    force: bool = False,
) -> None:
    """
    Renders a blueprint into a destination folder.

    For each file, if the file has a `.tt`, `.append`, or `.prepend` extension,
    even if the extension is not the *last one*, like `*.tt.py`, it will be treated
    as a template file and rendered with the provided context.

    * `.tt` files will be rendered and saved to its destinations.
    * `.append` files will be rendered and appended to its destinations.
    * `.prepend` files will be rendered and prepended to its destinations.
    * Other files will be copied as-is.

    To be able to work with regular Jinja files, the files are rendered using
    `[[` and `]]` instead of `{{` and `}}`; and `[%` and `%]` instead of `{%` and `%}`.
    You can also use these delimiters in your file names.

    If the files already exists and `force` is `False`, you will be asked for
    confirmation before overwriting them.

    Arguments:
        src:
            Path of the folder to render from, or URL of a git-based repository.
        dst:
            Destination path for the blueprint.
        context:
            Context variables for Jinja2 templates.
        ignore:
            List of file patterns to ignore.
            Default is (".DS_Store", "__pycache__", "*/__pycache__", "*/.DS_Store")
        envops:
            Jinja2 environment options.
        force:
            Whether to overwrite existing files without asking for confirmation.

    """
    ...

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

hecto-2.3.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

hecto-2.3.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file hecto-2.3.0.tar.gz.

File metadata

  • Download URL: hecto-2.3.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hecto-2.3.0.tar.gz
Algorithm Hash digest
SHA256 d0420511ff7c8475155ae00050173d478e009c5560059bad1bc975aa5a86ab34
MD5 5693d16cba1a3bd2818de25d37bac6dd
BLAKE2b-256 cf2fbb39b0fa0c90a977f002cdf3739b784c37a2c5e69037d53b51876e73e1fc

See more details on using hashes here.

File details

Details for the file hecto-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: hecto-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hecto-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd2c3fa03b8610189801f99c46d44572e53e7fef3211da486e93fda909857c61
MD5 105b4128a629bca0aab7d60382d4a73e
BLAKE2b-256 18028fdd2a18086fb0252f5fd7f90987947380394866488997827ba8ec5653e8

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