Skip to content

Commit

Permalink
Avoid adding pip related messages if installation method is different
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka committed Jun 12, 2023
1 parent 519ecd6 commit df7479c
Showing 1 changed file with 10 additions and 2 deletions.
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]
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("ansible-lint").read_text("INSTALLER").strip() != "pip": # type: ignore[union-attr]
return ""
except PackageNotFoundError as exc:
logging.debug(exc)
return ""

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

0 comments on commit df7479c

Please sign in to comment.