Skip to content

Commit fd8e5ac

Browse files
authored
Add excluded files (#8)
* LLM independent * add excluded files
1 parent 32e92cb commit fd8e5ac

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

code_buddy/main.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,34 @@ def get_all_files(repo):
4444

4545
def is_image_file(filename):
4646
"""Check if a file is an image based on its extension."""
47-
image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp', '.svg', '.ico', '.yaml'}
47+
image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp', '.svg', '.ico', '.yaml', '.woff'}
4848
return Path(filename).suffix.lower() in image_extensions
4949

50+
# is_file_name: takes a path to a file and returns False if file is excluded, file can be a relative path
51+
def is_excluded_file_name(file):
52+
# List of file names or directories to exclude
53+
excluded_files = [
54+
'node_modules', 'package-lock.json', 'yarn.lock', '.DS_Store', '.gitignore', '.gitattributes', '.gitmodules',
55+
'.git', '.idea', '.vscode', '.env', '.env.local', '.env.development', '.env.test', '.env.production',
56+
'.env.staging', '.env.local', '.env.*.local', 'npm-debug.log', 'yarn-debug.log', 'yarn-error.log', 'yarn-integrity'
57+
]
58+
59+
# Check if the file is in the list of excluded files or in an excluded directory
60+
file_name = os.path.basename(file) # Get the base name of the file
61+
for excluded in excluded_files:
62+
# Match either the exact file name or a wildcard match (for .env.*)
63+
if excluded.startswith('.env.*') and file_name.startswith('.env.') or file_name == excluded:
64+
return True
65+
66+
# If it's not excluded, return False
67+
return False
68+
69+
5070
def build_structure(root_path, files):
5171
"""Build a nested dictionary structure representing the project files."""
5272
structure = {}
5373
for file_path in files:
54-
if is_image_file(file_path):
74+
if is_image_file(file_path) or is_excluded_file_name(file_path):
5575
continue # Skip image files
5676
full_path = Path(root_path) / file_path
5777
# Ensure the file exists

0 commit comments

Comments
 (0)