Skip to content

Commit

Permalink
Avoid failure to determine type with relative paths (#1438)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 6, 2021
1 parent 5266a86 commit 262268f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

DEFAULT_KINDS = [
# Do not sort this list, order matters.
{"requirements": "requirements.yml"}, # v2 and v1
{"requirements": "**/meta/requirements.yml"}, # v1 only
{"reno": "releasenotes/*/*.{yaml,yml}"}, # reno release notes
{"reno": "**/releasenotes/*/*.{yaml,yml}"}, # reno release notes
{"playbook": "**/playbooks/*.{yml,yaml}"},
{"playbook": "**/*playbook*.{yml,yaml}"},
{"role": "**/roles/*/"},
Expand All @@ -28,6 +27,7 @@
"requirements": "**/molecule/*/{collections,requirements}.{yaml,yml}"
}, # molecule old collection requirements (v1), ansible 2.8 only
{"yaml": "**/molecule/*/{base,molecule}.{yaml,yml}"}, # molecule config
{"requirements": "**/requirements.yml"}, # v2 and v1
{"playbook": "**/molecule/*/*.{yaml,yml}"}, # molecule playbooks
{"yaml": "**/*.{yaml,yml}"},
{"yaml": "**/.*.{yaml,yml}"},
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def kind_from_path(path: Path) -> str:
"""Determine the file kind based on its name."""
# pathlib.Path.match patterns are very limited, they do not support *a*.yml
# glob.glob supports **/foo.yml but not multiple extensions
pathex = wcmatch.pathlib.PurePath(path)
pathex = wcmatch.pathlib.PurePath(path.absolute().resolve())
for entry in options.kinds:
for k, v in entry.items():
if pathex.globmatch(
Expand Down
4 changes: 4 additions & 0 deletions test/TestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ def test_is_playbook():
("examples/playbooks/vars/other.yml", "vars"),
("examples/playbooks/vars/subfolder/settings.yml", "vars"), # deep vars
("molecule/scenario/collections.yml", "requirements"), # deprecated 2.8 format
(
"../roles/geerlingguy.mysql/tasks/configure.yml",
"tasks",
), # relative path involved
),
)
def test_default_kinds(monkeypatch, path: str, kind: FileType) -> None:
Expand Down

0 comments on commit 262268f

Please sign in to comment.