|
14 | 14 | # limitations under the License. |
15 | 15 |
|
16 | 16 | """Module for the configuration of rails.""" |
17 | | -import fnmatch |
| 17 | + |
18 | 18 | import logging |
19 | 19 | import os |
20 | 20 | import warnings |
|
24 | 24 | from pydantic import BaseModel, ValidationError, root_validator |
25 | 25 | from pydantic.fields import Field |
26 | 26 |
|
| 27 | +from nemoguardrails import utils |
27 | 28 | from nemoguardrails.colang import parse_colang_file, parse_flow_elements |
28 | 29 | from nemoguardrails.colang.v2_x.lang.colang_ast import Flow |
29 | 30 | from nemoguardrails.colang.v2_x.lang.utils import format_colang_parsing_error_message |
30 | 31 | from nemoguardrails.colang.v2_x.runtime.errors import ColangParsingError |
31 | | -from nemoguardrails.utils import get_railsignore_patterns |
32 | 32 |
|
33 | 33 | log = logging.getLogger(__name__) |
34 | 34 |
|
@@ -552,13 +552,19 @@ def _load_path( |
552 | 552 | if not os.path.exists(config_path): |
553 | 553 | raise ValueError(f"Could not find config path: {config_path}") |
554 | 554 |
|
| 555 | + # the first .railsignore file found from cwd down to its subdirectories |
| 556 | + railsignore_path = utils.get_railsignore_path(config_path) |
| 557 | + ignore_patterns = utils.get_railsignore_patterns(railsignore_path) |
| 558 | + |
555 | 559 | if os.path.isdir(config_path): |
556 | 560 | for root, _, files in os.walk(config_path, followlinks=True): |
557 | 561 | # Followlinks to traverse symlinks instead of ignoring them. |
558 | 562 |
|
559 | 563 | for file in files: |
560 | 564 | # Verify railsignore to skip loading |
561 | | - ignored_by_railsignore = _is_file_ignored_by_railsignore(file) |
| 565 | + ignored_by_railsignore = utils.is_ignored_by_railsignore( |
| 566 | + file, ignore_patterns |
| 567 | + ) |
562 | 568 |
|
563 | 569 | if ignored_by_railsignore: |
564 | 570 | continue |
@@ -1210,16 +1216,3 @@ def _generate_rails_flows(flows): |
1210 | 1216 | flow_definitions.insert(1, _LIBRARY_IMPORT + _NEWLINE * 2) |
1211 | 1217 |
|
1212 | 1218 | return flow_definitions |
1213 | | - |
1214 | | - |
1215 | | -def _is_file_ignored_by_railsignore(filename: str) -> bool: |
1216 | | - ignore = False |
1217 | | - |
1218 | | - # Load candidate patterns from railsignore |
1219 | | - candidate_patterns = get_railsignore_patterns() |
1220 | | - |
1221 | | - for pattern in candidate_patterns: |
1222 | | - if fnmatch.fnmatch(filename, pattern): |
1223 | | - ignore = True |
1224 | | - |
1225 | | - return ignore |
0 commit comments