晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/testutils/_primer/ |
| Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/testutils/_primer/primer_run_command.py |
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
from __future__ import annotations
import json
import sys
import warnings
from io import StringIO
from git.repo import Repo
from pylint.lint import Run
from pylint.message import Message
from pylint.reporters import JSONReporter
from pylint.reporters.json_reporter import OldJsonExport
from pylint.testutils._primer.package_to_lint import PackageToLint
from pylint.testutils._primer.primer_command import (
PackageData,
PackageMessages,
PrimerCommand,
)
GITHUB_CRASH_TEMPLATE_LOCATION = "/home/runner/.cache"
CRASH_TEMPLATE_INTRO = "There is a pre-filled template"
class RunCommand(PrimerCommand):
def run(self) -> None:
packages: PackageMessages = {}
fatal_msgs: list[Message] = []
for package, data in self.packages.items():
messages, p_fatal_msgs = self._lint_package(package, data)
fatal_msgs += p_fatal_msgs
local_commit = Repo(data.clone_directory).head.object.hexsha
packages[package] = PackageData(commit=local_commit, messages=messages)
path = (
self.primer_directory
/ f"output_{'.'.join(str(i) for i in sys.version_info[:3])}_{self.config.type}.txt"
)
print(f"Writing result in {path}")
with open(path, "w", encoding="utf-8") as f:
json.dump(packages, f)
# Assert that a PR run does not introduce new fatal errors
if self.config.type == "pr":
plural = "s" if len(fatal_msgs) > 1 else ""
assert (
not fatal_msgs
), f"We encountered {len(fatal_msgs)} fatal error message{plural} (see log)."
@staticmethod
def _filter_fatal_errors(
messages: list[OldJsonExport],
) -> list[Message]:
"""Separate fatal errors so we can report them independently."""
fatal_msgs: list[Message] = []
for raw_message in messages:
message = JSONReporter.deserialize(raw_message)
if message.category == "fatal":
if GITHUB_CRASH_TEMPLATE_LOCATION in message.msg:
# Remove the crash template location if we're running on GitHub.
# We were falsely getting "new" errors when the timestamp changed.
message.msg = message.msg.rsplit(CRASH_TEMPLATE_INTRO)[0]
fatal_msgs.append(message)
return fatal_msgs
@staticmethod
def _print_msgs(msgs: list[Message]) -> str:
return "\n".join(f"- {JSONReporter.serialize(m)}" for m in msgs)
def _lint_package(
self, package_name: str, data: PackageToLint
) -> tuple[list[OldJsonExport], list[Message]]:
# We want to test all the code we can
enables = ["--enable-all-extensions", "--enable=all"]
# Duplicate code takes too long and is relatively safe
# TODO: Find a way to allow cyclic-import and compare output correctly
disables = ["--disable=duplicate-code,cyclic-import"]
arguments = data.pylint_args + enables + disables
output = StringIO()
reporter = JSONReporter(output)
print(f"Running 'pylint {', '.join(arguments)}'")
pylint_exit_code = -1
try:
Run(arguments, reporter=reporter)
except SystemExit as e:
pylint_exit_code = int(e.code) # type: ignore[arg-type]
readable_messages: str = output.getvalue()
messages: list[OldJsonExport] = json.loads(readable_messages)
fatal_msgs: list[Message] = []
if pylint_exit_code % 2 == 0:
print(f"Successfully primed {package_name}.")
else:
fatal_msgs = self._filter_fatal_errors(messages)
if fatal_msgs:
warnings.warn(
f"Encountered fatal errors while priming {package_name} !\n"
f"{self._print_msgs(fatal_msgs)}\n\n"
)
return messages, fatal_msgs
|