Skip to content

Commit

Permalink
Merge branch 'main' into fix/submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka committed May 16, 2023
2 parents 596d0cf + 8ef5ca4 commit bdb5b10
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 63 deletions.
7 changes: 4 additions & 3 deletions .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#
# pip-compile --no-annotate --output-file=.config/requirements-lock.txt --resolver=backtracking --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib pyproject.toml
#
ansible-core==2.14.5
ansible-core==2.15.0
attrs==23.1.0
black==23.3.0
bracex==2.3.post1
cffi==1.15.1
click==8.1.3
cryptography==40.0.2
filelock==3.12.0
importlib-resources==5.0.7
jinja2==3.1.2
jsonschema==4.17.3
markdown-it-py==2.2.0
Expand All @@ -20,13 +21,13 @@ mdurl==0.1.2
mypy-extensions==1.0.0
packaging==23.1
pathspec==0.11.1
platformdirs==3.5.0
platformdirs==3.5.1
pycparser==2.21
pygments==2.15.1
pyrsistent==0.19.3
pyyaml==6.0
rich==13.3.5
ruamel-yaml==0.17.24
ruamel-yaml==0.17.26
subprocess-tee==0.4.1
tomli==2.0.1
typing-extensions==4.5.0
Expand Down
1 change: 1 addition & 0 deletions .config/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pytest >= 7.2.2
pytest-mock
pytest-plus >= 0.2 # for PYTEST_REQPASS
pytest-xdist >= 2.1.0
ruamel.yaml>=0.17.26,<0.18 # only the latest is expected to pass our tests
ruamel-yaml-clib # needed for mypy
spdx-tools >= 0.7.1 # Apache
types-jsonschema # IDE support
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jsonschema>=4.10.0 # MIT, version needed for improved errors
packaging>=21.3 # Apache-2.0,BSD-2-Clause
pyyaml>=5.4.1 # MIT (centos 9 has 5.3.1)
rich>=12.0.0 # MIT
ruamel.yaml>=0.17.24,<0.18 # MIT, next version is planned to have breaking changes
ruamel.yaml>=0.17.0,<0.18 # MIT, next version is planned to have breaking changes
subprocess-tee>=0.4.1 # MIT, used by ansible-compat
yamllint >= 1.30.0 # GPLv3
wcmatch>=8.1.2 # MIT
15 changes: 8 additions & 7 deletions .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --resolver=backtracking --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib pyproject.toml
#
ansible-core==2.14.5
astroid==2.15.4
ansible-core==2.15.0
astroid==2.15.5
attrs==23.1.0
beautifulsoup4==4.12.1
black==23.3.0
Expand All @@ -32,6 +32,7 @@ griffe==0.26.0
htmlmin2==0.1.13
idna==3.4
importlib-metadata==6.1.0
importlib-resources==5.0.7
iniconfig==2.0.0
isodate==0.6.1
isort==5.12.0
Expand Down Expand Up @@ -59,14 +60,14 @@ mkdocs-minify-plugin==0.6.4
mkdocs-monorepo-plugin==1.0.4
mkdocstrings==0.21.2
mkdocstrings-python==0.9.0
mypy==1.2.0
mypy==1.3.0
mypy-extensions==1.0.0
netaddr==0.8.0
packaging==23.0
pathspec==0.11.1
pillow==9.5.0
pipdeptree==2.7.0
platformdirs==3.5.0
platformdirs==3.5.1
pluggy==1.0.0
ply==3.11
psutil==5.9.5
Expand All @@ -79,7 +80,7 @@ pyrsistent==0.19.3
pytest==7.3.1
pytest-mock==3.10.0
pytest-plus==0.4.0
pytest-xdist==3.2.1
pytest-xdist==3.3.0
python-dateutil==2.8.2
python-slugify==8.0.1
pyyaml==6.0
Expand All @@ -88,7 +89,7 @@ rdflib==6.3.2
regex==2023.3.23
requests==2.28.2
rich==13.3.5
ruamel-yaml==0.17.24
ruamel-yaml==0.17.26
six==1.16.0
soupsieve==2.4
spdx-tools==0.7.1
Expand All @@ -97,7 +98,7 @@ text-unidecode==1.3
tinycss2==1.2.1
tomli==2.0.1
tomlkit==0.11.8
types-jsonschema==4.17.0.7
types-jsonschema==4.17.0.8
types-pyyaml==6.0.12.9
typing-extensions==4.5.0
uritools==4.0.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 796
PYTEST_REQPASS: 797
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ repos:
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.265"
rev: "v0.0.267"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -140,7 +140,7 @@ repos:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.3.0
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
Expand All @@ -153,7 +153,7 @@ repos:
- jinja2
- pytest>=7.2.2
- rich>=13.2.0
- ruamel-yaml>=0.17.24
- ruamel-yaml>=0.17.26
- ruamel-yaml-clib>=0.2.7
- spdx-tools
- subprocess-tee
Expand Down Expand Up @@ -183,7 +183,7 @@ repos:
- pytest>=7.2.2
- pyyaml
- rich>=13.2.0
- ruamel-yaml>=0.17.24
- ruamel-yaml>=0.17.26
- ruamel-yaml-clib>=0.2.7
- spdx-tools
- typing_extensions
Expand Down
11 changes: 11 additions & 0 deletions examples/playbooks/bug-core-warning-unique-filter-fallback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Fixture for test_bug_3216
hosts: localhost
gather_facts: false
tasks:
- name: Set fact
ansible.builtin.set_fact:
qq: ["qq", "ww"]
- name: Print it
ansible.builtin.debug:
msg: "{{ qq | unique }}"
14 changes: 0 additions & 14 deletions examples/playbooks/no_handler_fail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,3 @@
ansible.builtin.debug:
msg: why isn't this a handler
when: result['changed'] == true

