CLOPY(1)

NAME
clopy - clopy 0.1.12

Clopy is a general purpose templating program designed to quickly setup projects and files. It is highly customizable right down to the prompts used to generate the files.

INSTALL

To install Clopy from PyPI use pip:

pip install clopy

QUICKSTART

To use Clopy, you must define a template.py file in your template directory. This file is used by Clopy to hook into your template to allow you to specify prompts and files that will be copied over to the new directory.

Here is a sample file:

# template.py
def bang(fp, cmd):
    license = input('What license will you use? [MIT or GPLv3]? : ')
    licensedict = {
        'license': license
    }
    tmpls = {
    'LICENSE': licensedict
    }
    # Initialize all templates
    outputs = init_all(fp, tmpls)
    # Output all files
    for name, out in outputs.items():
        output(path, name, out)

The only requirements for the template.py file are that:

•   The template file is named exactly template.py

•   There exists the following function in template.py:

    def bang(fp, cmd)

    The template file is a Jinja template that is initialized with the values of the user input at runtime.

COMMANDS

To use a template to create a new project run:

clopy new [filepath/to/template]

To initialize a template into the current directory run:

clopy init [filepath/to/template]

CONFIG

Clopy can be configured to use a templates.json file to read template file paths from as a shorthand. This file is stored in the ~/.config/clopy/templates directory. An example config file is given in the root project directory.

{
    "templates": {
        "python": "~/Templates/python-template"
    }
}

Now instead of doing this:

clopy new ~/Templates/python-template

You can run

clopy new python

And Clopy will look up the directory associated with the directory keyword.

  Configuring Templates

Templates can also have configuration files. These files are located in ~/.config/clopy/templates/`. These configuration files are stored in TOML format that you can use to define your own configuration variables for your templates.

API

  Clopy.Tmpl

clopy.tmpl.init_all(fp: str, tmpls: dict) -> dict
    Renders all file templates, and returns the output files

clopy.tmpl.loadcfg(cfp: str, cfg: dict) -> dict
    Loads the given config file for a template cfp: Config file path cfg: Default/Empty config file dictionary

    loadcfg reads the contents of cfp into a dictionary, and returns the config file as a dict if it exists, and returns cfg if the dict doesn't exist.

clopy.tmpl.match(s: str, choices: list) -> bool
    Checks if a str matches the given choices

clopy.tmpl.mkdest(path: pathlib.Path, cmd: str)
    Initializes or overwrites the destination directory

clopy.tmpl.output(dest: str, tmpl_name: str, tmpl: str)
    Outputs the rendered template contents to the destination dest: File path/directory of the template output tmpl_name: Name of the destination file where the output will be written to tmpl: The contents of the file

clopy.tmpl.promptf(prompt: str, val='') -> str
    Prompts the user with the given message and defaults to a set value if null

clopy.tmpl.render(src: str, tmpl_name: str, vardict: dict) -> str
    Renders the template file src: File path/directory of the template source tmpl_name: Name of the template file source vardict: A dictionary that contains the template variable names as keywords with.

clopy.tmpl.to_path(fp: str) -> pathlib.Path
    Convert str to Path

•   genindex

•   modindex

•   search

AUTHOR
Joseph Diza

COPYRIGHT
2022, Joseph Diza