Skip to content

Commit

Permalink
Merge pull request #145 from skv0zsneg/markdown-printer
Browse files Browse the repository at this point in the history
Adding Markdown printer
  • Loading branch information
HunterMcGushion authored Dec 28, 2024
2 parents 5a5b167 + 6f94034 commit 9bd0ea8
Show file tree
Hide file tree
Showing 5 changed files with 749 additions and 115 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ docstr-coverage some_project/src

#### Options

- _--destination=\<type\>, -dst \<type\>_ - Set the results output destination (default stdout)
- stdout - Output to standard STDOUT.
- file - Save output to file.
- _--format=\<type\>, -frm \<type\>_ - Set output style (default text)
- text - Output in simple style.
- markdown - Output in Markdown notation.
- _--skip-magic, -m_ - Ignore all magic methods (except `__init__`)
- _--skip-init, -i_ - Ignore all `__init__` methods
- _--skip-file-doc, -f_ - Ignore module docstrings (at the top of files)
Expand Down
36 changes: 34 additions & 2 deletions docstr_coverage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from docstr_coverage.config_file import set_config_defaults
from docstr_coverage.coverage import analyze
from docstr_coverage.ignore_config import IgnoreConfig
from docstr_coverage.printers import LegacyPrinter
from docstr_coverage.printers import LegacyPrinter, MarkdownPrinter


def do_include_filepath(filepath: str, exclude_re: Optional["re.Pattern"]) -> bool:
Expand Down Expand Up @@ -261,6 +261,24 @@ def _assert_valid_key_value(k, v):
default=".docstr_coverage",
help="Deprecated. Use json config (--config / -C) instead",
)
@click.option(
"-dst",
"--destination",
type=click.Choice(["stdout", "file"]),
default="stdout",
help="Results output destination",
show_default=True,
metavar="DESTINATION",
)
@click.option(
"-frm",
"--format",
type=click.Choice(["text", "markdown"]),
default="text",
help="Format of output",
show_default=True,
metavar="FORMAT",
)
def execute(paths, **kwargs):
"""Measure docstring coverage for `PATHS`"""

Expand Down Expand Up @@ -328,7 +346,21 @@ def execute(paths, **kwargs):
show_progress = not kwargs["percentage_only"]
results = analyze(all_paths, ignore_config=ignore_config, show_progress=show_progress)

LegacyPrinter(verbosity=kwargs["verbose"], ignore_config=ignore_config).print(results)
report_format: str = kwargs["format"]
if report_format == "markdown":
printer = MarkdownPrinter(results, verbosity=kwargs["verbose"], ignore_config=ignore_config)
elif report_format == "text":
printer = LegacyPrinter(results, verbosity=kwargs["verbose"], ignore_config=ignore_config)
else:
raise SystemError("Unknown report format: {0}".format(report_format))

destination: str = kwargs["destination"]
if destination == "file":
printer.save_to_file()
elif destination == "stdout":
printer.print_to_stdout()
else:
raise SystemError("Unknown output type: {0}".format(destination))

file_results, total_results = results.to_legacy()

Expand Down
2 changes: 1 addition & 1 deletion docstr_coverage/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def get_docstring_coverage(
ignore_names=ignore_names,
)
results = analyze(filenames, ignore_config)
LegacyPrinter(verbosity=verbose, ignore_config=ignore_config).print(results)
LegacyPrinter(results, verbosity=verbose, ignore_config=ignore_config).print_to_stdout()
return results.to_legacy()


Expand Down
Loading

0 comments on commit 9bd0ea8

Please sign in to comment.