Skip to content

Commit 528275b

Browse files
authored
Avoid displaying upgrade warning when installation is not pip (#4204)
1 parent 7e2f62e commit 528275b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
env:
7373
# Number of expected test passes, safety measure for accidental skip of
7474
# tests. Update value if you add/remove tests.
75-
PYTEST_REQPASS: 874
75+
PYTEST_REQPASS: 875
7676
steps:
7777
- uses: actions/checkout@v4
7878
with:

src/ansiblelint/config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ def get_version_warning() -> str:
292292
# 0.1dev1 is special fallback version
293293
if __version__ == "0.1.dev1": # pragma: no cover
294294
return ""
295+
pip = guess_install_method()
296+
# If we do not know how to upgrade, we do not want to show any warnings
297+
# about version.
298+
if not pip:
299+
return ""
295300

296301
msg = ""
297302
data = {}
@@ -332,9 +337,6 @@ def get_version_warning() -> str:
332337
msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
333338
elif current_version < new_version:
334339
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""
335-
336-
pip = guess_install_method()
337-
if pip:
338-
msg += f" Upgrade by running: [info]{pip}[/]"
340+
msg += f" Upgrade by running: [info]{pip}[/]"
339341

340342
return msg

test/test_main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ def test_get_version_warning(
8686
assert len(msg.split("\n")) == outlen
8787

8888

89+
def test_get_version_warning_no_pip(mocker: MockerFixture) -> None:
90+
"""Test that we do not display any message if install method is not pip."""
91+
mocker.patch("ansiblelint.config.guess_install_method", return_value="")
92+
assert get_version_warning() == ""
93+
94+
8995
@pytest.mark.parametrize(
9096
("lintable"),
9197
(

0 commit comments

Comments
 (0)