CLI Samples¶
Help¶
usage: datatemplate [-h] [--config-file CONFIG_FILE] {render,dump} ...
options:
-h, --help show this help message and exit
--config-file CONFIG_FILE
the path to conf.py
commands:
valid commands
{render,dump}
render render a template to stdout
dump dump the data to stdout without a template
Data File¶
---
key1: value1
---
key: value
key1: different value
Template File¶
.. -*- mode: rst -*-
Static Heading
--------------
Individual Item
~~~~~~~~~~~~~~~
{{ data[0]|tojson }}
List of Items
~~~~~~~~~~~~~
{% for item in data %}
- {{item|tojson}}
- {{item.key}}
- {{item.key1}}
{% endfor %}
Mapping Series Table
~~~~~~~~~~~~~~~~~~~~
Rendering a table from a list of nested dictionaries using dynamic
headers.
{{ make_list_table_from_mappings(
[('Key', 'key'), ('Key One', 'key1')],
data,
title='Table from series of mappings',
) }}
Rendering a Template¶
$ datatemplate render -o multiple-documents \
doc/source/_templates/sample-multiple.tmpl \
doc/source/sample-multiple.yaml
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/bin/datatemplate", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 76, in main
return args.func(args, conf)
^^^^^^^^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 107, in render
with io.open(args.template, 'r', encoding='utf-8-sig') as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'doc/source/_templates/sample-multiple.tmpl'
Experimenting by Dumping Data¶
CSV Data With Headers¶
$ datatemplate dump -o dialect:excel-tab \
-o headers \
doc/source/sample.csv
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/bin/datatemplate", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 76, in main
return args.func(args, conf)
^^^^^^^^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 134, in dump
with load(**conf) as data:
File "/home/docs/.asdf/installs/python/3.11.6/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/loaders.py", line 97, in load_csv
with open(absolute_resolved_path, 'r', newline='', encoding=encoding) as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/checkouts/latest/doc/source/doc/source/sample.csv'
CSV Data Without Headers¶
$ datatemplate dump -o dialect:excel-tab \
doc/source/sample.csv
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/bin/datatemplate", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 76, in main
return args.func(args, conf)
^^^^^^^^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/cli.py", line 134, in dump
with load(**conf) as data:
File "/home/docs/.asdf/installs/python/3.11.6/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/envs/latest/lib/python3.11/site-packages/sphinxcontrib/datatemplates/loaders.py", line 97, in load_csv
with open(absolute_resolved_path, 'r', newline='', encoding=encoding) as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/docs/checkouts/readthedocs.org/user_builds/sphinxcontribdatatemplates/checkouts/latest/doc/source/doc/source/sample.csv'