Skip to content

Commit

Permalink
Remove rich as a dependency
Browse files Browse the repository at this point in the history
Related: #4396 AAP-36125
  • Loading branch information
ssbarnea committed Dec 4, 2024
1 parent a5fbd7c commit d5c4a7a
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 128 deletions.
5 changes: 1 addition & 4 deletions .config/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ linkchecker==10.5.0 # via mkdocs-ansible
markdown==3.7 # via markdown-include, mkdocs, mkdocs-autorefs, mkdocs-htmlproofer-plugin, mkdocs-material, mkdocstrings, pymdown-extensions
markdown-exec==1.9.3 # via mkdocs-ansible
markdown-include==0.8.1 # via mkdocs-ansible
markdown-it-py==3.0.0 # via rich
markupsafe==3.0.2 # via jinja2, mkdocs, mkdocs-autorefs, mkdocstrings
mccabe==0.7.0 # via pylint
mdurl==0.1.2 # via markdown-it-py
mergedeep==1.3.4 # via mkdocs, mkdocs-get-deps
mkdocs==1.6.1 # via mkdocs-ansible, mkdocs-autorefs, mkdocs-gen-files, mkdocs-htmlproofer-plugin, mkdocs-macros-plugin, mkdocs-material, mkdocs-minify-plugin, mkdocs-monorepo-plugin, mkdocstrings
mkdocs-ansible==24.12.0 # via ansible-lint (pyproject.toml)
Expand All @@ -76,7 +74,7 @@ platformdirs==4.3.6 # via black, mkdocs-get-deps, mkdocstrings, pylint, to
pluggy==1.5.0 # via pytest, tox
psutil==6.1.0 # via pytest-xdist, ansible-lint (pyproject.toml)
pycparser==2.22 # via cffi
pygments==2.18.0 # via mkdocs-material, rich
pygments==2.18.0 # via mkdocs-material
pylint==3.3.2 # via ansible-lint (pyproject.toml)
pymdown-extensions==10.12 # via markdown-exec, mkdocs-ansible, mkdocs-material, mkdocstrings
pyproject-api==1.8.0 # via tox
Expand All @@ -92,7 +90,6 @@ pyyaml-env-tag==0.1 # via mkdocs
referencing==0.35.1 # via jsonschema, jsonschema-specifications, types-jsonschema
regex==2024.11.6 # via mkdocs-material
requests==2.32.3 # via linkchecker, mkdocs-htmlproofer-plugin, mkdocs-material
rich==13.9.4 # via ansible-lint (pyproject.toml)
rpds-py==0.22.1 # via jsonschema, referencing
ruamel-yaml==0.18.6 # via ansible-lint (pyproject.toml)
ruamel-yaml-clib==0.2.12 # via ruamel-yaml, ansible-lint (pyproject.toml)
Expand Down
4 changes: 0 additions & 4 deletions .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ importlib-metadata==8.5.0 # via ansible-lint (pyproject.toml)
jinja2==3.1.4 # via ansible-core
jsonschema==4.23.0 # via ansible-compat, ansible-lint (pyproject.toml)
jsonschema-specifications==2024.10.1 # via jsonschema
markdown-it-py==3.0.0 # via rich
markupsafe==3.0.2 # via jinja2
mdurl==0.1.2 # via markdown-it-py
mypy-extensions==1.0.0 # via black
packaging==24.2 # via ansible-compat, ansible-core, black, ansible-lint (pyproject.toml)
pathspec==0.12.1 # via black, yamllint, ansible-lint (pyproject.toml)
platformdirs==4.3.6 # via black
pycparser==2.22 # via cffi
pygments==2.18.0 # via rich
pyyaml==6.0.2 # via ansible-compat, ansible-core, yamllint, ansible-lint (pyproject.toml)
referencing==0.35.1 # via jsonschema, jsonschema-specifications
rich==13.9.4 # via ansible-lint (pyproject.toml)
rpds-py==0.22.1 # via jsonschema, referencing
ruamel-yaml==0.18.6 # via ansible-lint (pyproject.toml)
ruamel-yaml-clib==0.2.12 # via ruamel-yaml
Expand Down
1 change: 0 additions & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jsonschema>=4.10.0 # MIT, version needed for improved errors
packaging>=21.3 # Apache-2.0,BSD-2-Clause
pathspec>=0.10.3 # Mozilla Public License 2.0 (MPL 2.0)
pyyaml>=5.4.1 # MIT (centos 9 has 5.3.1)
rich>=12.0.0 # MIT
ruamel.yaml>=0.18.5 # MIT
subprocess-tee>=0.4.1 # MIT, used by ansible-compat
yamllint >= 1.30.0 # GPLv3
Expand Down
13 changes: 13 additions & 0 deletions .config/vulture_whitelist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
_.configured # unused attribute (src/ansiblelint/__main__.py:140)
configured # unused variable (src/ansiblelint/config.py:132)
_.keep_trailing_newline # unused attribute (src/ansiblelint/rules/jinja.py:280)
Expand All @@ -13,3 +14,15 @@
_.compact_seq_map # unused attribute (src/ansiblelint/yaml_utils.py:925)
_.Constructor # unused attribute (src/ansiblelint/yaml_utils.py:946)
_.preserve_quotes # unused attribute (src/ansiblelint/yaml_utils.py:956)
_.BLACK # unused variable (src/ansiblelint/output.py:172)
_.YELLOW # unused variable (src/ansiblelint/output.py:175)
_.CYAN # unused variable (src/ansiblelint/output.py:178)
_.WHITE # unused variable (src/ansiblelint/output.py:179)
_.GREY # unused variable (src/ansiblelint/output.py:180)
_.BRIGHT_RED # unused variable (src/ansiblelint/output.py:181)
_.BRIGHT_GREEN # unused variable (src/ansiblelint/output.py:182)
_.BRIGHT_YELLOW # unused variable (src/ansiblelint/output.py:183)
_.BRIGHT_BLUE # unused variable (src/ansiblelint/output.py:184)
_.BRIGHT_MAGENTA # unused variable (src/ansiblelint/output.py:185)
_.BRIGHT_CYAN # unused variable (src/ansiblelint/output.py:186)
_.BRIGHT_WHITE # unused variable (src/ansiblelint/output.py:187)
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ repos:
- pytest-mock
- pytest>=7.2.2
- pip>=22.3.1
- rich>=13.2.0
- ruamel-yaml-clib>=0.2.8
- ruamel-yaml>=0.18.6
- subprocess-tee
Expand Down Expand Up @@ -195,7 +194,6 @@ repos:
- pip>=22.3.1
- pytest-mock
- pytest>=7.2.2
- rich>=13.2.0
- ruamel-yaml-clib>=0.2.8
- ruamel-yaml>=0.18.6
- subprocess-tee
Expand All @@ -222,7 +220,6 @@ repos:
- pytest-mock
- pytest>=7.2.2
- pyyaml
- rich>=13.2.0
- ruamel-yaml-clib>=0.2.7
- ruamel-yaml>=0.18.2
- setuptools # needed for pkg_resources import
Expand Down
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dictionaries:
- bash
- words
- python
enabled: true
ignorePaths:
- cspell.config.yaml
# The requirements file
Expand Down
15 changes: 5 additions & 10 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

from ansible_compat.prerun import get_cache_dir
from filelock import BaseFileLock, FileLock, Timeout
from rich.markdown import Markdown
from rich.markup import escape

from ansiblelint.constants import RC, SKIP_SCHEMA_UPDATE

Expand All @@ -61,7 +59,6 @@
from ansiblelint.loaders import load_ignore_txt
from ansiblelint.output import (
console,
console_options,
console_stderr,
reconfigure,
render_yaml,
Expand All @@ -86,7 +83,7 @@ class LintLogHandler(logging.Handler):
def emit(self, record: logging.LogRecord) -> None:
try:
msg = self.format(record)
console_stderr.print(f"[dim]{msg}[/dim]", highlight=False)
console_stderr.print(f"[dim]{msg}[/]")
except RecursionError: # See issue 36272
raise
except Exception: # pylint: disable=broad-exception-caught # noqa: BLE001
Expand Down Expand Up @@ -170,7 +167,6 @@ def _do_list(rules: RulesCollection) -> int:
if options.list_rules:
console.print(
rules_as_str(rules),
highlight=False,
)
return 0

Expand Down Expand Up @@ -282,16 +278,15 @@ def main(argv: list[str] | None = None) -> int:
argv = sys.argv
cache_dir_lock = initialize_options(argv[1:])

console_options["force_terminal"] = options.colored
reconfigure(console_options)
reconfigure(colored=options.colored)

if options.version:
deps = get_deps_versions()
msg = f"ansible-lint [repr.number]{__version__}[/] using[dim]"
for k, v in deps.items():
msg += f" {escape(k)}:[repr.number]{v}[/]"
msg += f" {k}:[repr.number]{v}[/]"
msg += "[/]"
console.print(msg, markup=True, highlight=False)
console.print(msg, markup=True)
msg = get_version_warning()
if msg:
console.print(msg)
Expand Down Expand Up @@ -334,7 +329,7 @@ def main(argv: list[str] | None = None) -> int:
if options.list_profiles:
from ansiblelint.generate_docs import profiles_as_md

console.print(Markdown(profiles_as_md()))
profiles_as_md().display()
return 0

app = get_app(
Expand Down
34 changes: 6 additions & 28 deletions src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from typing import TYPE_CHECKING, Any

from ansible_compat.runtime import Runtime
from rich.markup import escape
from rich.table import Table

from ansiblelint import formatters
from ansiblelint._mockings import _perform_mockings
Expand Down Expand Up @@ -83,7 +81,6 @@ def render_matches(self, matches: list[MatchError]) -> None:
console.print(
self.formatter.format_result(matches),
markup=False,
highlight=False,
)
return

Expand All @@ -97,16 +94,15 @@ def render_matches(self, matches: list[MatchError]) -> None:
)
for match in ignored_matches:
if match.ignored:
# highlight must be off or apostrophes may produce unexpected results
console.print(self.formatter.apply(match), highlight=False)
console.print(self.formatter.apply(match))
if fatal_matches:
_logger.warning(
"Listing %s violation(s) that are fatal",
len(fatal_matches),
)
for match in fatal_matches:
if not match.ignored:
console.print(self.formatter.apply(match), highlight=False)
console.print(self.formatter.apply(match))

# If run under GitHub Actions we also want to emit output recognized by it.
if os.getenv("GITHUB_ACTIONS") == "true" and os.getenv("GITHUB_WORKFLOW"):
Expand All @@ -118,7 +114,6 @@ def render_matches(self, matches: list[MatchError]) -> None:
console_stderr.print(
formatter.apply(match),
markup=False,
highlight=False,
)

# If sarif_file is set, we also dump the results to a sarif file.
Expand Down Expand Up @@ -316,33 +311,16 @@ def report_summary( # pylint: disable=too-many-locals # noqa: C901

stars = ""
if summary.tag_stats:
table = Table(
title="Rule Violation Summary",
collapse_padding=True,
box=None,
show_lines=False,
)
table.add_column("count", justify="right")
table.add_column("tag")
table.add_column("profile")
table.add_column("rule associated tags")
table = "# Rule Violation Summary\n\n"
for tag, stats in summary.tag_stats.items():
table.add_row(
str(stats.count),
f"[link={RULE_DOC_URL}{tag.split('[')[0]}]{escape(tag)}[/link]",
stats.profile,
f"{', '.join(stats.associated_tags)}{' (warning)' if stats.warning else ''}",
style="yellow" if stats.warning else "red",
)
# rate stars for the top 5 profiles (min would not get
table += f"{stats.count:3} [link={RULE_DOC_URL}]{tag.split('[')[0]}[/link] [dim]profile:{profile} tags:{','.join(stats.associated_tags)}[/]\n"
rating = 5 - (len(PROFILES.keys()) - passed_profile_count)
if 0 < rating < 6:
stars = f" Rating: {rating}/5 star"

console_stderr.print(table)
console_stderr.print()
console.print(table, file=sys.stderr)

msg = "[green]Passed[/]" if is_success else "[red][bold]Failed[/][/]"
msg = "[success]Passed[/]" if is_success else "[failed][bold]Failed[/][/]"

msg += f": {summary.failures} failure(s), {summary.warnings} warning(s)"
if summary.fixed:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def get_config(arguments: list[str]) -> Options:
log_entries.append(
(
logging.INFO,
f"Identified [filename]{project_dir}[/] as project root due [bold]{method}[/].",
f"Identified [repr.path]{project_dir}[/] as project root due [bold]{method}[/].",
),
)

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def get_version_warning() -> str:
if current_version > new_version:
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}[/][/][/]"""
msg = f"""[warning]A new release of ansible-lint is available: [warning]{current_version}[/] → [success][link={html_url}]{new_version}[/link][/][/]"""
msg += f" Upgrade by running: [info]{pip}[/]"

return msg
16 changes: 7 additions & 9 deletions src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Generic, TypeVar

from rich.markup import escape

from ansiblelint.config import options
from ansiblelint.version import __version__

Expand Down Expand Up @@ -58,22 +56,22 @@ def apply(self, match: MatchError) -> str:
@staticmethod
def escape(text: str) -> str:
"""Escapes a string to avoid processing it as markup."""
return escape(text)
return text # escape(text)


class Formatter(BaseFormatter): # type: ignore[type-arg]
"""Default output formatter of ansible-lint."""

def apply(self, match: MatchError) -> str:
_id = getattr(match.rule, "id", "000")
result = f"[{match.level}][bold][link={match.rule.url}]{self.escape(match.tag)}[/link][/][/][dim]:[/] [{match.level}]{self.escape(match.message)}[/]"
result = f"[{match.level}][link={match.rule.url}]{match.tag}[/link][dim]:[/] [{match.level}]{self.escape(match.message)}[/]"
if match.level != "error":
result += f" [dim][{match.level}]({match.level})[/][/]"
result += f" [dim][{match.level}]({match.level})[/]"
if match.ignored:
result += " [dim]# ignored[/]"
result += (
"\n"
f"[filename]{self._format_path(match.filename or '')}[/]:{match.position}"
f"[repr.path]{self._format_path(match.filename or '')}[/]:{match.position}"
)
if match.details:
result += f" [dim]{self.escape(str(match.details))}[/]"
Expand All @@ -87,7 +85,7 @@ class QuietFormatter(BaseFormatter[Any]):
def apply(self, match: MatchError) -> str:
return (
f"[{match.level}]{match.rule.id}[/] "
f"[filename]{self._format_path(match.filename or '')}[/]:{match.position}"
f"[repr.path]{self._format_path(match.filename or '')}[/]:{match.position}"
)


Expand All @@ -96,8 +94,8 @@ class ParseableFormatter(BaseFormatter[Any]):

def apply(self, match: MatchError) -> str:
result = (
f"[filename]{self._format_path(match.filename or '')}[/][dim]:{match.position}:[/] "
f"[{match.level}][bold]{self.escape(match.tag)}[/bold]"
f"[repr.path]{self._format_path(match.filename or '')}[/][dim]:{match.position}:[/] "
f"[{match.level}][bold]{self.escape(match.tag)}[/]"
f"{ f': {match.message}' if not options.quiet else '' }[/]"
)
if match.level != "error":
Expand Down
7 changes: 4 additions & 3 deletions src/ansiblelint/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ansiblelint.config import PROFILES
from ansiblelint.constants import RULE_DOC_URL
from ansiblelint.output import Markdown
from ansiblelint.rules import RulesCollection, TransformMixin


Expand All @@ -12,7 +13,7 @@ def rules_as_str(rules: RulesCollection) -> str:
if issubclass(rule.__class__, TransformMixin):
rule.tags.insert(0, "autofix")
tag = f"{','.join(rule.tags)}" if rule.tags else ""
result += f"- [repr.url][link={RULE_DOC_URL}{rule.id}/]{rule.id}[/link][/] {rule.shortdesc}\n[dim] tags:{tag}[/dim]"
result += f"- [link={RULE_DOC_URL}{rule.id}/]{rule.id}[/link] {rule.shortdesc}\n[dim] tags:{tag}[/]"

if rule.version_changed and rule.version_changed != "historic":
result += f"[dim] modified:{rule.version_changed}[/]"
Expand All @@ -21,7 +22,7 @@ def rules_as_str(rules: RulesCollection) -> str:
return result


def profiles_as_md(*, header: bool = False, docs_url: str = RULE_DOC_URL) -> str:
def profiles_as_md(*, header: bool = False, docs_url: str = RULE_DOC_URL) -> Markdown:
"""Return markdown representation of supported profiles."""
result = ""

Expand Down Expand Up @@ -57,4 +58,4 @@ def profiles_as_md(*, header: bool = False, docs_url: str = RULE_DOC_URL) -> str
result += f"- [{rule}]({rule_data['url']})\n"

result += "\n"
return result
return Markdown(result)
Loading

0 comments on commit d5c4a7a

Please sign in to comment.