Skip to main content

(graph).

Project description

NOTE: The scope of this project is COMPLETE. Please do not send feature requests.

Hecto(graph)

Coverage Status Tests

A small and simple library for rendering projects templates.

  • 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 copy

# Create a project from a local path
copy('path/to/project/template', 'path/to/destination')

# 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/"
copy('https://github.com/jpscaletti/hecto.git', 'path/to/destination')
copy('gh:jpscaletti/hecto.git', 'path/to/destination')
copy('gl:jpscaletti/hecto.git', 'path/to/destination')

How it works

The content of the files inside the project template are copied to the destination without changes, unless are suffixed with the extension '.tmpl'. (you can customize that with the render_as setting). In that case, the templating engine is used to render them.

A slightly customized Jinja2 templates are used. The main difference is that variables are referenced with [[ name ]] instead of {{ name }} and blocks are [% if name %] instead of {% if name %}. To read more about templating see the Jinja2 documentation.

Use the data argument to pass whatever extra context you want to be available in the templates. The arguments can be any valid Python value, even a function.

API

hecto.copy()

hecto.copy(
    src_path,
    dst_path,

    data=DEFAULT_DATA,
    *,
    exclude=DEFAULT_EXCLUDE,
    include=[],
    skip_if_exists=[],
    envops={},
    render_as=DEFAULT_RENDER_AS,

    pretend=False,
    force=False,
    skip=False,
    quiet=False,
)

Uses the template in src_path to generate a new project at dst_path.

Arguments:

  • src_path (str):
    Absolute path to the project skeleton. May be a version control system URL.

  • dst_path (str):
    Absolute path to where to render the project template.

  • data (dict):
    Optional. Data to be passed to the templates.

  • exclude (list of str):
    Optional. A list of names or shell-style patterns matching files or folders that must not be copied.

  • include (list of str):
    Optional. A list of names or shell-style patterns matching files or folders that must be included, even if its name is a match for the exclude list. Eg: ['.gitignore']. The default is an empty list.

  • skip_if_exists (list of str):
    Optional. Skip any of these file names or shell-style patterns, without asking, if another with the same name already exists in the destination folder. It only makes sense if you are copying to a folder that already exists.

  • envops (dict):
    Optional. Extra options for the Jinja template environment.

  • render_as (function):
    An optional hook that takes the absolute source path and the relative destination path of a file as arguments.

    It should return None if the file must be copied as-is or a Path object of the new relative destination (can be the same as the one received).

    By default all the files with the .tmpl postfix are rendered and saved without that postfix. Eg: readme.md.tmpl becomes readme.md.

  • pretend (bool):
    Optional. Run but do not make any changes

  • force (bool):
    Optional. Overwrite files that already exist, without asking

  • skip (bool):
    Optional. Skip files that already exist, without asking

  • quiet (bool):
    Optional. Suppress the status output

The hecto.yaml file

If a YAML file named hecto.yaml is found in the root of the project, it will be read and used for arguments defaults.

Note that they become just the defaults, so any explicitly-passed argument will overwrite them.

# Shell-style patterns files/folders that must not be copied.
exclude:
  - "*.bar"
  - ".git"
  - ".git/*"

# Shell-style patterns files/folders that *must be* copied, even if
# they are in the exclude list
include:
  - "foo.bar"

# Shell-style patterns files to skip, without asking, if they already exists
# in the destination folder
skip_if_exists:
  - ".gitignore"

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-1.191025.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

hecto-1.191025-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hecto-1.191025.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for hecto-1.191025.tar.gz
Algorithm Hash digest
SHA256 2369145a5abb8833afb2089e60b7ab3437efa521a1bd48c1133b952a9b2b7600
MD5 23ef59087d961cc648f4a20ab0f1b6e6
BLAKE2b-256 ffee30c1e2107997c047a677606ef73eb5c61349eb5090afe29fe558d61c2e7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hecto-1.191025-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for hecto-1.191025-py3-none-any.whl
Algorithm Hash digest
SHA256 9cbc9b41fa278017a85ebe828cb3836689faea2d42a009f7eb53fb7b0c2ad294
MD5 778c2f594daeac72e32b133f38e5c9dc
BLAKE2b-256 9f857241112c4448197d07095f91f890b76cd389e127a32c0f54a853cadc4e4d

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