Skip to content

Commit

Permalink
Avoid displaying upgrade warning when installation is not pip (#4204)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jun 4, 2024
1 parent 7e2f62e commit 528275b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 874
PYTEST_REQPASS: 875
steps:
- uses: actions/checkout@v4
with:
Expand Down
10 changes: 6 additions & 4 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ def get_version_warning() -> str:
# 0.1dev1 is special fallback version
if __version__ == "0.1.dev1": # pragma: no cover
return ""
pip = guess_install_method()
# If we do not know how to upgrade, we do not want to show any warnings
# about version.
if not pip:
return ""

msg = ""
data = {}
Expand Down Expand Up @@ -332,9 +337,6 @@ def get_version_warning() -> str:
msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
elif current_version < new_version:
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""

pip = guess_install_method()
if pip:
msg += f" Upgrade by running: [info]{pip}[/]"
msg += f" Upgrade by running: [info]{pip}[/]"

return msg
6 changes: 6 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def test_get_version_warning(
assert len(msg.split("\n")) == outlen


def test_get_version_warning_no_pip(mocker: MockerFixture) -> None:
"""Test that we do not display any message if install method is not pip."""
mocker.patch("ansiblelint.config.guess_install_method", return_value="")
assert get_version_warning() == ""


@pytest.mark.parametrize(
("lintable"),
(
Expand Down

0 comments on commit 528275b

Please sign in to comment.