You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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, but
but if we change current working directory to temp/a, CLI suddenly fails, because the schema file is not found:
temp$ cd a
temp/a$ yamale ../c/document.yaml --schema=b/my_schema.yaml
Validating .../temp/c/document.yaml...
Validation failed!
Invalid schema name for 'b/my_schema.yaml' or schema not found.
This looks like a bug in CLI.
Root-cause analysis
It seems like intended behaviour in _find_data_path_schema function of yamale/command_line.pyfile: 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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: