Exclude dirs/files prefixed with . (#3986)
This commit is contained in:
parent
2bc84af87e
commit
13ab2be5f6
2 changed files with 61 additions and 22 deletions
|
@ -61,11 +61,17 @@ def _include_yaml(loader: SafeLineLoader,
|
|||
return load_yaml(fname)
|
||||
|
||||
|
||||
def _find_files(directory, pattern):
|
||||
def _is_file_valid(name: str) -> bool:
|
||||
"""Decide if a file is valid."""
|
||||
return not name.startswith('.')
|
||||
|
||||
|
||||
def _find_files(directory: str, pattern: str):
|
||||
"""Recursively load files in a directory."""
|
||||
for root, _dirs, files in os.walk(directory):
|
||||
for root, dirs, files in os.walk(directory, topdown=True):
|
||||
dirs[:] = [d for d in dirs if _is_file_valid(d)]
|
||||
for basename in files:
|
||||
if fnmatch.fnmatch(basename, pattern):
|
||||
if _is_file_valid(basename) and fnmatch.fnmatch(basename, pattern):
|
||||
filename = os.path.join(root, basename)
|
||||
yield filename
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue