]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/flake8/discover_files.py
580d5fdf407bcc47326007f3d280cfe2dad696b1
1 """Functions related to discovering paths."""
2 from __future__
import annotations
6 from typing
import Callable
7 from typing
import Generator
8 from typing
import Sequence
10 from flake8
import utils
12 LOG
= logging
.getLogger(__name__
)
18 predicate
: Callable
[[str], bool],
19 ) -> Generator
[str, None, None]:
20 """Generate filenames from an argument.
23 Parameter from the command-line.
25 Predicate to use to filter out filenames. If the predicate
26 returns ``True`` we will exclude the filename, otherwise we
27 will yield it. By default, we include every filename
35 if os
.path
.isdir(arg
):
36 for root
, sub_directories
, files
in os
.walk(arg
):
37 # NOTE(sigmavirus24): os.walk() will skip a directory if you
38 # remove it from the list of sub-directories.
39 for directory
in tuple(sub_directories
):
40 joined
= os
.path
.join(root
, directory
)
42 sub_directories
.remove(directory
)
44 for filename
in files
:
45 joined
= os
.path
.join(root
, filename
)
46 if not predicate(joined
):
55 stdin_display_name
: str,
56 filename_patterns
: Sequence
[str],
57 exclude
: Sequence
[str],
58 ) -> Generator
[str, None, None]:
59 """Expand out ``paths`` from commandline to the lintable files."""
63 def is_excluded(arg
: str) -> bool:
65 # if the stdin_display_name is the default, always include it
66 if stdin_display_name
== "stdin":
68 arg
= stdin_display_name
70 return utils
.matches_filename(
73 log_message
='"%(path)s" has %(whether)sbeen excluded',
80 for filename
in _filenames_from(path
, predicate
=is_excluded
)
84 # always lint explicitly passed (even if not matching filter)
86 # otherwise, check the file against filtered patterns
87 or utils
.fnmatch(filename
, filename_patterns
)