Open AndreyNautilus opened 5 months ago
I can create a PR with the fix if you prefer.
Will gladly accept contributions if you feel so inclined
@cblakkan , sorry it took longer than expected to create a proper PR, but here it is: https://github.com/23andMe/Yamale/pull/241
First of all: thanks for a great tool!
Description
yamale
CLI can't find schema file if path to schema file doesn't form a valid path with any parent folder of the path to the document file. For example (see "how to reproduce" below):$ yamale c/document.yaml --schema=a/b/my_schema.yaml
works fine, buta$ yamale ../c/document.yaml --schema=b/my_schema.yaml
fails.How to reproduce Let's assume the following folder structure:
with
document.yaml
:and
my_schema.yaml
:If the current working directory is
temp
, everything works as expected:but if we change current working directory to
temp/a
, CLI suddenly fails, because the schema file is not found:This looks like a bug in CLI.
Root-cause analysis It seems like intended behaviour in
_find_data_path_schema
function ofyamale/command_line.py
file: traverse all parent folders of the absolute path to the document, append the path to schema as suffix and try to read the schema by that path. So, if such iteration never returns a path to schema, the schema is not found.Suggested solution Take current working directory into account when looking for schema. Before iterating parent directories of the path to the document, try to find the schema starting from the current working directory.
I can create a PR with the fix if you prefer.