refactor: optimize important file checking and add variations

This commit is contained in:
Paul Gauthier (aider) 2024-08-30 14:43:42 -07:00
parent 92c378d459
commit 3ff67d564c

View file

@ -5,11 +5,24 @@ IMPORTANT_FILES = [
".gitignore", ".gitignore",
".gitattributes", ".gitattributes",
# Documentation # Documentation
"README",
"README.md", "README.md",
"README.txt",
"README.rst",
"CONTRIBUTING",
"CONTRIBUTING.md", "CONTRIBUTING.md",
"CONTRIBUTING.txt",
"CONTRIBUTING.rst",
"LICENSE", "LICENSE",
"LICENSE.md",
"LICENSE.txt",
"CHANGELOG",
"CHANGELOG.md", "CHANGELOG.md",
"CHANGELOG.txt",
"CHANGELOG.rst",
"SECURITY",
"SECURITY.md", "SECURITY.md",
"SECURITY.txt",
"CODEOWNERS", "CODEOWNERS",
# Package Management and Dependencies # Package Management and Dependencies
"requirements.txt", "requirements.txt",
@ -185,7 +198,8 @@ IMPORTANT_FILES = [
] ]
IMPORTANT_FILES = [os.path.normpath(path) for path in IMPORTANT_FILES] # Normalize IMPORTANT_FILES once
NORMALIZED_IMPORTANT_FILES = [os.path.normpath(path) for path in IMPORTANT_FILES]
def is_important(file_path): def is_important(file_path):
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
@ -213,13 +227,9 @@ def is_important(file_path):
return True return True
''' '''
# Check if the file_path matches any of the IMPORTANT_FILES # Check if the file_path matches any of the NORMALIZED_IMPORTANT_FILES
normalized_path = os.path.normpath(file_path) normalized_path = os.path.normpath(file_path)
for important_file in IMPORTANT_FILES: return any(normalized_path.endswith(important_file) for important_file in NORMALIZED_IMPORTANT_FILES)
if normalized_path.endswith(important_file):
return True
return False
def filter_important_files(file_paths): def filter_important_files(file_paths):