Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ansible-lint for openSUSE:Factory checked in at 2023-11-07 21:28:12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ansible-lint (Old) and /work/SRC/openSUSE:Factory/.ansible-lint.new.17445 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ansible-lint" Tue Nov 7 21:28:12 2023 rev:38 rq:1123967 version:6.22.0 Changes: -------- --- /work/SRC/openSUSE:Factory/ansible-lint/ansible-lint.changes 2023-10-23 23:40:34.778689898 +0200 +++ /work/SRC/openSUSE:Factory/.ansible-lint.new.17445/ansible-lint.changes 2023-11-07 21:29:06.917604600 +0100 @@ -1,0 +2,15 @@ +Tue Nov 7 11:31:10 UTC 2023 - Johannes Kastl <ka...@b1-systems.de> + +-update to 6.22.0: + * Minor Changes + - Enable YAML 1.2 support for non-ansible files (#3809) + @ssbarnea + * Bugfixes + - Require ruamel.yaml >= 0.18.5 (#3880) @ssbarnea + - Improve logging regarding to yaml loading and dumping (#3875) + @ssbarnea + - Avoid creating new load method in our custom formatter + (#3874) @ssbarnea + - Support `ruamel-yaml >= 0.18.2` (#3869) @hswong3i + +------------------------------------------------------------------- Old: ---- ansible-lint-6.21.1.tar.gz New: ---- ansible-lint-6.22.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ansible-lint.spec ++++++ --- /var/tmp/diff_new_pack.XNqqVF/_old 2023-11-07 21:29:07.377621540 +0100 +++ /var/tmp/diff_new_pack.XNqqVF/_new 2023-11-07 21:29:07.377621540 +0100 @@ -40,7 +40,7 @@ %global lib_name ansiblelint %{?python_enable_dependency_generator} Name: ansible-lint -Version: 6.21.1 +Version: 6.22.0 Release: 0%{?dist} Summary: Best practices checker for Ansible License: MIT @@ -68,9 +68,9 @@ # Add runtime requirements (unless required for tests) # to make sure this only builds if they are present # https://github.com/ansible/ansible-lint/blob/main/.config/requirements.in -BuildRequires: ansible-core >= 2.15.0 +BuildRequires: ansible-core >= 2.15.5 BuildRequires: %{ansible_python}-ansible-compat >= 4.1.10 -BuildRequires: %{ansible_python}-black >= 22.8.0 +BuildRequires: %{ansible_python}-black >= 23.10.1 BuildRequires: %{ansible_python}-enrich >= 1.2.7 BuildRequires: %{ansible_python}-filelock >= 3.3.0 BuildRequires: %{ansible_python}-jsonschema >= 4.17.3 @@ -78,7 +78,7 @@ BuildRequires: %{ansible_python}-PyYAML >= 6.0.1 BuildRequires: %{ansible_python}-requests >= 2.31.0 BuildRequires: %{ansible_python}-rich >= 13.5.2 -BuildRequires: (%{ansible_python}-ruamel.yaml >= 0.17.31 and %{ansible_python}-ruamel.yaml < 0.18) +BuildRequires: %{ansible_python}-ruamel.yaml >= 0.17.31 BuildRequires: %{ansible_python}-subprocess-tee >= 0.4.1 BuildRequires: %{ansible_python}-tenacity BuildRequires: %{ansible_python}-wcmatch >= 8.4.1 @@ -86,9 +86,9 @@ # # https://github.com/ansible/ansible-lint/blob/main/.config/requirements.in -Requires: ansible-core >= 2.15.0 +Requires: ansible-core >= 2.15.5 Requires: %{ansible_python}-ansible-compat >= 4.1.10 -Requires: %{ansible_python}-black >= 22.8.0 +Requires: %{ansible_python}-black >= 23.10.1 Requires: %{ansible_python}-bracex >= 2.2.1 Requires: %{ansible_python}-enrich >= 1.2.7 Requires: %{ansible_python}-filelock >= 3.3.0 @@ -97,7 +97,7 @@ Requires: %{ansible_python}-PyYAML >= 6.0.1 Requires: %{ansible_python}-requests >= 2.31.0 Requires: %{ansible_python}-rich >= 13.5.2 -Requires: (%{ansible_python}-ruamel.yaml >= 0.17.31 and %{ansible_python}-ruamel.yaml < 0.18) +Requires: %{ansible_python}-ruamel.yaml >= 0.17.31 Requires: %{ansible_python}-subprocess-tee >= 0.4.1 Requires: %{ansible_python}-tenacity Requires: %{ansible_python}-wcmatch >= 8.4.1 ++++++ ansible-lint-6.21.1.tar.gz -> ansible-lint-6.22.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.config/dictionary.txt new/ansible-lint-6.22.0/.config/dictionary.txt --- old/ansible-lint-6.21.1/.config/dictionary.txt 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.config/dictionary.txt 2023-11-06 15:36:40.000000000 +0100 @@ -208,6 +208,7 @@ matchvar matchyaml maxdepth +maxsplit minversion mkdir mkdocs diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.config/requirements-lock.txt new/ansible-lint-6.22.0/.config/requirements-lock.txt --- old/ansible-lint-6.21.1/.config/requirements-lock.txt 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.config/requirements-lock.txt 2023-11-06 15:36:40.000000000 +0100 @@ -5,40 +5,40 @@ # pip-compile --no-annotate --output-file=.config/requirements-lock.txt --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib pyproject.toml # ansible-compat==4.1.10 -ansible-core==2.15.4 +ansible-core==2.15.5 attrs==23.1.0 -black==23.9.1 +black==23.10.1 bracex==2.4 certifi==2023.7.22 cffi==1.16.0 -charset-normalizer==3.2.0 +charset-normalizer==3.3.2 click==8.1.7 -cryptography==41.0.4 -filelock==3.12.4 +cryptography==41.0.5 +filelock==3.13.1 idna==3.4 importlib-resources==5.0.7 jinja2==3.1.2 -jsonschema==4.19.1 +jsonschema==4.19.2 jsonschema-specifications==2023.7.1 markdown-it-py==3.0.0 markupsafe==2.1.3 mdurl==0.1.2 mypy-extensions==1.0.0 -packaging==23.1 +packaging==23.2 pathspec==0.11.2 -platformdirs==3.10.0 +platformdirs==3.11.0 pycparser==2.21 pygments==2.16.1 pyyaml==6.0.1 referencing==0.30.2 requests==2.31.0 -rich==13.5.3 -rpds-py==0.10.3 -ruamel-yaml==0.17.33 +rich==13.6.0 +rpds-py==0.10.6 +ruamel-yaml==0.18.5 subprocess-tee==0.4.1 tomli==2.0.1 typing-extensions==4.8.0 -urllib3==2.0.5 +urllib3==2.0.7 wcmatch==8.5 yamllint==1.32.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.config/requirements-test.txt new/ansible-lint-6.22.0/.config/requirements-test.txt --- old/ansible-lint-6.21.1/.config/requirements-test.txt 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.config/requirements-test.txt 2023-11-06 15:36:40.000000000 +0100 @@ -11,7 +11,7 @@ pytest-mock pytest-plus >= 0.6 # for PYTEST_REQPASS pytest-xdist >= 2.1.0 -ruamel.yaml>=0.17.31,<0.18 # only the latest is expected to pass our tests +ruamel.yaml>=0.17.31 ruamel-yaml-clib # needed for mypy types-jsonschema # IDE support types-pyyaml # IDE support diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.config/requirements.in new/ansible-lint-6.22.0/.config/requirements.in --- old/ansible-lint-6.21.1/.config/requirements.in 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.config/requirements.in 2023-11-06 15:36:40.000000000 +0100 @@ -10,7 +10,7 @@ pathspec>=0.10.3 # Mozilla Public License 2.0 (MPL 2.0) pyyaml>=5.4.1 # MIT (centos 9 has 5.3.1) rich>=12.0.0 # MIT -ruamel.yaml>=0.17.0,<0.18,!=0.17.29,!=0.17.30 # MIT, next version is planned to have breaking changes +ruamel.yaml>=0.18.5 # MIT requests>=2.31.0 # Apache-2.0 (indirect, but we want newer version for security reasons) subprocess-tee>=0.4.1 # MIT, used by ansible-compat yamllint >= 1.30.0 # GPLv3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.config/requirements.txt new/ansible-lint-6.22.0/.config/requirements.txt --- old/ansible-lint-6.21.1/.config/requirements.txt 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.config/requirements.txt 2023-11-06 15:36:40.000000000 +0100 @@ -5,12 +5,12 @@ # pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib pyproject.toml # ansible-compat==4.1.10 -ansible-core==2.15.4 -astroid==2.15.8 +ansible-core==2.15.5 +astroid==3.0.1 attrs==23.1.0 babel==2.12.1 beautifulsoup4==4.12.2 -black==23.9.1 +black==23.10.1 boolean-py==4.0 bracex==2.4 cairocffi==1.6.1 @@ -20,16 +20,16 @@ charset-normalizer==3.2.0 click==8.1.7 colorama==0.4.6 -coverage==7.3.1 +coverage==7.3.2 coverage-enable-subprocess==1.0 -cryptography==41.0.4 +cryptography==41.0.5 csscompressor==0.9.5 cssselect2==0.7.0 defusedxml==0.7.1 dill==0.3.7 exceptiongroup==1.1.3 execnet==2.0.2 -filelock==3.12.4 +filelock==3.13.1 ghp-import==2.1.0 griffe==0.36.4 htmlmin2==0.1.13 @@ -41,9 +41,8 @@ jinja2==3.1.2 jmespath==1.0.1 jsmin==3.0.1 -jsonschema==4.19.1 +jsonschema==4.19.2 jsonschema-specifications==2023.7.1 -lazy-object-proxy==1.9.0 license-expression==30.1.1 markdown==3.4.4 markdown-exec==1.6.0 @@ -64,7 +63,7 @@ mkdocs-monorepo-plugin==1.0.5 mkdocstrings==0.23.0 mkdocstrings-python==1.7.1 -mypy==1.5.1 +mypy==1.6.1 mypy-extensions==1.0.0 netaddr==0.9.0 packaging==23.1 @@ -74,13 +73,13 @@ pipdeptree==2.13.0 platformdirs==3.10.0 pluggy==1.3.0 -psutil==5.9.5 +psutil==5.9.6 pycparser==2.21 pygments==2.16.1 -pylint==2.17.6 +pylint==3.0.2 pymdown-extensions==10.3 -pytest==7.4.2 -pytest-mock==3.11.1 +pytest==7.4.3 +pytest-mock==3.12.0 pytest-plus==0.6.0 pytest-xdist==3.3.1 python-dateutil==2.8.2 @@ -90,24 +89,23 @@ referencing==0.30.2 regex==2023.8.8 requests==2.31.0 -rich==13.5.3 -rpds-py==0.10.3 -ruamel-yaml==0.17.33 +rich==13.6.0 +rpds-py==0.10.6 +ruamel-yaml==0.18.5 six==1.16.0 soupsieve==2.5 subprocess-tee==0.4.1 text-unidecode==1.3 tinycss2==1.2.1 tomli==2.0.1 -tomlkit==0.12.1 -types-jsonschema==4.19.0.3 +tomlkit==0.12.2 +types-jsonschema==4.19.0.4 types-pyyaml==6.0.12.12 typing-extensions==4.8.0 urllib3==2.0.5 watchdog==3.0.0 wcmatch==8.5 webencodings==0.5.1 -wrapt==1.15.0 yamllint==1.32.0 zipp==3.17.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.git_archival.txt new/ansible-lint-6.22.0/.git_archival.txt --- old/ansible-lint-6.21.1/.git_archival.txt 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.git_archival.txt 2023-11-06 15:36:40.000000000 +0100 @@ -1,4 +1,4 @@ -node: b4d48101af3a26f66e304db200e80716fdf8b719 -node-date: 2023-10-19T17:04:45+01:00 +node: 4113104583a59ba2d1f04fee3b049c5f43f6578c +node-date: 2023-11-06T14:36:40+00:00 describe-name: latest -ref-names: HEAD -> main, tag: v6.21.1, tag: v6, tag: latest +ref-names: HEAD -> main, tag: v6.22.0, tag: v6, tag: latest diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.github/workflows/tox.yml new/ansible-lint-6.22.0/.github/workflows/tox.yml --- old/ansible-lint-6.21.1/.github/workflows/tox.yml 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.github/workflows/tox.yml 2023-11-06 15:36:40.000000000 +0100 @@ -70,7 +70,7 @@ env: # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 834 + PYTEST_REQPASS: 845 steps: - uses: actions/checkout@v4 with: @@ -103,7 +103,7 @@ cache: pip python-version: ${{ matrix.python_version || '3.9' }} - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 cache: "npm" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/.pre-commit-config.yaml new/ansible-lint-6.22.0/.pre-commit-config.yaml --- old/ansible-lint-6.21.1/.pre-commit-config.yaml 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/.pre-commit-config.yaml 2023-11-06 15:36:40.000000000 +0100 @@ -64,18 +64,18 @@ - prettier-plugin-toml - prettier-plugin-sort-json - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v7.3.1 + rev: v7.3.2 hooks: - id: cspell # entry: codespell --relative args: [--relative, --no-progress, --no-summary] name: Spell check with cspell - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.0 + rev: 0.27.1 hooks: - id: check-github-workflows - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v4.4.0 + rev: v4.5.0 hooks: - id: end-of-file-fixer # ignore formatting-prettier to have an accurate prettier comparison @@ -131,17 +131,17 @@ types: [file, yaml] entry: yamllint --strict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.0.292" + rev: "v0.1.3" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black language_version: python3 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy # empty args needed in order to match mypy cli behavior @@ -157,7 +157,7 @@ - pytest>=7.2.2 - rich>=13.2.0 - ruamel-yaml-clib>=0.2.7 - - ruamel-yaml>=0.17.31 + - ruamel-yaml>=0.18.2 - subprocess-tee - types-PyYAML - types-jsonschema>=4.4.2 @@ -188,7 +188,7 @@ - pyyaml - rich>=13.2.0 - ruamel-yaml-clib>=0.2.7 - - ruamel-yaml>=0.17.31 + - ruamel-yaml>=0.18.2 - typing_extensions - wcmatch - yamllint diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/pyproject.toml new/ansible-lint-6.22.0/pyproject.toml --- old/ansible-lint-6.21.1/pyproject.toml 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/pyproject.toml 2023-11-06 15:36:40.000000000 +0100 @@ -205,18 +205,19 @@ junit_suite_name = "ansible_lint_test_suite" minversion = "4.6.6" norecursedirs = [ - "build", - "collections", - "dist", - "docs", - "src/ansible_lint.egg-info", + "*.egg", ".cache", ".eggs", ".git", ".github", - ".tox", - "*.egg", + ".mypy_cache", ".projects", + ".tox", + "build", + "collections", + "dist", + "docs", + "src/ansible_lint.egg-info", ] python_files = [ "test_*.py", @@ -232,7 +233,6 @@ xfail_strict = true [tool.ruff] -required-version = "0.0.292" ignore = [ "D203", # incompatible with D211 "D213", # incompatible with D212 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/src/ansiblelint/schemas/__main__.py new/ansible-lint-6.22.0/src/ansiblelint/schemas/__main__.py --- old/ansible-lint-6.21.1/src/ansiblelint/schemas/__main__.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/src/ansiblelint/schemas/__main__.py 2023-11-06 15:36:40.000000000 +0100 @@ -68,7 +68,10 @@ raise RuntimeError(msg) path = Path(__file__).parent.resolve() / f"{kind}.json" _logger.debug("Refreshing %s schema ...", kind) - request = Request(url) + if not url.startswith(("http:", "https:")): + msg = f"Unexpected url schema: {url}" + raise ValueError(msg) + request = Request(url) # noqa: S310 etag = data.get("etag", "") if etag: request.add_header("If-None-Match", f'"{data.get("etag")}"') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/src/ansiblelint/transformer.py new/ansible-lint-6.22.0/src/ansiblelint/transformer.py --- old/ansible-lint-6.21.1/src/ansiblelint/transformer.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/src/ansiblelint/transformer.py 2023-11-06 15:36:40.000000000 +0100 @@ -8,7 +8,11 @@ from ansiblelint.file_utils import Lintable from ansiblelint.rules import AnsibleLintRule, TransformMixin -from ansiblelint.yaml_utils import FormattedYAML, get_path_to_play, get_path_to_task +from ansiblelint.yaml_utils import ( + FormattedYAML, + get_path_to_play, + get_path_to_task, +) if TYPE_CHECKING: from ansiblelint.config import Options @@ -92,9 +96,14 @@ # We need a fresh YAML() instance for each load because ruamel.yaml # stores intermediate state during load which could affect loading # any other files. (Based on suggestion from ruamel.yaml author) - yaml = FormattedYAML() + yaml = FormattedYAML( + # Ansible only uses YAML 1.1, but others files should use newer 1.2 (ruamel.yaml defaults to 1.2) + version=(1, 1) + if file.is_owned_by_ansible() + else None, + ) - ruamel_data = yaml.loads(data) + ruamel_data = yaml.load(data) if not isinstance(ruamel_data, (CommentedMap, CommentedSeq)): # This is an empty vars file or similar which loads as None. # It is not safe to write this file or data-loss is likely. @@ -108,12 +117,8 @@ if self.write_set != {"none"}: self._do_transforms(file, ruamel_data or data, file_is_yaml, matches) - if not file.is_owned_by_ansible(): - # Do nothing until we enable support for YAML 1.2 - # https://github.com/ansible/ansible-lint/issues/3811 - continue - if file_is_yaml: + _logger.debug("Dumping %s using YAML (%s)", file, yaml.version) # noinspection PyUnboundLocalVariable file.content = yaml.dumps(ruamel_data) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/src/ansiblelint/utils.py new/ansible-lint-6.22.0/src/ansiblelint/utils.py --- old/ansible-lint-6.21.1/src/ansiblelint/utils.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/src/ansiblelint/utils.py 2023-11-06 15:36:40.000000000 +0100 @@ -34,6 +34,7 @@ from pathlib import Path from typing import Any +import ruamel.yaml.parser import yaml from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.parsing.convert_bool import boolean @@ -702,7 +703,11 @@ @property def name(self) -> str | None: """Return the name of the task.""" - return self.raw_task.get("name", None) + name = self.raw_task.get("name", None) + if name is not None and not isinstance(name, str): + msg = "Task name can only be a string." + raise RuntimeError(msg) + return name @property def action(self) -> str: @@ -906,8 +911,9 @@ yaml.parser.ParserError, yaml.scanner.ScannerError, yaml.constructor.ConstructorError, + ruamel.yaml.parser.ParserError, ) as exc: - msg = "Failed to load YAML file" + msg = f"Failed to load YAML file: {lintable.path}" raise RuntimeError(msg) from exc if len(result) == 0: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/src/ansiblelint/yaml_utils.py new/ansible-lint-6.22.0/src/ansiblelint/yaml_utils.py --- old/ansible-lint-6.21.1/src/ansiblelint/yaml_utils.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/src/ansiblelint/yaml_utils.py 2023-11-06 15:36:40.000000000 +0100 @@ -35,6 +35,7 @@ if TYPE_CHECKING: # noinspection PyProtectedMember from ruamel.yaml.comments import LineCol + from ruamel.yaml.compat import StreamTextType from ruamel.yaml.nodes import ScalarNode from ruamel.yaml.representer import RoundTripRepresenter from ruamel.yaml.tokens import CommentToken @@ -43,6 +44,7 @@ _logger = logging.getLogger(__name__) + YAMLLINT_CONFIG = """ extends: default rules: @@ -749,13 +751,14 @@ class FormattedYAML(YAML): """A YAML loader/dumper that handles ansible content better by default.""" - def __init__( + def __init__( # pylint: disable=too-many-arguments self, *, typ: str | None = None, pure: bool = False, output: Any = None, plug_ins: list[str] | None = None, + version: tuple[int, int] | None = None, ): """Return a configured ``ruamel.yaml.YAML`` instance. @@ -815,10 +818,12 @@ tasks: - name: Task """ - # Default to reading/dumping YAML 1.1 (ruamel.yaml defaults to 1.2) - self._yaml_version_default: tuple[int, int] = (1, 1) - self._yaml_version: str | tuple[int, int] = self._yaml_version_default - + if version: + if isinstance(version, str): + x, y = version.split(".", maxsplit=1) + version = (int(x), int(y)) + self._yaml_version_default: tuple[int, int] = version + self._yaml_version: tuple[int, int] = self._yaml_version_default super().__init__(typ=typ, pure=pure, output=output, plug_ins=plug_ins) # NB: We ignore some mypy issues because ruamel.yaml typehints are not great. @@ -919,8 +924,8 @@ return cast(dict[str, Union[bool, int, str]], config) - @property # type: ignore[override] - def version(self) -> str | tuple[int, int]: + @property + def version(self) -> tuple[int, int] | None: """Return the YAML version used to parse or dump. Ansible uses PyYAML which only supports YAML 1.1. ruamel.yaml defaults to 1.2. @@ -928,19 +933,25 @@ We can relax the version requirement once ansible uses a version of PyYAML that includes this PR: https://github.com/yaml/pyyaml/pull/555 """ - return self._yaml_version + if hasattr(self, "_yaml_version"): + return self._yaml_version + return None @version.setter - def version(self, value: str | tuple[int, int] | None) -> None: + def version(self, value: tuple[int, int] | None) -> None: """Ensure that yaml version uses our default value. The yaml Reader updates this value based on the ``%YAML`` directive in files. So, if a file does not include the directive, it sets this to None. But, None effectively resets the parsing version to YAML 1.2 (ruamel's default). """ - self._yaml_version = value if value is not None else self._yaml_version_default + if value is not None: + self._yaml_version = value + elif hasattr(self, "_yaml_version_default"): + self._yaml_version = self._yaml_version_default + # We do nothing if the object did not have a previous default version defined - def loads(self, stream: str) -> Any: + def load(self, stream: Path | StreamTextType) -> Any: """Load YAML content from a string while avoiding known ruamel.yaml issues.""" if not isinstance(stream, str): msg = f"expected a str but got {type(stream)}" @@ -951,7 +962,7 @@ text, preamble_comment = self._pre_process_yaml(stream) try: - data = self.load(stream=text) + data = super().load(stream=text) except ComposerError: data = self.load_all(stream=text) except ParserError: @@ -976,7 +987,11 @@ stream.write(preamble_comment) self.dump(data, stream) text = stream.getvalue() - return self._post_process_yaml(text) + strip_version_directive = hasattr(self, "_yaml_version_default") + return self._post_process_yaml( + text, + strip_version_directive=strip_version_directive, + ) def _prevent_wrapping_flow_style(self, data: Any) -> None: if not isinstance(data, (CommentedMap, CommentedSeq)): @@ -1064,7 +1079,7 @@ return text, "".join(preamble_comments) or None @staticmethod - def _post_process_yaml(text: str) -> str: + def _post_process_yaml(text: str, *, strip_version_directive: bool = False) -> str: """Handle known issues with ruamel.yaml dumping. Make sure there's only one newline at the end of the file. @@ -1076,6 +1091,10 @@ Make sure null list items don't end in a space. """ + # remove YAML directive + if strip_version_directive and text.startswith("%YAML"): + text = text.split("\n", 1)[1] + text = text.rstrip("\n") + "\n" lines = text.splitlines(keepends=True) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/test/conftest.py new/ansible-lint-6.22.0/test/conftest.py --- old/ansible-lint-6.21.1/test/conftest.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/test/conftest.py 2023-11-06 15:36:40.000000000 +0100 @@ -83,7 +83,7 @@ # Writing fixtures with ansiblelint.yaml_utils.FormattedYAML() for fixture in fixtures_dir_after.glob("fmt-[0-9].yml"): - data = yaml.loads(fixture.read_text()) + data = yaml.load(fixture.read_text()) output = yaml.dumps(data) fixture.write_text(output) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/test/schemas/package-lock.json new/ansible-lint-6.22.0/test/schemas/package-lock.json --- old/ansible-lint-6.21.1/test/schemas/package-lock.json 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/test/schemas/package-lock.json 2023-11-06 15:36:40.000000000 +0100 @@ -9,14 +9,14 @@ "js-yaml": "^4.1.0", "safe-stable-stringify": "^2.4.3", "ts-node": "^10.9.1", - "vscode-json-languageservice": "^5.3.6" + "vscode-json-languageservice": "^5.3.7" }, "devDependencies": { - "@types/chai": "^4.3.6", - "@types/js-yaml": "^4.0.6", + "@types/chai": "^4.3.9", + "@types/js-yaml": "^4.0.8", "@types/minimatch": "^5.1.2", - "@types/mocha": "^10.0.2", - "@types/node": "^20.7.1", + "@types/mocha": "^10.0.3", + "@types/node": "^20.8.10", "chai": "^4.3.10", "minimatch": "^9.0.3", "mocha": "^10.2.0", @@ -77,15 +77,15 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==" }, "node_modules/@types/chai": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.6.tgz", - "integrity": "sha512-VOVRLM1mBxIRxydiViqPcKn6MIxZytrbMpd6RJLIWKxUNr3zux8no0Oc7kJx0WAPIitgZ0gkrDS+btlqQpubpw==", + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.9.tgz", + "integrity": "sha512-69TtiDzu0bcmKQv3yg1Zx409/Kd7r0b5F1PfpYJfSHzLGtB53547V4u+9iqKYsTu/O2ai6KTb0TInNpvuQ3qmg==", "dev": true }, "node_modules/@types/js-yaml": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.6.tgz", - "integrity": "sha512-ACTuifTSIIbyksx2HTon3aFtCKWcID7/h3XEmRpDYdMCXxPbl+m9GteOJeaAkiAta/NJaSFuA7ahZ0NkwajDSw==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.8.tgz", + "integrity": "sha512-m6jnPk1VhlYRiLFm3f8X9Uep761f+CK8mHyS65LutH2OhmBF0BeMEjHgg05usH8PLZMWWc/BUR9RPmkvpWnyRA==", "dev": true }, "node_modules/@types/minimatch": { @@ -95,15 +95,18 @@ "dev": true }, "node_modules/@types/mocha": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.2.tgz", - "integrity": "sha512-NaHL0+0lLNhX6d9rs+NSt97WH/gIlRHmszXbQ/8/MV/eVcFNdeJ/GYhrFuUc8K7WuPhRhTSdMkCp8VMzhUq85w==", + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.3.tgz", + "integrity": "sha512-RsOPImTriV/OE4A9qKjMtk2MnXiuLLbcO3nCXK+kvq4nr0iMfFgpjaX3MPLb6f7+EL1FGSelYvuJMV6REH+ZPQ==", "dev": true }, "node_modules/@types/node": { - "version": "20.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz", - "integrity": "sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==" + "version": "20.8.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.10.tgz", + "integrity": "sha512-TlgT8JntpcbmKUFzjhsyhGfP2fsiz1Mv56im6enJ905xG1DAYesxJaeSbGqQmAw8OWPdhyJGhGSQGKRNJ45u9w==", + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@vscode/l10n": { "version": "0.0.16", @@ -1193,6 +1196,11 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -1207,31 +1215,31 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" }, "node_modules/vscode-json-languageservice": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-5.3.6.tgz", - "integrity": "sha512-P4kthBi3GMLKi7Lmp24nkKHAWxbFfCsIDBPlMrK1Tag1aqbl3l60UferDkfAasupDVBM2dekbArzGycUjw8OHA==", + "version": "5.3.7", + "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-5.3.7.tgz", + "integrity": "sha512-jdDggN2SLMQw4C/tLr11v6/OK4cMVGy7tbyZRHQvukQ6lcflY3UV+ZMkmwHKCqXz2TmxkjQb536eJW6JMEVeew==", "dependencies": { "@vscode/l10n": "^0.0.16", "jsonc-parser": "^3.2.0", - "vscode-languageserver-textdocument": "^1.0.8", - "vscode-languageserver-types": "^3.17.3", - "vscode-uri": "^3.0.7" + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-languageserver-types": "^3.17.5", + "vscode-uri": "^3.0.8" } }, "node_modules/vscode-languageserver-textdocument": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.8.tgz", - "integrity": "sha512-1bonkGqQs5/fxGT5UchTgjGVnfysL0O8v1AYMBjqTbWQTFn721zaPGDYFkOKtfDgFiSgXM3KwaG3FMGfW4Ed9Q==" + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.11.tgz", + "integrity": "sha512-X+8T3GoiwTVlJbicx/sIAF+yuJAqz8VvwJyoMVhwEMoEKE/fkDmrqUgDMyBECcM2A2frVZIUj5HI/ErRXCfOeA==" }, "node_modules/vscode-languageserver-types": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz", - "integrity": "sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==" + "version": "3.17.5", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz", + "integrity": "sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==" }, "node_modules/vscode-uri": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz", - "integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA==" + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.8.tgz", + "integrity": "sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==" }, "node_modules/workerpool": { "version": "6.2.1", @@ -1383,15 +1391,15 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==" }, "@types/chai": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.6.tgz", - "integrity": "sha512-VOVRLM1mBxIRxydiViqPcKn6MIxZytrbMpd6RJLIWKxUNr3zux8no0Oc7kJx0WAPIitgZ0gkrDS+btlqQpubpw==", + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.9.tgz", + "integrity": "sha512-69TtiDzu0bcmKQv3yg1Zx409/Kd7r0b5F1PfpYJfSHzLGtB53547V4u+9iqKYsTu/O2ai6KTb0TInNpvuQ3qmg==", "dev": true }, "@types/js-yaml": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.6.tgz", - "integrity": "sha512-ACTuifTSIIbyksx2HTon3aFtCKWcID7/h3XEmRpDYdMCXxPbl+m9GteOJeaAkiAta/NJaSFuA7ahZ0NkwajDSw==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.8.tgz", + "integrity": "sha512-m6jnPk1VhlYRiLFm3f8X9Uep761f+CK8mHyS65LutH2OhmBF0BeMEjHgg05usH8PLZMWWc/BUR9RPmkvpWnyRA==", "dev": true }, "@types/minimatch": { @@ -1401,15 +1409,18 @@ "dev": true }, "@types/mocha": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.2.tgz", - "integrity": "sha512-NaHL0+0lLNhX6d9rs+NSt97WH/gIlRHmszXbQ/8/MV/eVcFNdeJ/GYhrFuUc8K7WuPhRhTSdMkCp8VMzhUq85w==", + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.3.tgz", + "integrity": "sha512-RsOPImTriV/OE4A9qKjMtk2MnXiuLLbcO3nCXK+kvq4nr0iMfFgpjaX3MPLb6f7+EL1FGSelYvuJMV6REH+ZPQ==", "dev": true }, "@types/node": { - "version": "20.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz", - "integrity": "sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==" + "version": "20.8.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.10.tgz", + "integrity": "sha512-TlgT8JntpcbmKUFzjhsyhGfP2fsiz1Mv56im6enJ905xG1DAYesxJaeSbGqQmAw8OWPdhyJGhGSQGKRNJ45u9w==", + "requires": { + "undici-types": "~5.26.4" + } }, "@vscode/l10n": { "version": "0.0.16", @@ -2179,6 +2190,11 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -2193,31 +2209,31 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" }, "vscode-json-languageservice": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-5.3.6.tgz", - "integrity": "sha512-P4kthBi3GMLKi7Lmp24nkKHAWxbFfCsIDBPlMrK1Tag1aqbl3l60UferDkfAasupDVBM2dekbArzGycUjw8OHA==", + "version": "5.3.7", + "resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-5.3.7.tgz", + "integrity": "sha512-jdDggN2SLMQw4C/tLr11v6/OK4cMVGy7tbyZRHQvukQ6lcflY3UV+ZMkmwHKCqXz2TmxkjQb536eJW6JMEVeew==", "requires": { "@vscode/l10n": "^0.0.16", "jsonc-parser": "^3.2.0", - "vscode-languageserver-textdocument": "^1.0.8", - "vscode-languageserver-types": "^3.17.3", - "vscode-uri": "^3.0.7" + "vscode-languageserver-textdocument": "^1.0.11", + "vscode-languageserver-types": "^3.17.5", + "vscode-uri": "^3.0.8" } }, "vscode-languageserver-textdocument": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.8.tgz", - "integrity": "sha512-1bonkGqQs5/fxGT5UchTgjGVnfysL0O8v1AYMBjqTbWQTFn721zaPGDYFkOKtfDgFiSgXM3KwaG3FMGfW4Ed9Q==" + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.11.tgz", + "integrity": "sha512-X+8T3GoiwTVlJbicx/sIAF+yuJAqz8VvwJyoMVhwEMoEKE/fkDmrqUgDMyBECcM2A2frVZIUj5HI/ErRXCfOeA==" }, "vscode-languageserver-types": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz", - "integrity": "sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==" + "version": "3.17.5", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz", + "integrity": "sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==" }, "vscode-uri": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz", - "integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA==" + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.8.tgz", + "integrity": "sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==" }, "workerpool": { "version": "6.2.1", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/test/schemas/package.json new/ansible-lint-6.22.0/test/schemas/package.json --- old/ansible-lint-6.21.1/test/schemas/package.json 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/test/schemas/package.json 2023-11-06 15:36:40.000000000 +0100 @@ -4,7 +4,7 @@ "js-yaml": "^4.1.0", "safe-stable-stringify": "^2.4.3", "ts-node": "^10.9.1", - "vscode-json-languageservice": "^5.3.6" + "vscode-json-languageservice": "^5.3.7" }, "scripts": { "compile": "tsc -p ./src", @@ -12,11 +12,11 @@ "test": "python3 src/rebuild.py && mocha" }, "devDependencies": { - "@types/chai": "^4.3.6", - "@types/js-yaml": "^4.0.6", + "@types/chai": "^4.3.9", + "@types/js-yaml": "^4.0.8", "@types/minimatch": "^5.1.2", - "@types/mocha": "^10.0.2", - "@types/node": "^20.7.1", + "@types/mocha": "^10.0.3", + "@types/node": "^20.8.10", "chai": "^4.3.10", "minimatch": "^9.0.3", "mocha": "^10.2.0", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansible-lint-6.21.1/test/test_yaml_utils.py new/ansible-lint-6.22.0/test/test_yaml_utils.py --- old/ansible-lint-6.21.1/test/test_yaml_utils.py 2023-10-19 18:04:45.000000000 +0200 +++ new/ansible-lint-6.22.0/test/test_yaml_utils.py 2023-11-06 15:36:40.000000000 +0100 @@ -202,8 +202,7 @@ assert output == expected_output -@pytest.fixture(name="yaml_formatting_fixtures") -def fixture_yaml_formatting_fixtures(fixture_filename: str) -> tuple[str, str, str]: +def load_yaml_formatting_fixtures(fixture_filename: str) -> tuple[str, str, str]: """Get the contents for the formatting fixture files. To regenerate these fixtures, please run ``pytest --regenerate-formatting-fixtures``. @@ -220,32 +219,67 @@ @pytest.mark.parametrize( - "fixture_filename", + ("before", "after", "version"), ( - pytest.param("fmt-1.yml", id="1"), - pytest.param("fmt-2.yml", id="2"), - pytest.param("fmt-3.yml", id="3"), - pytest.param("fmt-4.yml", id="4"), - pytest.param("fmt-5.yml", id="5"), + pytest.param("---\nfoo: bar\n", "---\nfoo: bar\n", None, id="1"), + # verify that 'on' is not translated to bool (1.2 behavior) + pytest.param("---\nfoo: on\n", "---\nfoo: on\n", None, id="2"), + # When version is manually mentioned by us, we expect to output without version directive + pytest.param("---\nfoo: on\n", "---\nfoo: on\n", (1, 2), id="3"), + pytest.param("---\nfoo: on\n", "---\nfoo: true\n", (1, 1), id="4"), + pytest.param("%YAML 1.1\n---\nfoo: on\n", "---\nfoo: true\n", (1, 1), id="5"), + # verify that in-line directive takes precedence but dumping strips if we mention a specific version + pytest.param("%YAML 1.1\n---\nfoo: on\n", "---\nfoo: true\n", (1, 2), id="6"), + # verify that version directive are kept if present + pytest.param("%YAML 1.1\n---\nfoo: on\n", "---\nfoo: true\n", None, id="7"), + pytest.param( + "%YAML 1.2\n---\nfoo: on\n", + "%YAML 1.2\n---\nfoo: on\n", + None, + id="8", + ), + pytest.param("---\nfoo: YES\n", "---\nfoo: true\n", (1, 1), id="9"), + pytest.param("---\nfoo: YES\n", "---\nfoo: YES\n", (1, 2), id="10"), + pytest.param("---\nfoo: YES\n", "---\nfoo: YES\n", None, id="11"), + ), +) +def test_fmt(before: str, after: str, version: tuple[int, int] | None) -> None: + """Tests behavior of formatter in regards to different YAML versions, specified or not.""" + yaml = ansiblelint.yaml_utils.FormattedYAML(version=version) + data = yaml.load(before) + result = yaml.dumps(data) + assert result == after + + +@pytest.mark.parametrize( + ("fixture_filename", "version"), + ( + pytest.param("fmt-1.yml", (1, 1), id="1"), + pytest.param("fmt-2.yml", (1, 1), id="2"), + pytest.param("fmt-3.yml", (1, 1), id="3"), + pytest.param("fmt-4.yml", (1, 1), id="4"), + pytest.param("fmt-5.yml", (1, 1), id="5"), ), ) def test_formatted_yaml_loader_dumper( - yaml_formatting_fixtures: tuple[str, str, str], - fixture_filename: str, # noqa: ARG001 + fixture_filename: str, + version: tuple[int, int], ) -> None: """Ensure that FormattedYAML loads/dumps formatting fixtures consistently.""" # pylint: disable=unused-argument - before_content, prettier_content, after_content = yaml_formatting_fixtures + before_content, prettier_content, after_content = load_yaml_formatting_fixtures( + fixture_filename, + ) assert before_content != prettier_content assert before_content != after_content - yaml = ansiblelint.yaml_utils.FormattedYAML() + yaml = ansiblelint.yaml_utils.FormattedYAML(version=version) - data_before = yaml.loads(before_content) + data_before = yaml.load(before_content) dump_from_before = yaml.dumps(data_before) - data_prettier = yaml.loads(prettier_content) + data_prettier = yaml.load(prettier_content) dump_from_prettier = yaml.dumps(data_prettier) - data_after = yaml.loads(after_content) + data_after = yaml.load(after_content) dump_from_after = yaml.dumps(data_after) # comparing data does not work because the Comment objects @@ -276,7 +310,7 @@ def fixture_ruamel_data(lintable: Lintable) -> CommentedMap | CommentedSeq: """Return the loaded YAML data for the Lintable.""" yaml = ansiblelint.yaml_utils.FormattedYAML() - data: CommentedMap | CommentedSeq = yaml.loads(lintable.content) + data: CommentedMap | CommentedSeq = yaml.load(lintable.content) return data