| 111 | 111 | raise argparse.ArgumentTypeError(msg) from e |
| 112 | 112 | |
| 113 | 113 | |
| 114 | def _split_regex_csv(value: str) -> list[str]: | |
| 115 | """Split CSV string while respecting regex syntax. | |
| 116 | ||
| 117 | This function intelligently splits a comma-separated string of regex patterns, | |
| 118 | respecting commas that appear inside regex constructs like: | |
| 119 | - Character classes: [a,b,c] | |
| 120 | - Quantifiers: {1,3} | |
| 121 | - Groups: (foo,bar) | |
| 122 | ||
| 123 | Only commas at the top level (outside these constructs) are treated as delimiters. | |
| 124 | """ | |
| 125 | if not value: | |
| 126 | return [] | |
| 127 | ||
| 128 | patterns = [] | |
| 129 | current = [] | |
| 130 | depth = 0 # Track nesting level for parentheses and braces | |
| 131 | in_char_class = False # Track if we're inside a character class | |
| 132 | i = 0 | |
| 133 | ||
| 134 | while i < len(value): | |
| 135 | char = value[i] | |
| 136 | ||
| 137 | # Handle character classes specially - they can contain commas | |
| 138 | if char == '[' and not in_char_class: | |
| 139 | in_char_class = True | |
| 140 | elif char == ']' and in_char_class: | |
| 141 | in_char_class = False | |
| 142 | ||
| 143 | # Track nesting for parentheses and braces (but not in char classes) | |
| 144 | elif char in '({' and not in_char_class: | |
| 145 | depth += 1 | |
| 146 | elif char in ')}' and not in_char_class: | |
| 147 | depth -= 1 | |
| 148 | ||
| 149 | # Split on comma only at top level and not in character classes | |
| 150 | elif char == ',' and depth == 0 and not in_char_class: | |
| 151 | pattern = ''.join(current).strip() | |
| 152 | if pattern: # Skip empty patterns | |
| 153 | patterns.append(pattern) | |
| 154 | current = [] | |
| 155 | i += 1 | |
| 156 | continue | |
| 157 | ||
| 158 | current.append(char) | |
| 159 | i += 1 | |
| 160 | ||
| 161 | # Add the last pattern | |
| 162 | pattern = ''.join(current).strip() | |
| 163 | if pattern: | |
| 164 | patterns.append(pattern) | |
| 165 | ||
| 166 | return patterns | |
| 167 | ||
| 168 | ||
| 114 | 169 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 170 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 171 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 172 | for pattern in _split_regex_csv(value): | |
| 118 | 173 | patterns.append(_regex_transformer(pattern)) |
| 119 | 174 | return patterns |
| 120 | 175 |
| 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.