Working with YAML files ¶
Makefile.yaml has checked syntax before it is parsed by RKD. A jsonschema library was used to validate YAML files against a JSON formatted schema file.
This gives the early validation of typing inside of YAML files, and a clear message to the user about place where the typo is.
YAML parsing API ¶
Schema validation is a part of YAML parsing, the preferred way of working with YAML files is to not only parse the schema but also validate. In result of this there is a class that wraps yaml library - rkd.yaml_parser.YamlFileLoader , use it instead of plain yaml library.
Notice: The YAML and schema files are automatically searched in .rkd, .rkd/schema directories, including RKD_PATH
Example usage:
from rkd.yaml_parser import YamlFileLoader
parsed = YamlFileLoader([]).load_from_file('deployment.yml', 'org.riotkit.harbor/deployment/v1')
FAQ ¶
-
FileNotFoundError: Schema “my-schema-name.json” cannot be found, looked in: [‘…/riotkit-harbor’, ‘/…/riotkit-harbor/schema’, ‘/…/riotkit-harbor/.rkd/schema’, ‘/home/…/.rkd/schema’, ‘/usr/lib/rkd/schema’, ‘/usr/lib/python3.8/site-packages/rkd/internal/schema’]
The schema file cannot be found, the name is invalid or file missing. The schema should be placed somewhere in the .rkd/schema directory - in global, in home directory or in project.
-
rkd.exception.YAMLFileValidationError: YAML schema validation failed at path “tasks” with error: [] is not of type ‘object’
It means you created a list (starts with “-“) instead of dictionary at “tasks” path.
Example of what went wrong:
tasks:
- description: first
- description: second
Example of how it should be as an ‘object’ (dictionary):
tasks:
first:
description: first
second:
description: second
API ¶
- class rkd.core.yaml_parser. YamlFileLoader ( paths : List [ str ] ) [source] ¶
-
YAML loader extended by schema validation support
YAML schema is stored as JSON files in .rkd/schema directories. The Loader looks in all paths defined in RKD_PATH as well as in paths provided by ApplicationContext
- find_path_by_name ( filename : str , subdir : str ) str [source] ¶
-
Find schema in one of RKD directories or in current path