晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/cloudlinux/venv/lib64/python3.11/site-packages/prospector/ |
| Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/prospector/finder.py |
from pathlib import Path
from typing import Callable, Iterable, Iterator, List
from prospector.exceptions import PermissionMissing
from prospector.pathutils import is_python_module, is_python_package, is_virtualenv
_SKIP_DIRECTORIES = (".git", ".tox", ".mypy_cache", ".pytest_cache", ".venv", "__pycache__", "node_modules")
class FileFinder:
"""
This class is responsible for taking a combination of command-line arguments
and configuration loaded from a profile to discover all files and modules which
should be inspected.
Individual tools can be told to ignore certain files, so the job of this class
is basically to know which files to pass to which tools to be inspected.
"""
def __init__(self, *provided_paths: Path, exclusion_filters: Iterable[Callable] = None):
"""
:param provided_paths:
A list of Path objects to search for files and modules - can be either directories or files
:param exclusion_filters:
An optional list of filters. All paths will be checked against this list - if any return True,
the path is excluded.
"""
self._provided_files = []
self._provided_dirs = []
self._exclusion_filters = [
# we always want to ignore some things
lambda _path: _path.is_dir() and _path.name in _SKIP_DIRECTORIES,
is_virtualenv,
] + list(exclusion_filters or [])
for path in provided_paths:
if not path.exists():
raise FileNotFoundError(path)
# ensure all paths from now one are absolute paths; they can be converted
# to relative paths for output purposes later
path = path.absolute()
if path.is_file():
self._provided_files.append(path)
if path.is_dir():
self._provided_dirs.append(path)
def make_syspath(self) -> List[Path]:
paths = set()
for path in self._provided_dirs:
paths.add(path)
for module in self.python_modules:
paths.add(module.parent)
return sorted(paths)
def is_excluded(self, path: Path) -> bool:
return any(filt(path) for filt in self._exclusion_filters)
def _filter(self, paths: Iterable[Path]) -> List[Path]:
return [path for path in paths if not self.is_excluded(path)]
def _walk(self, directory: Path) -> Iterator[Path]:
if not self.is_excluded(directory):
yield directory
for path in directory.iterdir():
if self.is_excluded(path):
continue
if path.is_dir():
yield from self._walk(path)
else:
yield path
@property
def files(self) -> List[Path]:
"""
List every individual file found from the given configuration.
This method is useful for tools which require an explicit list of files to check.
"""
files = set()
for path in self._provided_files:
files.add(path)
for directory in self.directories:
for path in self._walk(directory):
if path.is_file():
files.add(path)
return self._filter(files)
@property
def python_packages(self) -> List[Path]:
"""
Lists every directory found in the given configuration which is a python module (that is,
contains an `__init__.py` file).
This method is useful for passing to tools which will do their own discovery of python files.
"""
return self._filter(d for d in self.directories if is_python_package(d))
@property
def python_modules(self) -> List[Path]:
"""
Lists every directory found in the given configuration which is a python module (that is,
contains an `__init__.py` file).
This method is useful for passing to tools which will do their own discovery of python files.
"""
return self._filter(f for f in self.files if is_python_module(f))
@property
def directories(self) -> List[Path]:
"""
Lists every directory found from the given configuration, regardless of its contents.
This method is useful for passing to tools which will do their own discovery of python files.
"""
dirs = set()
for directory in self._provided_dirs:
dirs.add(directory)
try:
for obj in self._walk(directory):
if obj.is_dir():
dirs.add(obj)
except PermissionError as err:
raise PermissionMissing(obj) from err
return self._filter(dirs)
|