- name: This should be a handler 5 # noqa: literal-compare
ansible.builtin.debug:
msg: why isn't this a handler
when:
- result['changed'] == true
- another_condition

- name: This should be a handler 6
ansible.builtin.debug:
msg: why isn't this a handler
when:
- first_condition
- result.changed
16 changes: 16 additions & 0 deletions examples/playbooks/no_handler_pass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
- conditionA
- conditionB

- name: Check when with a list of size 1
ansible.builtin.debug:
var: result
when:
- conditionA

- name: Registering task 1
ansible.builtin.command: echo Hello
register: r1
Expand All @@ -49,6 +55,16 @@
ansible.builtin.command: echo Hello
when: r1.changed and r2.changed

- name: Use when with or # noqa: no-changed-when
ansible.builtin.command: echo Hello
when: r1.changed or conditionA

- name: Use when with list of conditions # noqa: no-changed-when
ansible.builtin.command: echo Hello
when:
- r1.changed
- conditionA

- name: Registering task
ansible.builtin.command: echo Hello
register: r
Expand Down
29 changes: 24 additions & 5 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, TextIO

from ansible_compat.config import ansible_version
from ansible_compat.prerun import get_cache_dir
from filelock import FileLock, Timeout
from rich.markup import escape

from ansiblelint import cli
from ansiblelint._mockings import _perform_mockings_cleanup
Expand All @@ -46,7 +46,13 @@
reconfigure,
render_yaml,
)
from ansiblelint.config import Options, get_version_warning, log_entries, options
from ansiblelint.config import (
Options,
get_deps_versions,
get_version_warning,
log_entries,
options,
)
from ansiblelint.constants import RC
from ansiblelint.loaders import load_ignore_txt
from ansiblelint.skip_utils import normalize_tag
Expand Down Expand Up @@ -208,9 +214,12 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901
reconfigure(console_options)

if options.version:
console.print(
f"ansible-lint [repr.number]{__version__}[/] using ansible [repr.number]{ansible_version()}[/]",
)
deps = get_deps_versions()
msg = f"ansible-lint [repr.number]{__version__}[/] using[dim]"
for k, v in deps.items():
msg += f" {escape(k)}:[repr.number]{v}[/]"
msg += "[/]"
console.print(msg, markup=True, highlight=False)
msg = get_version_warning()
if msg:
console.print(msg)
Expand Down Expand Up @@ -252,6 +261,16 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901
result = _get_matches(rules, options)

if options.write_list:
ruamel_safe_version = "0.17.26"
from packaging.version import Version
from ruamel.yaml import __version__ as ruamel_yaml_version_str

