Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pydocstyle' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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)
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)
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)
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)
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
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
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:
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
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'),
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])