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 adding pip related messages if installation method is different #3551

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import warnings
from dataclasses import dataclass, field
from functools import lru_cache
from importlib.metadata import PackageNotFoundError, version
from importlib.metadata import PackageNotFoundError, distribution, version
from pathlib import Path
from typing import TYPE_CHECKING, Any
from urllib.error import HTTPError, URLError
Expand Down Expand Up @@ -152,7 +152,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me
config_file: str | None = None
generate_ignore: bool = False
rulesdir: list[Path] = field(default_factory=list)
cache_dir_lock: FileLock | None = None
cache_dir_lock: FileLock | None = None # type: ignore[valid-type]
audgirka marked this conversation as resolved.
Show resolved Hide resolved
use_default_rules: bool = False
version: bool = False # display version command
list_profiles: bool = False # display profiles command
Expand Down Expand Up @@ -205,6 +205,14 @@ def in_venv() -> bool:
def guess_install_method() -> str:
"""Guess if pip upgrade command should be used."""
package_name = "ansible-lint"

try:
if distribution(package_name).read_text("INSTALLER").strip() != "pip": # type: ignore[union-attr]
audgirka marked this conversation as resolved.
Show resolved Hide resolved
return ""
except PackageNotFoundError as exc:
logging.debug(exc)
return ""

pip = ""
if in_venv():
_logger.debug("Found virtualenv, assuming `pip3 install` will work.")
Expand Down