Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid displaying upgrade warning when installation is not pip #4204

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading