A CLI tool for generating files from Jinja2 templates and environment variables.
Project description
A CLI tool for generating files from Jinja2 templates and environment variables. Tested on Python versions 2.7, 3.5 and later.
Examples
$ template -h
usage: template [-h] [-o OUTPUT] [filename]
A CLI tool for generating files from Jinja2 templates and environment
variables.
positional arguments:
filename Input filename
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output to filename
$ export name='John'
$ echo 'Hello {{ name if name is defined else 'world' }}. | template
Hello John.
$ echo '{{ USER }}' > username.j2
$ template --output username.txt username.j2
$ cat username.txt
John
Jinja filters
The following Jinja filters were added:
to_yaml
: Convert to yaml.from_yaml
: Convert from yaml.to_json
: Convert to json.from_json
: Convert from json.to_toml
: Convert to toml.from_toml
: Convert from toml.jmespath
: Queries data using the JMESPath query language.run
: Runs a command and returns the stdout, stderr and returncode using run.
Example usage can be seen in tests
and for specific filters in the
docstrings in template/filters.py
.
Testing
Tests require Python 3.7, pipenv and Bats. Run the tests with the following commands:
pipenv run lint # Pre-commit hooks.
pipenv run check # Twine check.
pipenv run doctest # Doc tests.
pipenv run bats # Bats tests.
Also, Travis CI is setup for this project so every push to this repository is checked with all supported Python versions.
Release
Release requires Python 3.7 and pipenv. To bump the
version run pipenv run bumpversion major|minor|patch
to update the
version and git commit and tag. Then run pipenv run upload
to upload the
new version to PyPI and git push --follow-tags
to push the git commit
and tag.
License
This software is licensed under the AGPL 3+ license (see the LICENSE.txt
file).
Pending tasks
Release on tagged commits to PyPI in Travis CI (https://docs.travis-ci.com/user/deployment/pypi/ and https://docs.travis-ci.com/user/encryption-keys/).
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 Distribution
Hashes for template-0.5.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b42335b40e4493f667c45ad6856e1478244014fd6ac6280ee71759f390ebf65a |
|
MD5 | 46fd75080d0bff44a2f91882b134ad49 |
|
BLAKE2b-256 | 33eb611e88ad9d0351fbccb3792a22c612a2b175b51854d03177a5b13f45bb6b |