Skip to content

Commit

Permalink
feat: railsignore - finalizing review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanitshimanga authored and Pouyanpi committed Oct 18, 2024
1 parent 11b7292 commit 23a57a7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions nemoguardrails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def snake_to_camelcase(name: str) -> str:


def get_railsignore_path(path: Optional[str] = None) -> Optional[Path]:
"""Helper to get railsignore path.
"""Get railsignore path.
Args:
path (Optional[str]): The starting path to search for the .railsignore file.
Expand All @@ -341,9 +341,9 @@ def get_railsignore_path(path: Optional[str] = None) -> Optional[Path]:
return None


def get_railsignore_patterns(railsignore_path) -> Set[str]:
"""
Helper to retrieve all specified patterns in railsignore.
def get_railsignore_patterns(railsignore_path: Path) -> Set[str]:
"""Retrieve all specified patterns in railsignore.
Returns:
Set[str]: The set of filenames or glob patterns in railsignore
"""
Expand All @@ -352,8 +352,6 @@ def get_railsignore_patterns(railsignore_path) -> Set[str]:
if railsignore_path is None:
return ignored_patterns

# railsignore_path = get_railsignore_path()

# File doesn't exist or is empty
if not railsignore_path.exists() or not os.path.getsize(railsignore_path):
return ignored_patterns
Expand All @@ -377,13 +375,14 @@ def get_railsignore_patterns(railsignore_path) -> Set[str]:
return ignored_patterns


def is_ignored_by_railsignore(filename, ignore_patterns) -> bool:
ignore = False
def is_ignored_by_railsignore(filename: str, ignore_patterns: str) -> bool:
"""Verify if a filename should be ignored by a railsignore pattern"""

# Load candidate patterns from railsignore
ignore = False

for pattern in ignore_patterns:
if fnmatch.fnmatch(filename, pattern):
ignore = True
break

return ignore

0 comments on commit 23a57a7

Please sign in to comment.