How to use pydocstyle - 10 common examples

To help you get started, we’ve selected a few pydocstyle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github henry0312 / pytest-docstyle / src / pytest_pydocstyle.py View on Github external
def runtest(self):
        pydocstyle.utils.log.setLevel(logging.WARN)  # TODO: follow that of pytest

        # https://github.com/PyCQA/pydocstyle/blob/4.0.1/src/pydocstyle/cli.py#L42-L45
        for filename, checked_codes, ignore_decorators in self.parser.get_files_to_check():
            errors = [str(error) for error in pydocstyle.check((str(self.fspath),), select=checked_codes,
                                                               ignore_decorators=ignore_decorators)]
        if errors:
            raise PyDocStyleError('\n'.join(errors))
        elif hasattr(self.config, 'cache'):
            # update cache
            # http://pythonhosted.org/pytest-cache/api.html
            cache = self.config.cache.get(self.CACHE_KEY, {})
            cache[str(self.fspath)] = self.fspath.mtime()
            self.config.cache.set(self.CACHE_KEY, cache)
github CheckPointSW / Karta / tests.py View on Github external
import pydocstyle
import os
from glob import glob

SRC_DIR = "src"

def fileList():
    return filter(lambda z: not z.endswith("__init__.py"), [y for x in os.walk(SRC_DIR) for y in glob(os.path.join(x[0], '*.py'))])


file_list = fileList()

passed = True

# Documentation tests
for check in pydocstyle.check(file_list, ignore=["D100", "D104", "D413", "D213", "D203", "D402"]):
    print(check)
    passed = False

# last status
exit(0 if passed else 1)
github henry0312 / pytest-docstyle / src / pytest_pydocstyle.py View on Github external
def runtest(self):
        pydocstyle.utils.log.setLevel(logging.WARN)  # TODO: follow that of pytest

        # https://github.com/PyCQA/pydocstyle/blob/4.0.1/src/pydocstyle/cli.py#L42-L45
        for filename, checked_codes, ignore_decorators in self.parser.get_files_to_check():
            errors = [str(error) for error in pydocstyle.check((str(self.fspath),), select=checked_codes,
                                                               ignore_decorators=ignore_decorators)]
        if errors:
            raise PyDocStyleError('\n'.join(errors))
        elif hasattr(self.config, 'cache'):
            # update cache
            # http://pythonhosted.org/pytest-cache/api.html
            cache = self.config.cache.get(self.CACHE_KEY, {})
            cache[str(self.fspath)] = self.fspath.mtime()
            self.config.cache.set(self.CACHE_KEY, cache)
github henry0312 / pytest-docstyle / src / pytest_pydocstyle.py View on Github external
def pytest_collect_file(parent, path):
    config = parent.config
    if config.getoption('pydocstyle') and path.ext == '.py':
        parser = pydocstyle.config.ConfigurationParser()
        args = [str(path.basename)]
        with _patch_sys_argv(args):
            parser.parse()
        for filename, _, _ in parser.get_files_to_check():
            # https://github.com/pytest-dev/pytest/blob/ee1950af7793624793ee297e5f48b49c8bdf2065/src/_pytest/nodes.py#L477
            return File.from_parent(parent=parent, fspath=path, config_parser=parser)
github dickreuter / neuron_poker / tests / test_pylint.py View on Github external
def run_pydocstyle():
    """Adjust version of pydocstile to return detailed errors to the test."""
    log.setLevel(logging.DEBUG)
    conf = ConfigurationParser()
    setup_stream_handlers(conf.get_default_run_configuration())

    try:
        conf.parse()
    except IllegalConfiguration:
        return ReturnCode.invalid_options

    run_conf = conf.get_user_run_configuration()

    # Reset the logger according to the command line arguments
    setup_stream_handlers(run_conf)

    log.debug("starting in debug mode.")

    Error.explain = run_conf.explain
    Error.source = run_conf.source
