-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loading data as yaml with date or datetime fails with json exception #3
Comments
@epDHowwD Hi 👋 Try: example:
- someDate: "2022-02-02" |
No I cannot change the database so the tool on top works. The yaml data comes various data sources and we use your cmdline tool (and I cannot underline its usefulness in this scenario enough) to extract information from it to display it in our documentation. We basically generate documentation from the actual configuration files. These config files we cannot change just so they work in the docu display well. What we did, and what I propose you to fix differently, is to patch the tool in the way to remove the verbosity logging as json of the data being read in the function #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
import jinja2_tools
# fixes https://github.com/Avielyo10/jinja2-tools/issues/3
from jinja2_tools.exceptions import InvalidDataType
from jinja2_tools.util import input_handler, load_yaml
from jinja2_tools.cli import main
def fixed_get_data(self):
try:
ih_content = input_handler(self.data)
except InvalidDataType as err:
print(err.message, file=sys.stderr)
sys.exit(128)
else:
self.data = load_yaml(ih_content)
# print_verbose({'title': '[Data]', 'content': json.dumps(
# self.data, indent=2), 'verbose': self.verbose})
return self.data
jinja2_tools.objects.Data.get_data = fixed_get_data
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main()) For example you can replace the json.dumps function with some yaml dump or pprint. That would cover more data types. At least as much as yaml supports generally. |
@epDHowwD got you, I'll create a fix for all the dumps! |
Done! |
some data file:
Using the cli interface:
Error is:
Looking into objects.py there is a json.dumps invocation on the loaded yaml which seems not be able to cope with date and timestamps.
The text was updated successfully, but these errors were encountered: