| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 116 | patterns: list[Pattern[str]] = [] | |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 115 | """Transforms a comma separated list of regular expressions. | |
| 116 | ||
| 117 | This function handles the case where a single regular expression | |
| 118 | contains commas (e.g., (foo{1,3})) by first attempting to split | |
| 119 | the input on commas and validate each part. If all parts are valid | |
| 120 | regular expressions and there are multiple parts, they are treated | |
| 121 | as separate patterns. Otherwise, the entire input is treated as | |
| 122 | a single regular expression. | |
| 123 | """ | |
| 124 | if not value: | |
| 125 | return [] | |
| 126 | ||
| 127 | # First, try to split and see if all parts are valid regexes | |
| 128 | parts = [part.strip() for part in value.split(",") if part.strip()] | |
| 129 | ||
| 130 | # Try to compile each part as a separate regex | |
| 131 | valid_parts = [] | |
| 132 | all_valid = True | |
| 133 | ||
| 134 | for part in parts: | |
| 135 | try: | |
| 136 | compiled = _regex_transformer(part) | |
| 137 | valid_parts.append(compiled) | |
| 138 | except (re.error, argparse.ArgumentTypeError): | |
| 139 | all_valid = False | |
| 140 | break | |
| 141 | ||
| 142 | # If all parts are valid regexes and there are multiple parts, return them | |
| 143 | if all_valid and len(valid_parts) > 1: | |
| 144 | return valid_parts | |
| 145 | ||
| 146 | # Otherwise, treat the whole thing as a single regex | |
| 147 | try: | |
| 148 | return [_regex_transformer(value)] | |
| 149 | except (re.error, argparse.ArgumentTypeError) as e: | |
| 150 | # If even the whole thing is invalid, re-raise with better error | |
| 151 | if not all_valid and valid_parts: | |
| 152 | # The first invalid part caused the issue | |
| 153 | first_invalid = parts[len(valid_parts)] | |
| 154 | try: | |
| 155 | _regex_transformer(first_invalid) | |
| 156 | except (re.error, argparse.ArgumentTypeError) as inner_e: | |
| 157 | raise inner_e from e | |
| 158 | else: | |
| 159 | raise | |
| 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.