22import fnmatch
33import os
44import pathlib
5+ import stat
56
67from shutil import copy2 as copy
78from dataclasses import dataclass
@@ -29,6 +30,7 @@ def __init__(
2930 folders : list ,
3031 include : list ,
3132 ignore : list ,
33+ ignore_hidden : bool ,
3234 ignore_paths : list ,
3335 semiliterate : list ,
3436 ** kwargs ):
@@ -39,6 +41,7 @@ def __init__(
3941 folders (list): Glob of folders to search for files
4042 include (list): Glob of filenames to copy directly to output
4143 ignore (list): Glob of paths to exclude
44+ ignore_hidden (bool): Whether to ignore hidden files for processing
4245 ignore_paths (list): Absolute filepaths to exclude
4346 semiliterate (list): Settings for processing file content in
4447 Semiliterate
@@ -48,6 +51,8 @@ def __init__(
4851 self .folders = set (folders )
4952 self .doc_glob = set (include )
5053 self .ignore_glob = set (ignore )
54+ self .ignore_hidden = ignore_hidden # to be deprecated
55+ self .hidden_prefix = set (["." , "__" ]) # to be deprecated
5156 self .ignore_paths = set (ignore_paths )
5257 self .semiliterate = []
5358 for item in semiliterate :
@@ -118,14 +123,37 @@ def match_pattern(name, pattern):
118123
119124 def should_extract_file (self , name : str ):
120125 """Check if file should be extracted."""
126+ def has_hidden_attribute (filepath ):
127+ """Returns true if hidden attribute is set."""
128+ try :
129+ return bool (os .stat (filepath ).st_file_attributes &
130+ stat .FILE_ATTRIBUTE_HIDDEN )
131+ except (AttributeError , AssertionError ):
132+ return False
133+
134+ def has_hidden_prefix (filepath ):
135+ """Returns true if the file starts with a hidden prefix."""
136+ parts = filepath .split (os .path .sep )
137+
138+ def hidden_prefix (name ):
139+ if name == "." :
140+ return False
141+ return any (name .startswith (pattern )
142+ for pattern in self .hidden_prefix )
143+ return any (hidden_prefix (part ) for part in parts )
121144 # Check if file is text based
122145 try :
123146 with open (name , 'r' , encoding = 'utf-8' ) as f :
124147 _ = f .read ()
125- return True
126148 except UnicodeDecodeError :
127149 return False
128150
151+ # Check if file is hidden and should ignore
152+ if self .ignore_hidden :
153+ is_hidden = has_hidden_prefix (name ) or has_hidden_attribute (name )
154+ return not is_hidden
155+ return True
156+
129157 def merge_docs (self , from_dir , dirty = False ):
130158 """Merge docs directory"""
131159 if not os .path .exists (from_dir ):
0 commit comments