Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrogate #8

Merged
merged 4 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/duty/callables/blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def run(
if exclude:
exclude = tuple(re.compile(regex, re.I) if isinstance(regex, str) else regex for regex in exclude)
filepaths = set()
for path in paths:
path = Path(path)
for path_ in paths:
path = Path(path_)
jexio marked this conversation as resolved.
Show resolved Hide resolved
if path.is_file():
filepaths.add(path.as_posix())
else:
Expand Down
158 changes: 158 additions & 0 deletions src/duty/callables/interrogate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
"""Callable for [Interrogate](https://github.com/econchick/interrogate)."""

from __future__ import annotations

import sys

from duty.callables import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal

_BADGE_STYLE = Literal["flat", "flat-square", "flat-square-modified", "for-the-badge", "plastic", "social"]


@lazy("interrogate")
def run(
*src: str,
verbose: int | None = None,
quiet: bool | None = None,
fail_under: float | None = None,
exclude: str | None = None,
ignore_init_method: bool | None = None,
ignore_init_module: bool | None = None,
ignore_magic: bool | None = None,
ignore_module: bool | None = None,
ignore_nested_functions: bool | None = None,
ignore_nested_classes: bool | None = None,
ignore_private: bool | None = None,
ignore_property_decorators: bool | None = None,
ignore_setters: bool | None = None,
ignore_semiprivate: bool | None = None,
ignore_regex: str | None = None,
whitelist_regex: str | None = None,
output: str | None = None,
config: str | None = None,
color: bool | None = None,
omit_covered_files: bool | None = None,
generate_badge: str | None = None,
badge_format: Literal["png", "svg"] | None = None,
badge_style: _BADGE_STYLE | None = None,
) -> None:
"""Run `interrogate`.

Args:
src: Format the directories and file paths.
verbose: Level of verbosity.
quiet: Do not print output.
fail_under: Fail when coverage % is less than a given amount.
exclude: Exclude PATHs of files and/or directories.
ignore_init_method: Ignore __init__ method of classes.
ignore_init_module: Ignore __init__.py modules.
jexio marked this conversation as resolved.
Show resolved Hide resolved
ignore_magic: Ignore all magic methods of classes.
ignore_module: Ignore module-level docstrings.
ignore_nested_functions: Ignore nested functions and methods.
ignore_nested_classes: Ignore nested classes.
ignore_private: Ignore private classes, methods, and functions starting with two underscores.
ignore_property_decorators: Ignore methods with property setter/getter decorators.
ignore_setters: Ignore methods with property setter decorators.
ignore_semiprivate: Ignore semiprivate classes, methods, and functions starting with a single underscore.
ignore_regex: Regex identifying class, method, and function names to ignore.
whitelist_regex: Regex identifying class, method, and function names to include.
output: Write output to a given FILE.
config: Read configuration from pyproject.toml or setup.cfg.
color: Toggle color output on/off when printing to stdout.
omit_covered_files: Omit reporting files that have 100% documentation coverage.
generate_badge: Generate a shields.io status badge (an SVG image) in at a given file or directory.
badge_format: File format for the generated badge.
badge_style: Desired style of shields.io badge.
"""
from interrogate.cli import main as interrogate

cli_args: list[str] = list(src)

if verbose:
cli_args.append("--verbose")
cli_args.append(str(verbose))

if quiet:
cli_args.append("--quiet")

if fail_under:
cli_args.append("--fail-under")
cli_args.append(str(fail_under))

if exclude:
cli_args.append("--exclude")
cli_args.append(exclude)

if ignore_init_method:
cli_args.append("--ignore-init-method")

if ignore_init_module:
cli_args.append("--ignore-init-module")

if ignore_magic:
cli_args.append("--ignore-magic")

if ignore_module:
cli_args.append("--ignore-module")

if ignore_nested_functions:
cli_args.append("--ignore-nested-functions")

if ignore_nested_classes:
cli_args.append("--ignore-nested-classes")

if ignore_private:
cli_args.append("--ignore-private")

if ignore_property_decorators:
cli_args.append("--ignore-property-decorators")

if ignore_setters:
cli_args.append("--ignore-setters")

if ignore_semiprivate:
cli_args.append("--ignore-semiprivate")

if ignore_regex:
cli_args.append("--ignore-regex")
cli_args.append(ignore_regex)

if whitelist_regex:
cli_args.append("--whitelist-regex")
cli_args.append(whitelist_regex)

if output:
cli_args.append("--output")
cli_args.append(output)

if omit_covered_files:
cli_args.append("--omit-covered-files")

if generate_badge:
cli_args.append("--generate-badge")
cli_args.append(generate_badge)

if badge_format:
cli_args.append("--badge-format")
cli_args.append(badge_format)

if badge_style:
cli_args.append("--badge-style")
cli_args.append(badge_style)

if config:
cli_args.append("--config")
cli_args.append(config)

if color is True:
cli_args.append("--color")
elif color is False:
cli_args.append("--no-color")

interrogate(cli_args)