| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 116 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 117 | ||
| 118 | # Handle the case where the input is already a list/tuple | |
| 119 | if isinstance(value, (list, tuple)): | |
| 120 | for pattern in value: | |
| 121 | patterns.append(_regex_transformer(pattern)) | |
| 122 | return patterns | |
| 123 | ||
| 124 | # Parse comma-separated regex patterns while respecting commas within regex syntax | |
| 125 | # We need to split on commas that are not inside brackets, braces, or parentheses | |
| 126 | patterns_list = [] | |
| 127 | current_pattern = "" | |
| 128 | bracket_count = 0 # For [] | |
| 129 | brace_count = 0 # For {} | |
| 130 | paren_count = 0 # For () | |
| 131 | ||
| 132 | i = 0 | |
| 133 | while i < len(value): | |
| 134 | char = value[i] | |
| 135 | ||
| 136 | # Track nesting levels (only count if not escaped) | |
| 137 | if char == '[' and (i == 0 or value[i-1] != '\\'): | |
| 138 | bracket_count += 1 | |
| 139 | elif char == ']' and (i == 0 or value[i-1] != '\\'): | |
| 140 | bracket_count = max(0, bracket_count - 1) | |
| 141 | elif char == '{' and (i == 0 or value[i-1] != '\\'): | |
| 142 | brace_count += 1 | |
| 143 | elif char == '}' and (i == 0 or value[i-1] != '\\'): | |
| 144 | brace_count = max(0, brace_count - 1) | |
| 145 | elif char == '(' and (i == 0 or value[i-1] != '\\'): | |
| 146 | paren_count += 1 | |
| 147 | elif char == ')' and (i == 0 or value[i-1] != '\\'): | |
| 148 | paren_count = max(0, paren_count - 1) | |
| 149 | ||
| 150 | # Split on comma only if we're not inside any nested structure | |
| 151 | if char == ',' and bracket_count == 0 and brace_count == 0 and paren_count == 0: | |
| 152 | pattern = current_pattern.strip() | |
| 153 | if pattern: # Only add non-empty patterns | |
| 154 | patterns_list.append(pattern) | |
| 155 | current_pattern = "" | |
| 156 | else: | |
| 157 | current_pattern += char | |
| 158 | ||
| 159 | i += 1 | |
| 160 | ||
| 161 | # Add the last pattern | |
| 162 | pattern = current_pattern.strip() | |
| 163 | if pattern: | |
| 164 | patterns_list.append(pattern) | |
| 165 | ||
| 166 | # If no patterns were found (empty string), return empty list | |
| 167 | if not patterns_list: | |
| 168 | return patterns | |
| 169 | ||
| 170 | # Compile each pattern | |
| 171 | for pattern in patterns_list: | |
| 118 | 172 | patterns.append(_regex_transformer(pattern)) |
| 173 | ||
| 119 | 174 | return patterns |
| 120 | 175 | |
| 121 | 176 | |
| 122 | 177 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 178 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | 179 | patterns: list[Pattern[str]] = [] |
| 125 | for pattern in _csv_transformer(value): | |
| 180 | ||
| 181 | # Handle the case where the input is already a list/tuple | |
| 182 | if isinstance(value, (list, tuple)): | |
| 183 | for pattern in value: | |
| 184 | patterns.append( | |
| 185 | re.compile( | |
| 186 | str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\") | |
| 187 | + "|" | |
| 188 | + pathlib.PureWindowsPath(pattern).as_posix() | |
| 189 | ) | |
| 190 | ) | |
| 191 | return patterns | |
| 192 | ||
| 193 | # Parse comma-separated regex patterns while respecting commas within regex syntax | |
| 194 | # We need to split on commas that are not inside brackets, braces, or parentheses | |
| 195 | patterns_list = [] | |
| 196 | current_pattern = "" | |
| 197 | bracket_count = 0 # For [] | |
| 198 | brace_count = 0 # For {} | |
| 199 | paren_count = 0 # For () | |
| 200 | ||
| 201 | i = 0 | |
| 202 | while i < len(value): | |
| 203 | char = value[i] | |
| 204 | ||
| 205 | # Track nesting levels (only count if not escaped) | |
| 206 | if char == '[' and (i == 0 or value[i-1] != '\\'): | |
| 207 | bracket_count += 1 | |
| 208 | elif char == ']' and (i == 0 or value[i-1] != '\\'): | |
| 209 | bracket_count = max(0, bracket_count - 1) | |
| 210 | ||
| 211 | elif char == '{' and (i == 0 or value[i-1] != '\\'): | |
| 212 | brace_count += 1 | |
| 213 | elif char == '}' and (i == 0 or value[i-1] != '\\'): | |
| 214 | brace_count = max(0, brace_count - 1) | |
| 215 | elif char == '(' and (i == 0 or value[i-1] != '\\'): | |
| 216 | paren_count += 1 | |
| 217 | elif char == ')' and (i == 0 or value[i-1] != '\\'): | |
| 218 | paren_count = max(0, paren_count - 1) | |
| 219 | ||
| 220 | # Split on comma only if we're not inside any nested structure | |
| 221 | if char == ',' and bracket_count == 0 and brace_count == 0 and paren_count == 0: | |
| 222 | pattern = current_pattern.strip() | |
| 223 | if pattern: # Only add non-empty patterns | |
| 224 | patterns_list.append(pattern) | |
| 225 | current_pattern = "" | |
| 226 | else: | |
| 227 | current_pattern += char | |
| 228 | ||
| 229 | i += 1 | |
| 230 | ||
| 231 | # Add the last pattern | |
| 232 | pattern = current_pattern.strip() | |
| 233 | if pattern: | |
| 234 | patterns_list.append(pattern) | |
| 235 | ||
| 236 | # If no patterns were found (empty string), return empty list | |
| 237 | if not patterns_list: | |
| 238 | return patterns | |
| 239 | ||
| 240 | # Compile each pattern | |
| 241 | for pattern in patterns_list: | |
| 126 | 242 | patterns.append( |
| 127 | 243 | re.compile( |
| 128 | 244 | str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\") |
| 130 | 246 | + pathlib.PureWindowsPath(pattern).as_posix() |
| 131 | 247 | ) |
| 132 | 248 | ) |
| 249 | ||
| 133 | 250 | return patterns |
| 134 | 251 | |
| 135 | 252 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Pass |
tests/config/test_config.py::test_unknown_message_id | Pass |
tests/config/test_config.py::test_unknown_option_name | Pass |
tests/config/test_config.py::test_unknown_short_option_name | Pass |
tests/config/test_config.py::test_unknown_confidence | Pass |
tests/config/test_config.py::test_empty_confidence | Pass |
tests/config/test_config.py::test_unknown_yes_no | Pass |
tests/config/test_config.py::test_unknown_py_version | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Pass |
tests/config/test_config.py::test_regex_error | Pass |
tests/config/test_config.py::test_short_verbose | Pass |
tests/config/test_config.py::test_argument_separator | Pass |
tests/config/test_config.py::test_clear_cache_post_run | Pass |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Pass |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Pass |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.