github dickreuter / neuron_poker / tests / test_pylint.py View on Github external
log.debug("starting in debug mode.")

    Error.explain = run_conf.explain
    Error.source = run_conf.source

    errors = []
    changed_files = get_relevant_files()

    if not changed_files:
        return []

    all_files = conf.get_files_to_check()
    all_files = [file for file in all_files if file[0] in changed_files]
    try:
        for filename, checked_codes, ignore_decorators in all_files:
            errors.extend(check((filename,), select=checked_codes, ignore_decorators=ignore_decorators))
    except IllegalConfiguration as error:
        # An illegal configuration file was found during file generation.
        log.error(error.args[0])
        return ReturnCode.invalid_options

    count = 0
    errors_final = []
    for err in errors:
        if hasattr(err, 'code') and not any(ignore in str(err) for ignore in IGNORES):
            sys.stdout.write('%s\n' % err)
            errors_final.append(err)
        count += 1
    return errors_final
github dickreuter / neuron_poker / tests / test_pylint.py View on Github external
def run_pydocstyle():
    """Adjust version of pydocstile to return detailed errors to the test."""
    log.setLevel(logging.DEBUG)
    conf = ConfigurationParser()
    setup_stream_handlers(conf.get_default_run_configuration())

    try:
        conf.parse()
    except IllegalConfiguration:
        return ReturnCode.invalid_options

    run_conf = conf.get_user_run_configuration()

    # Reset the logger according to the command line arguments
    setup_stream_handlers(run_conf)

    log.debug("starting in debug mode.")

    Error.explain = run_conf.explain
    Error.source = run_conf.source

    errors = []
    changed_files = get_relevant_files()

    if not changed_files:
        return []

    all_files = conf.get_files_to_check()
    all_files = [file for file in all_files if file[0] in changed_files]
    try:
        for filename, checked_codes, ignore_decorators in all_files:
github dickreuter / neuron_poker / tests / test_pylint.py View on Github external
def run_pydocstyle():
    """Adjust version of pydocstile to return detailed errors to the test."""
    log.setLevel(logging.DEBUG)
    conf = ConfigurationParser()
    setup_stream_handlers(conf.get_default_run_configuration())

    try:
        conf.parse()
    except IllegalConfiguration:
        return ReturnCode.invalid_options

    run_conf = conf.get_user_run_configuration()

    # Reset the logger according to the command line arguments
    setup_stream_handlers(run_conf)

    log.debug("starting in debug mode.")

    Error.explain = run_conf.explain
    Error.source = run_conf.source
github colcon / colcon-core / test / test_flake8.py View on Github external
def test_flake8():
    # for some reason the pydocstyle logger changes to an effective level of 1
    # set higher level to prevent the output to be flooded with debug messages
    log.setLevel(logging.WARNING)

    style_guide = get_style_guide(
        extend_ignore=['D100', 'D104'],
        show_source=True,
    )
    style_guide_tests = get_style_guide(
        extend_ignore=['D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
        show_source=True,
    )

    stdout = sys.stdout
    sys.stdout = sys.stderr
    # implicitly calls report_errors()
    report = style_guide.check_files([
        str(Path(__file__).parents[1] / 'bin' / 'colcon'),
        str(Path(__file__).parents[1] / 'colcon_core'),
github dickreuter / neuron_poker / tests / test_pylint.py View on Github external
conf = ConfigurationParser()
    setup_stream_handlers(conf.get_default_run_configuration())

    try:
        conf.parse()
    except IllegalConfiguration:
        return ReturnCode.invalid_options

    run_conf = conf.get_user_run_configuration()

    # Reset the logger according to the command line arguments
    setup_stream_handlers(run_conf)

    log.debug("starting in debug mode.")

    Error.explain = run_conf.explain
    Error.source = run_conf.source

    errors = []
    changed_files = get_relevant_files()

    if not changed_files:
        return []

    all_files = conf.get_files_to_check()
    all_files = [file for file in all_files if file[0] in changed_files]
    try:
        for filename, checked_codes, ignore_decorators in all_files:
            errors.extend(check((filename,), select=checked_codes, ignore_decorators=ignore_decorators))
    except IllegalConfiguration as error:
        # An illegal configuration file was found during file generation.
        log.error(error.args[0])