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
Fork of
- Documentation: https://cookiecutter.readthedocs.io
- GitHub: https://github.com/cookiecutter/cookiecutter
- PyPI: https://pypi.org/project/cookiecutter/
- Free and open source software: BSD license
Cookiecutter is the worlds most popular code scaffolding tool with over 4 thousand open source cookiecutters available today. This fork includes many additional features including:
- Loops
- Conditionals
- Plugins
Inspired by Ansible's syntax, this project aims to be a flexible declarative CLI that is easy to write operators for to extend functionality. It was originally built to extend cookiecutter to include conditionals and loops in the configuration file format. We are now looking at it as an upstream declarative CLI sandbox to prove out patterns that can either be integrated back into cookiecutter or fit a variety of other use cases.
Quick Demo
Broken - Updating 7/20/2020
pip3 install nukikata
nukikata https://github.com/insight-infrastructure/nukikata-demo-monty --directory demos/monty-python
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.<> }}
but work is being done on maintaining a namespacing convention when stitching other cookiecutters together.
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):
type = 'print'
def __init__(self, *args, **kwargs): # noqa
super(PrintOperator, self).__init__(*args, **kwargs)
def _execute(self):
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
checkbox
- Multi-select list
- Inputs
choices
- list of dicts withname
as choice. See example above.
- PyInquirer Example
- Outputs list
confirm
- Verification
- PyInquirer Example
- Outputs boolean
editor
- Opens up editor
- PyInquirer Example
- Outputs string
expand
- Path completion to local file
- PyInquirer Example
- Outputs string
input
- Simple input with question
- PyInquirer Example
- Outputs string
list
- Single select from list
- PyInquirer Example
- Outputs string
rawlist
- Single select from list
- PyInquirer Example
- Outputs string
password
- Input that is hidden
- PyInquirer Example
- Outputs string
Python wrappers
command
- Execute an arbitrary shell command
- Outputs stdout as
string
jinja
- Takes template as path and renders to path
- Inputs
template_path
- stringoutput_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
- Writes json to file if
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
- Reinserts
yaml
- Same as
json
operator
- Same as
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for nukikata-2.0.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 313619ac19b8d630ed0724f72dfe22798c58b3dac02c784f0d27425b241549a7 |
|
MD5 | 3dd19370d7a31a5437781ee545124149 |
|
BLAKE2b-256 | fc5197b967a94d6ec4f597350fcedbba6cea9cef7cd1fc90f3fb2a9b9e418911 |