Skip to main content

A CLI tool for generating files from Jinja2 templates and environment variables.

Project description

https://git.shore.co.il/nimrod/template/badges/master/pipeline.svg

A CLI tool for generating files from Jinja2 templates and environment variables.

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 Pipenv and Bats. Run the tests with the following commands:

pipenv run lint  # Pre-commit hooks.
pipenv run doctest  # Doc tests.
pipenv run bats  # Bats tests.
pipenv run check  # Twine check.

Also, GitLab CI is setup for this project so every push to this repository is checked with all Python 2.7, Python 3.6 and later and all supported versions of PyPy.

Release

Release requires Pipenv. To bump the version run pipenv run bumpversion major|minor|patch to update the version and git commit and tag the changes, then run git push --follow-tags to push the git commit and tag. The GitLab CI will then build and upload a release to PyPI. To manually upload to PyPI run pipenv run build to build the Python package and pipenv run upload -s dist/* to upload a signed version.

License

This software is licensed under the AGPL 3+ license (see the LICENSE.txt file).

Author

Nimrod Adar, contact me or visit my website. Patches are welcome via git send-email. The repository is located at: https://git.shore.co.il/nimrod/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

template-0.6.4-py2.py3-none-any.whl (17.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file template-0.6.4-py2.py3-none-any.whl.

File metadata

  • Download URL: template-0.6.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for template-0.6.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 81094bb6282a687136e9cd1fcc56008e3702790f869a85aa478398cb8fd3b4ca
MD5 b7c8bc50064b9312901992dff451b0bc
BLAKE2b-256 a99c4d4ab35f214ab831003c088a0ad6b6b706bf3309c439014ba04b816c7273

See more details on using hashes here.

Supported by

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