Skip to content

Commit

Permalink
Remove enrich as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 5, 2022
1 parent d8c0828 commit fd56ae9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
1 change: 0 additions & 1 deletion .config/ansible-lint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ BuildRequires: git
%endif
# Named based on fedora 35:
Requires: ansible-core >= 2.12.0
Requires: python3-enrich
Requires: python3-packaging
Requires: python3-pyyaml
Requires: python3-rich
Expand Down
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ repos:
- ansible-compat>=2.2.0
- ansible-core
- black
- enrich
- filelock
- flaky
- pytest
Expand Down Expand Up @@ -170,7 +169,6 @@ repos:
- ansible-core
- black
- docutils
- enrich
- filelock
- flaky
- jsonschema>=4.9.0
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ coverage-enable-subprocess==1.0
cryptography==38.0.1
dill==0.3.5.1
docutils==0.17.1
enrich==1.2.7
execnet==1.9.0
filelock==3.8.0
flake8==5.0.4
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ install_requires =
ansible-compat>=2.2.1 # GPLv3
ansible-core>=2.12.0 # GPLv3
black>=22.1.0 # MIT
enrich>=1.2.6
filelock # The Unlicense
jsonschema>=4.9.0 # MIT, version needed for improved errors
packaging
Expand Down
48 changes: 46 additions & 2 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
import subprocess
import sys
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Callable, Iterator
from typing import TYPE_CHECKING, Any, Callable, Iterator, TextIO

from ansible_compat.config import ansible_version
from ansible_compat.prerun import get_cache_dir
from enrich.console import should_do_markup
from filelock import FileLock, Timeout

from ansiblelint import cli
Expand Down Expand Up @@ -350,5 +349,50 @@ def path_inject() -> None:
raise RuntimeError("Failed to find ansible executable in PATH")


# Based on Ansible implementation
def to_bool(value: Any) -> bool:
"""Return a bool for the arg."""
if value is None or isinstance(value, bool):
return bool(value)
if isinstance(value, str):
value = value.lower()
if value in ("yes", "on", "1", "true", 1):
return True
return False


def should_do_markup(stream: TextIO = sys.stdout) -> bool:
"""Decide about use of ANSI colors."""
py_colors = None

# https://xkcd.com/927/
for env_var in ["PY_COLORS", "CLICOLOR", "FORCE_COLOR", "ANSIBLE_FORCE_COLOR"]:
value = os.environ.get(env_var, None)
if value is not None:
py_colors = to_bool(value)
break

# If deliverately disabled colors
if os.environ.get("NO_COLOR", None):
return False

# User configuration requested colors
if py_colors is not None:
return to_bool(py_colors)

term = os.environ.get("TERM", "")
if "xterm" in term:
return True

if term == "dumb":
return False

# Use tty detection logic as last resort because there are numerous
# factors that can make isatty return a misleading value, including:
# - stdin.isatty() is the only one returning true, even on a real terminal
# - stderr returting false if user user uses a error stream coloring solution
return stream.isatty()


if __name__ == "__main__":
_run_cli_entrypoint()

0 comments on commit fd56ae9

Please sign in to comment.