| 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): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 117 | ||
| 118 | # Handle empty string case | |
| 119 | if not value: | |
| 120 | try: | |
| 121 | patterns.append(_regex_transformer(value)) | |
| 122 | return patterns | |
| 123 | except argparse.ArgumentTypeError: | |
| 124 | # Empty string is not a valid regex, fall back to CSV (which will be empty) | |
| 125 | return patterns | |
| 126 | ||
| 127 | # Check if the value contains regex constructs that use commas | |
| 128 | # These include quantifiers like {n,m}, character classes with commas, etc. | |
| 129 | has_regex_commas = ( | |
| 130 | '{' in value and '}' in value and ',' in value # Quantifiers like {1,3} | |
| 131 | or '[' in value and ']' in value and ',' in value # Character classes with commas | |
| 132 | ) | |
| 133 | ||
| 134 | # If the value contains regex constructs with commas, try to treat it as a single pattern first | |
| 135 | if has_regex_commas: | |
| 136 | try: | |
| 137 | patterns.append(_regex_transformer(value)) | |
| 138 | return patterns | |
| 139 | except argparse.ArgumentTypeError: | |
| 140 | # If it fails, fall back to CSV splitting | |
| 141 | pass | |
| 142 | ||
| 143 | # Split on commas and try to compile each part | |
| 144 | csv_parts = _csv_transformer(value) | |
| 145 | ||
| 146 | # If we only have one part, treat it as a single pattern | |
| 147 | if len(csv_parts) == 1: | |
| 148 | patterns.append(_regex_transformer(value)) | |
| 149 | return patterns | |
| 150 | ||
| 151 | # Try to compile each part as a separate regex | |
| 152 | # If all compile successfully, treat as CSV-separated patterns | |
| 153 | try: | |
| 154 | compiled_parts = [_regex_transformer(part) for part in csv_parts] | |
| 155 | return compiled_parts | |
| 156 | except argparse.ArgumentTypeError: | |
| 157 | # If any part fails to compile, treat the whole string as a single pattern | |
| 158 | patterns.append(_regex_transformer(value)) | |
| 159 | return patterns | |
| 120 | 160 | |
| 121 | 161 | |
| 122 | 162 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | 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_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.