if Version(ruamel_safe_version) > Version(ruamel_yaml_version_str):
_logger.warning(
"We detected use of `--write` feature with a buggy ruamel-yaml %s library instead of >=%s, upgrade it before reporting any bugs like dropped comments.",
ruamel_yaml_version_str,
ruamel_safe_version,
)
_do_transform(result, options)

mark_as_success = True
Expand Down
13 changes: 13 additions & 0 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import warnings
from dataclasses import dataclass, field
from functools import lru_cache
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
from typing import TYPE_CHECKING, Any
from urllib.error import HTTPError, URLError
Expand Down Expand Up @@ -240,6 +241,18 @@ def guess_install_method() -> str:
return pip if use_pip else ""


def get_deps_versions() -> dict[str, Version | None]:
"""Return versions of most important dependencies."""
result: dict[str, Version | None] = {}

for name in ["ansible-core", "ruamel-yaml", "ruamel-yaml-clib"]:
try:
result[name] = Version(version(name))
except PackageNotFoundError:
result[name] = None
return result


def get_version_warning() -> str:
"""Display warning if current version is outdated."""
# 0.1dev1 is special fallback version
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
_logger = logging.getLogger(__name__)

ignored_re = re.compile(
"|".join(
"|".join( # noqa: FLY002
[
r"^parameters are mutually exclusive:",
# https://github.com/ansible/ansible-lint/issues/3128 as strings can be jinja
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Token = namedtuple("Token", "lineno token_type value")

ignored_re = re.compile(
"|".join(
"|".join( # noqa: FLY002
[
r"^Object of type method is not JSON serializable",
r"^Unexpected templating type error occurred on",
Expand Down
10 changes: 5 additions & 5 deletions src/ansiblelint/rules/no_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _changed_in_when(item: str) -> bool:
return False
item_list = item.split()

if {"and", "not"} & set(item_list):
if {"and", "or", "not"} & set(item_list):
return False
return any(
changed in item
Expand Down Expand Up @@ -75,9 +75,9 @@ def matchtask(
when = task.get("when")

if isinstance(when, list):
for item in when:
if _changed_in_when(item):
return True
if len(when) > 1:
return False
return _changed_in_when(when[0])
if isinstance(when, str):
return _changed_in_when(when)
return False
Expand All @@ -92,7 +92,7 @@ def matchtask(
@pytest.mark.parametrize(
("test_file", "failures"),
(
pytest.param("examples/playbooks/no_handler_fail.yml", 7, id="fail"),
pytest.param("examples/playbooks/no_handler_fail.yml", 5, id="fail"),
pytest.param("examples/playbooks/no_handler_pass.yml", 0, id="pass"),
),
)
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"tag": "moves",
},
"with_filetree": {
"msg": "with_filetree was moved to with_community.general.flattened in 2.10",
"msg": "with_filetree was moved to with_community.general.filetree in 2.10",
"tag": "moves",
},
"with_cartesian": {
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_ansible_syntax_check_matches( # noqa: C901
hosts: localhost
tasks:
- ansible.builtin.import_role:
name: {str(lintable.path.expanduser())}
name: {lintable.path.expanduser()!s}
"""
# pylint: disable=consider-using-with
fh = tempfile.NamedTemporaryFile(mode="w", suffix=".yml", prefix="play")
Expand Down
10 changes: 10 additions & 0 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from fnmatch import fnmatch
from typing import TYPE_CHECKING, Any

from ansible_compat.runtime import AnsibleWarning

import ansiblelint.skip_utils
import ansiblelint.utils
from ansiblelint._internal.rules import LoadingFailureRule, WarningRule
Expand Down Expand Up @@ -120,6 +122,14 @@ def run(self) -> list[MatchError]:
warnings.simplefilter("always")
matches = self._run()
for warn in captured_warnings:
# Silence Ansible runtime warnings that are unactionable
# https://github.com/ansible/ansible-lint/issues/3216
if warn.category is AnsibleWarning and isinstance(warn.source, dict):
msg = warn.source["msg"]
if msg.startswith(
"Falling back to Ansible unique filter as Jinja2 one failed",
):
continue
# For the moment we are ignoring deprecation warnings as Ansible
# modules outside current content can generate them and user
# might not be able to do anything about them.
Expand Down

0 comments on commit bdb5b10

Please sign in to comment.