Skip to main content

Jinja Recursive Templating from the CLI

Project description

jinjarecurse CLI tool


PyPI GitHub Workflow Status GitHub PyPI - Downloads


Jinja Recursive Templating for the CLI. Recursively template one file or many folders of many files like a config management languages allow, without the whole config management language. Useful if you're switching from managing an application from config management to just docker and need some simple templating logic.

Installation

pip install jinjarecurse

Example Usage

$ jinjarecurse --help
 jinjarecurse (CLI)

Usage:
    jinjarecurse --vars=VARS_FILE --input=INPUT_PATH --output=OUTPUT_PATH

Options:
    -v <file>, --vars   <file>
    -i <file>, --input  <file>
    -o <file>, --output <file>

Single file

Given a config file containing your variables e.g. vars.yaml:

#comment: not available
root: /
number: 1
dictionary:
    street: 123 North Ave
    city: New York
    state: New York
list:
    - ABC
    - DEF
    - HJK
layer_1:
    layer_2:
        layer_3: last

And an input file jinja2 template e.g. i_file:

# Top level
{{root}}
{{number}}
{{dictionary}}
{{list}}
{{layer_1}}

# Nested data

{{dictionary.street}}
{{dictionary.city}}
{{dictionary.state}}
{{layer_1.layer_2.layer_3}}

You can populate it and specify an output filepath e.g. o_file:

$ jinjarecurse -v example/vars.yaml -i example/i_file -o example/o_file
WARNING: example/o_file (output) exists and any conflicting files will be overwritten
Writing from example/i_file to example/o_file

Contents of the output file e.g. o_file:

# Top level
/
1
{'street': '123 North Ave', 'city': 'New York', 'state': 'New York'}
['ABC', 'DEF', 'HJK']
{'layer_2': {'layer_3': 'last'}}

# Nested data

123 North Ave
New York
New York
last

Directory

You can also template an entire directory e.g. i_dir at once. Note the output files in the output directory will maintain the filenames from the input directory:

$ jinjarecurse -v example/vars.yaml -i example/i_dir -o example/o_dir
Writing from example/i_dir/i_file to example/o_dir/i_file
Writing from example/i_dir/i_file_1 to example/o_dir/i_file_1
Writing from example/i_dir/i_file_2 to example/o_dir/i_file_2

Tests

To run the unit tests, first install the dependencies:

$ pipenv install --dev .

Then invoke pytest:

$ pipenv run py.test -vvvs

Changelog

Please see the Releases and CHANGELOG.md.

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

jinjarecurse-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

jinjarecurse-0.0.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file jinjarecurse-0.0.3.tar.gz.

File metadata

  • Download URL: jinjarecurse-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for jinjarecurse-0.0.3.tar.gz
Algorithm Hash digest
SHA256 231786f104f2d9ab7fcaa6a07f73cf6d13fdd6ebd033ad2073e24a521db1e68d
MD5 bd34df8ace395145f6c0cd10c3525c57
BLAKE2b-256 fe310184376acb2a2b74bf3c6d7121bf78672174599437ebe39b60fc9a7df521

See more details on using hashes here.

File details

Details for the file jinjarecurse-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jinjarecurse-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for jinjarecurse-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ddac487f8db514b6605a69bf89796b230e61891e84bcca3163768ed701354ace
MD5 93db4b57ff66903adb760909601d0d1f
BLAKE2b-256 7c257569ecdd8353be30a178a67e180a74af0c794d42712ce094cbcb956ffa65

See more details on using hashes here.

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