晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/cloudlinux/venv/lib64/python3.11/site-packages/prospector/ |
| Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/prospector/suppression.py |
r"""
Each tool has its own method of ignoring errors and warnings.
For example, pylint requires a comment of the form
# pylint disable=<error codes>
PEP8 will not warn on lines with
# noqa
Additionally, flake8 follows that convention for pyflakes errors,
but pyflakes itself does not.
Finally, an entire file is ignored by flake8 if this line is found
in the file:
# flake8\: noqa (the \ is needed to stop prospector ignoring this file :))
This module's job is to attempt to collect all of these methods into
a single coherent list of error suppression locations.
"""
import re
import warnings
from collections import defaultdict
from pathlib import Path
from typing import List
from prospector import encoding
from prospector.exceptions import FatalProspectorException
from prospector.message import Message
_FLAKE8_IGNORE_FILE = re.compile(r"flake8[:=]\s*noqa", re.IGNORECASE)
_PEP8_IGNORE_LINE = re.compile(r"#\s+noqa", re.IGNORECASE)
_PYLINT_SUPPRESSED_MESSAGE = re.compile(r"^Suppressed \'([a-z0-9-]+)\' \(from line \d+\)$")
def get_noqa_suppressions(file_contents):
"""
Finds all pep8/flake8 suppression messages
:param file_contents:
A list of file lines
:return:
A pair - the first is whether to ignore the whole file, the
second is a set of (0-indexed) line numbers to ignore.
"""
ignore_whole_file = False
ignore_lines = set()
for line_number, line in enumerate(file_contents):
if _FLAKE8_IGNORE_FILE.search(line):
ignore_whole_file = True
if _PEP8_IGNORE_LINE.search(line):
ignore_lines.add(line_number + 1)
return ignore_whole_file, ignore_lines
_PYLINT_EQUIVALENTS = {
# TODO: blending has this info already?
"unused-import": (
("pyflakes", "FL0001"),
("frosted", "E101"),
)
}
def _parse_pylint_informational(messages: List[Message]):
ignore_files = set()
ignore_messages: dict = defaultdict(lambda: defaultdict(list))
for message in messages:
if message.source == "pylint":
if message.code == "suppressed-message":
# this is a message indicating that a message was raised
# by pylint but suppressed by configuration in the file
match = _PYLINT_SUPPRESSED_MESSAGE.match(message.message)
if not match:
raise FatalProspectorException(f"Could not parsed suppressed message from {message.message}")
suppressed_code = match.group(1)
line_dict = ignore_messages[message.location.path]
line_dict[message.location.line].append(suppressed_code)
elif message.code == "file-ignored":
ignore_files.add(message.location.path)
return ignore_files, ignore_messages
def get_suppressions(filepaths: List[Path], messages):
"""
Given every message which was emitted by the tools, and the
list of files to inspect, create a list of files to ignore,
and a map of filepath -> line-number -> codes to ignore
"""
paths_to_ignore = set()
lines_to_ignore: dict = defaultdict(set)
messages_to_ignore: dict = defaultdict(lambda: defaultdict(set))
# first deal with 'noqa' style messages
for filepath in filepaths:
try:
file_contents = encoding.read_py_file(filepath).split("\n")
except encoding.CouldNotHandleEncoding as err:
# TODO: this output will break output formats such as JSON
warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning)
continue
ignore_file, ignore_lines = get_noqa_suppressions(file_contents)
if ignore_file:
paths_to_ignore.add(filepath)
lines_to_ignore[filepath] |= ignore_lines
# now figure out which messages were suppressed by pylint
pylint_ignore_files, pylint_ignore_messages = _parse_pylint_informational(messages)
paths_to_ignore |= pylint_ignore_files
for filepath, line in pylint_ignore_messages.items():
for line_number, codes in line.items():
for code in codes:
messages_to_ignore[filepath][line_number].add(("pylint", code))
if code in _PYLINT_EQUIVALENTS:
for equivalent in _PYLINT_EQUIVALENTS[code]:
messages_to_ignore[filepath][line_number].add(equivalent)
return paths_to_ignore, lines_to_ignore, messages_to_ignore
|