Skip to content

Commit

Permalink
Relax ruamel-yaml requirements (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 12, 2023
1 parent bbdd0fe commit b97bf14
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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
2 changes: 1 addition & 1 deletion .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit b97bf14

Please sign in to comment.