Skip to content

Commit

Permalink
add option to exclude hidden dirs and files
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelgatelement committed Jul 19, 2023
1 parent a86a96a commit 9b951c1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/reuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
re.compile(r"^\.reuse$"),
]

_IGNORE_HIDDEN_PATTERN = re.compile(r"^\..+$")

_IGNORE_MESON_PARENT_DIR_PATTERNS = [
re.compile(r"^subprojects$"),
]
Expand Down
12 changes: 12 additions & 0 deletions src/reuse/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ def parser() -> argparse.ArgumentParser:
action="store_true",
help=_("do not skip over Meson subprojects"),
)
parser.add_argument(
"--exclude-hidden-dirs",
action="store_true",
help=_("skip hidden directories"),
)
parser.add_argument(
"--exclude-hidden-files",
action="store_true",
help=_("skip hidden files"),
)
parser.add_argument(
"--no-multiprocessing",
action="store_true",
Expand Down Expand Up @@ -291,6 +301,8 @@ def main(args: Optional[List[str]] = None, out: IO[str] = sys.stdout) -> int:
project = create_project()
project.include_submodules = parsed_args.include_submodules
project.include_meson_subprojects = parsed_args.include_meson_subprojects
project.exclude_hidden_dirs = parsed_args.exclude_hidden_dirs
project.exclude_hidden_files = parsed_args.exclude_hidden_files

return parsed_args.func(parsed_args, project, out)

Expand Down
3 changes: 3 additions & 0 deletions src/reuse/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def add_arguments(parser: ArgumentParser) -> None:
mutex_group.add_argument(
"-j", "--json", action="store_true", help=_("formats output as JSON")
)
mutex_group.add_argument(
"--ignore-hidden-files", action="store_true", help=_("ignore hidden files")
)
mutex_group.add_argument(
"-p",
"--plain",
Expand Down
9 changes: 9 additions & 0 deletions src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . import (
_IGNORE_DIR_PATTERNS,
_IGNORE_FILE_PATTERNS,
_IGNORE_HIDDEN_PATTERN,
_IGNORE_MESON_PARENT_DIR_PATTERNS,
IdentifierNotFound,
ReuseInfo,
Expand Down Expand Up @@ -62,6 +63,8 @@ def __init__(
root: StrPath,
include_submodules: bool = False,
include_meson_subprojects: bool = False,
exclude_hidden_files: bool = False,
exclude_hidden_dirs: bool = False,
):
self._root = Path(root)
if not self._root.is_dir():
Expand Down Expand Up @@ -265,10 +268,16 @@ def _is_path_ignored(self, path: Path) -> bool:
for pattern in _IGNORE_FILE_PATTERNS:
if pattern.match(name):
return True
if self.exclude_hidden_files:
if _IGNORE_HIDDEN_PATTERN.match(name):
return True
elif path.is_dir():
for pattern in _IGNORE_DIR_PATTERNS:
if pattern.match(name):
return True
if self.exclude_hidden_dirs:
if _IGNORE_HIDDEN_PATTERN.match(name):
return True
if not self.include_meson_subprojects:
for pattern in _IGNORE_MESON_PARENT_DIR_PATTERNS:
if pattern.match(parent_dir):
Expand Down

0 comments on commit 9b951c1

Please sign in to comment.