Skip to content

Commit

Permalink
feat: add a --versions option to view all plugin versions (#242)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Aug 23, 2024
1 parent ac4da96 commit 51ca05f
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions src/repo_review/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib.metadata
import itertools
import json
import os
Expand Down Expand Up @@ -74,6 +75,29 @@ def list_all(ctx: click.Context, _param: click.Parameter, value: bool) -> None:
ctx.exit()


def all_versions(ctx: click.Context, _param: click.Parameter, value: bool) -> None:
if not value or ctx.resilient_parsing:
return

groups = ["repo_review.checks", "repo_review.families", "repo_review.fixtures"]
packages = {
dist.name: dist.version
for group in groups
for ep in importlib.metadata.entry_points(group=group)
if (dist := ep.dist) is not None
}
deps = ["rich", "rich-click", "click", "markdown-it-py", "pyyaml"]
rich.print("Repo-review's dependencies:")
for name in deps:
rich.print(
f" [bold]{name}[/bold]: [magenta]{importlib.metadata.version(name)}[/magenta]"
)
rich.print("Packages providing repo-review plugins:")
for name, version in sorted(packages.items()):
rich.print(f" [bold]{name}[/bold]: [green]{version}[/green]")
ctx.exit()


def rich_printer(
families: Mapping[str, Family],
processed: list[Result],
Expand Down Expand Up @@ -243,9 +267,25 @@ def _remote_path_processor(package: Path) -> Path | GHPath:
"packages",
type=click.Path(dir_okay=True, path_type=Path),
nargs=-1,
required=True,
required=False,
callback=remote_path_support,
)
@click.option(
"--versions",
is_flag=True,
callback=all_versions,
expose_value=False,
is_eager=True,
help="List all plugin versions and exit",
)
@click.option(
"--list-all",
is_flag=True,
callback=list_all,
expose_value=False,
is_eager=True,
help="List all checks and exit",
)
@click.option(
"--format",
"format_opt",
Expand All @@ -259,6 +299,12 @@ def _remote_path_processor(package: Path) -> Path | GHPath:
type=click.Choice(["rich", "json", "html", "svg"]),
help="Select additional output format for stderr. Will disable terminal escape codes for stdout for easy redirection.",
)
@click.option(
"--show",
type=click.Choice(["all", "err", "errskip"]),
default="all",
help="Show all (default), or just errors, or errors and skips",
)
@click.option(
"--select",
help="Only run certain checks, comma separated. All checks run if empty.",
Expand All @@ -275,20 +321,6 @@ def _remote_path_processor(package: Path) -> Path | GHPath:
help="Path to python package.",
default="",
)
@click.option(
"--list-all",
is_flag=True,
callback=list_all,
expose_value=False,
is_eager=True,
help="List all checks and exit",
)
@click.option(
"--show",
type=click.Choice(["all", "err", "errskip"]),
default="all",
help="Show all (default), or just errors, or errors and skips",
)
def main(
packages: list[Path | GHPath],
format_opt: Formats,
Expand All @@ -299,8 +331,11 @@ def main(
show: Show,
) -> None:
"""
Pass in a local Path or gh:org/repo@branch.
Pass in a local Path or gh:org/repo@branch. Will run on the current
directory if no path passed.
"""
if not packages:
packages = [Path()]

if len(packages) > 1:
if format_opt == "json":
Expand Down

0 comments on commit 51ca05f

Please sign in to comment.