Skip to main content

Fork of cookiecutter - https://github.com/cookiecutter/cookiecutter The most popular command-line utility to create projects from project templates, e.g. creating a Python package project from a Python package project template.

Project description

nukikata

Japanese for cookiecutter: クッキーの抜き型 - Kukkī no nukikata | Direct translation: To shape or mold

pypi python Build Status codecov

Fork of

Cookiecutter

github.com/cookiecutter/cookiecutter with additional features including:

  • Loops
  • Conditionals
  • Plugins

Inspired by Ansible's syntax, this project aims to be a config driven CLI with a plugins based rendering and hooking capabilities.

Quick Demo

pip3 install nukikata
nukikata https://github.com/insight-infrastructure/nukikata-demo-monty
curl https://raw.githubusercontent.com/insight-infrastructure/nukikata-demo-basic/master/nuki.yaml
cat output.json

Features

All cookiecutter features are supported in addition to loops, conditionals, and plugins. These features are only available to supplied dictionary objects with a type key to trigger the associated operator. Loops and conditionals are triggered by rendering jinja expressions per the example below.

nuki.yaml

---
name:
  type: input
  message: What is your name?

colors:
  type: checkbox
  message: What are your favorite colors?
  choices:
    - name: blue
    - name: green
    - name: grey

wingspeed:
  type: list
  message: What is the airspeed velocity of an unladen swallow??
  choices:
    - name: I donno
    - name: What do you mean? African or European swallow?

bad_outcome:
  type: print
  statement: Wrong answer {{ nuki.name }}...
  when: "{{ 'I donno' in nuki.wingspeed }}"

color_essays:
  type: input
  message: Please tell me how much you like the color {{nuki.item}}?
  default: Oh color {{nuki.item}}, you are so frickin cool...
  loop: "{{ nuki.colors }}"
  when: "{{ nuki.colors|length > 1 }}"

democmd:
  type: command
  command: pwd

dump_json:
  type: json
  contents: "{{ nuki }}"
  path: output.json

Here the jinja default context key goes to the name of file - ie {{ nuki.<> }}

Prompts are enhanced by extending the functionality from PyInquirer as a set of operators as noted by the types input, list, and checkbox. Writing new operators is super simple as seen in the print operator:

cookiecuttuer/operators/print.py

class PrintOperator(BaseOperator):
    """Operator for PyInquirer type prompts."""

    type = 'print'

    def __init__(self, operator_dict, context=None, no_input=False):
        """Initialize PyInquirer Hook."""
        super(PrintOperator, self).__init__(
            operator_dict=operator_dict, context=context, no_input=no_input
        )

    def execute(self):
        """Run the prompt."""
        print(self.operator_dict['statement'])
        return self.operator_dict['statement']

New operator PRs welcome. We're aiming to interface with various APIs and popular libraries to create simple ways to conditionally call and loop through popular methods.

Operators

Numerous operators are currently available with more coming down the line. Below is a current list of operators.

Note: This is a WIP. API docs will be generated with sphinx soon to cover the operators.

The main type of operator being used are derivations of PyInquirer which greatly enhanced the capabilities of the original cookiecutter due to the ability to use multi-select inputs that return lists. Please inspect the PyInquirer API docs to understand the interface. All features are supported except for validation and filter which is not supported and when which is implemented in jinja.

Here is a short list of the operators currently supported.

PyInquirer

All PyInquirer operators require message input

Python wrappers

  • command
    • Execute an arbitrary shell command
    • Outputs stdout as string
  • jinja
    • Takes template as path and renders to path
    • Inputs
      • template_path - string
      • output_path - string
    • Outputs None
  • json
    • Writes json to file if contents key supplied
    • Reads json from file
    • Requires path to output file
    • Outputs path to outputs or dict
  • nukikata
    • Wraps calls to other nukikatas
    • Outputs project_dir
  • print
    • Prints the statement
    • Outputs statement parameter
    • Useful for intermediary rendering
  • stat
    • Reinserts input parameter to the variable
    • Useful for intermediary rendering
  • yaml
    • Same as json operator

Note to Users and Developers

This is a very early WIP but has long term ambitions of being a sort of swiss army knife for management of configuration files and boilerplate. Please consider contributing or leaving your comments in the issues section on where you see this project going and what features you would like added. All future improvements are being migrated into github issues from a local ttd file.

This project intends on being an edge release of cookiecutter and would not have been possible were it not for the orginal maintainers of that repository. Development in this repository is meant to be a proving ground for features that could be implemented and merged into the original cookiecutter repository. Please consider supporting both projects.

Windows will not be supported and hence certain features will likely only exist in this repo compared to the original. This tool was built to handle the mountains of configuration files normally dealt with in declarative infrastructure deployments.

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

nukikata-1.7.2.5.tar.gz (161.3 kB view hashes)

Uploaded Source

Built Distribution

nukikata-1.7.2.5-py2.py3-none-any.whl (49.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page