Skip to content

Commit

Permalink
Require ruamel.yaml >= 0.18.5 (#3880)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Nov 6, 2023
1 parent 348c385 commit 4113104
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ black==23.10.1
bracex==2.4
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.1
charset-normalizer==3.3.2
click==8.1.7
cryptography==41.0.5
filelock==3.13.0
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
Expand All @@ -34,7 +34,7 @@ referencing==0.30.2
requests==2.31.0
rich==13.6.0
rpds-py==0.10.6
ruamel-yaml==0.18.3
ruamel-yaml==0.18.5
subprocess-tee==0.4.1
tomli==2.0.1
typing-extensions==4.8.0
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packaging>=21.3 # Apache-2.0,BSD-2-Clause
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.17.29,!=0.17.30 # MIT
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
Expand Down
10 changes: 5 additions & 5 deletions .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defusedxml==0.7.1
dill==0.3.7
exceptiongroup==1.1.3
execnet==2.0.2
filelock==3.13.0
filelock==3.13.1
ghp-import==2.1.0
griffe==0.36.4
htmlmin2==0.1.13
Expand All @@ -41,7 +41,7 @@ isort==5.12.0
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
license-expression==30.1.1
markdown==3.4.4
Expand Down Expand Up @@ -91,15 +91,15 @@ regex==2023.8.8
requests==2.31.0
rich==13.6.0
rpds-py==0.10.6
ruamel-yaml==0.18.3
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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ repos:
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
Expand Down
12 changes: 6 additions & 6 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if TYPE_CHECKING:
# noinspection PyProtectedMember
from ruamel.yaml.comments import LineCol
from ruamel.yaml.compat import StreamTextType, VersionType
from ruamel.yaml.compat import StreamTextType
from ruamel.yaml.nodes import ScalarNode
from ruamel.yaml.representer import RoundTripRepresenter
from ruamel.yaml.tokens import CommentToken
Expand Down Expand Up @@ -758,7 +758,7 @@ def __init__( # pylint: disable=too-many-arguments
pure: bool = False,
output: Any = None,
plug_ins: list[str] | None = None,
version: VersionType | None = None,
version: tuple[int, int] | None = None,
):
"""Return a configured ``ruamel.yaml.YAML`` instance.
Expand Down Expand Up @@ -822,8 +822,8 @@ def __init__( # pylint: disable=too-many-arguments
if isinstance(version, str):
x, y = version.split(".", maxsplit=1)
version = (int(x), int(y))
self._yaml_version_default: VersionType = version
self._yaml_version: VersionType = self._yaml_version_default
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.
Expand Down Expand Up @@ -925,7 +925,7 @@ def _defaults_from_yamllint_config() -> dict[str, bool | int | str]:
return cast(dict[str, Union[bool, int, str]], config)

@property
def version(self) -> VersionType | None:
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.
Expand All @@ -938,7 +938,7 @@ def version(self) -> VersionType | None:
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.
Expand Down
14 changes: 7 additions & 7 deletions test/schemas/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/js-yaml": "^4.0.8",
"@types/minimatch": "^5.1.2",
"@types/mocha": "^10.0.3",
"@types/node": "^20.8.9",
"@types/node": "^20.8.10",
"chai": "^4.3.10",
"minimatch": "^9.0.3",
"mocha": "^10.2.0",
Expand Down
3 changes: 1 addition & 2 deletions test/test_yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

if TYPE_CHECKING:
from ruamel.yaml.comments import CommentedMap, CommentedSeq
from ruamel.yaml.compat import VersionType
from ruamel.yaml.emitter import Emitter

fixtures_dir = Path(__file__).parent / "fixtures"
Expand Down Expand Up @@ -244,7 +243,7 @@ def load_yaml_formatting_fixtures(fixture_filename: str) -> tuple[str, str, str]
pytest.param("---\nfoo: YES\n", "---\nfoo: YES\n", None, id="11"),
),
)
def test_fmt(before: str, after: str, version: VersionType) -> None:
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)
Expand Down

0 comments on commit 4113104

Please sign in to comment.