| 111 | 111 | raise argparse.ArgumentTypeError(msg) from e |
| 112 | 112 | |
| 113 | 113 | |
| 114 | def _split_regex_csv(value: str) -> Sequence[str]: | |
| 115 | """Split a comma-separated list of regular expressions, handling commas within regex syntax. | |
| 116 | ||
| 117 | This function is smart about regex syntax and won't split on commas that are | |
| 118 | part of regex constructs like {1,3} or character classes [a,b]. | |
| 119 | """ | |
| 120 | if not value.strip(): | |
| 121 | return [] | |
| 122 | ||
| 123 | patterns = [] | |
| 124 | current = [] | |
| 125 | i = 0 | |
| 126 | paren_depth = 0 | |
| 127 | brace_depth = 0 | |
| 128 | bracket_depth = 0 | |
| 129 | ||
| 130 | while i < len(value): | |
| 131 | char = value[i] | |
| 132 | ||
| 133 | # Track nesting levels to avoid splitting inside regex constructs | |
| 134 | if char == '(' and (i == 0 or value[i-1] != '\\'): | |
| 135 | paren_depth += 1 | |
| 136 | elif char == ')' and (i == 0 or value[i-1] != '\\'): | |
| 137 | paren_depth = max(0, paren_depth - 1) | |
| 138 | elif char == '{' and (i == 0 or value[i-1] != '\\'): | |
| 139 | brace_depth += 1 | |
| 140 | elif char == '}' and (i == 0 or value[i-1] != '\\'): | |
| 141 | brace_depth = max(0, brace_depth - 1) | |
| 142 | elif char == '[' and (i == 0 or value[i-1] != '\\'): | |
| 143 | bracket_depth += 1 | |
| 144 | elif char == ']' and (i == 0 or value[i-1] != '\\'): | |
| 145 | bracket_depth = max(0, bracket_depth - 1) | |
| 146 | ||
| 147 | # Split on comma only if we're not inside any regex construct | |
| 148 | if char == ',' and paren_depth == 0 and brace_depth == 0 and bracket_depth == 0: | |
| 149 | pattern = ''.join(current).strip() | |
| 150 | if pattern: | |
| 151 | patterns.append(pattern) | |
| 152 | current = [] | |
| 153 | else: | |
| 154 | current.append(char) | |
| 155 | ||
| 156 | i += 1 | |
| 157 | ||
| 158 | # Add the last pattern | |
| 159 | pattern = ''.join(current).strip() | |
| 160 | if pattern: | |
| 161 | patterns.append(pattern) | |
| 162 | ||
| 163 | return patterns | |
| 164 | ||
| 165 | ||
| 114 | 166 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 167 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 168 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 169 | for pattern in _split_regex_csv(value): | |
| 118 | 170 | patterns.append(_regex_transformer(pattern)) |
| 119 | 171 | return patterns |
| 120 | 172 |
| 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.