Skip to content
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

Schema not found by CLI if path to document starts with ".." #238

Open
AndreyNautilus opened this issue Mar 5, 2024 · 2 comments
Open

Comments

@AndreyNautilus
Copy link
Contributor

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, but
  • a$ yamale ../c/document.yaml --schema=b/my_schema.yaml fails.

How to reproduce
Let's assume the following folder structure:

temp/
├─ a/
│  ├─ b/
│  │  ├─ my_schema.yaml
├─ c/
│  ├─ document.yaml

with document.yaml:

name: abc

and my_schema.yaml:

name: str()

If the current working directory is temp, everything works as expected:

temp$ yamale c/document.yaml --schema=a/b/my_schema.yaml
Validating .../temp/c/document.yaml...
Validation success! 👍

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.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.

@cblakkan
Copy link
Member

cblakkan commented Mar 6, 2024

I can create a PR with the fix if you prefer.

Will gladly accept contributions if you feel so inclined

@AndreyNautilus
Copy link
Contributor Author

@cblakkan , sorry it took longer than expected to create a proper PR, but here it is: #241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants