| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | # First, try to split on commas and see if all parts are valid regexes | |
| 117 | # This maintains backward compatibility with comma-separated patterns | |
| 118 | split_patterns = _csv_transformer(value) | |
| 116 | 119 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 120 | split_valid = True | |
| 121 | ||
| 122 | # Try to compile each split pattern | |
| 123 | for pattern in split_patterns: | |
| 124 | try: | |
| 125 | patterns.append(_regex_transformer(pattern)) | |
| 126 | except argparse.ArgumentTypeError: | |
| 127 | split_valid = False | |
| 128 | break | |
| 129 | ||
| 130 | # If all split patterns are valid, return them | |
| 131 | if split_valid and len(patterns) > 1: | |
| 132 | return patterns | |
| 133 | ||
| 134 | # Otherwise, treat the entire value as a single regex pattern | |
| 135 | return [_regex_transformer(value)] | |
| 120 | 136 | |
| 121 | 137 | |
| 122 | 138 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 139 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | patterns: list[Pattern[str]] = [] | |
| 125 | for pattern in _csv_transformer(value): | |
| 126 | patterns.append( | |
| 140 | # For path patterns, we're more conservative about splitting | |
| 141 | # Only split if we have clear comma-separated path patterns | |
| 142 | split_patterns = _csv_transformer(value) | |
| 143 | ||
| 144 | # If there's only one pattern after splitting, treat it as a single pattern | |
| 145 | if len(split_patterns) == 1: | |
| 146 | return [ | |
| 127 | 147 | re.compile( |
| 128 | str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\") | |
| 148 | str(pathlib.PureWindowsPath(value)).replace("\\", "\\\\") | |
| 129 | 149 | + "|" |
| 130 | + pathlib.PureWindowsPath(pattern).as_posix() | |
| 150 | + pathlib.PureWindowsPath(value).as_posix() | |
| 151 | ) | |
| 152 | ] | |
| 153 | ||
| 154 | # For multiple patterns, check if they look like separate path patterns | |
| 155 | # We'll be conservative and only split if all parts are simple path names | |
| 156 | # without complex regex syntax that might include commas | |
| 157 | looks_like_separate_paths = True | |
| 158 | for pattern in split_patterns: | |
| 159 | # If a pattern contains complex regex syntax, treat the whole thing as one pattern | |
| 160 | if any(char in pattern for char in ['{', '}', '[', ']', '*', '+', '?', '|']): | |
| 161 | looks_like_separate_paths = False | |
| 162 | break | |
| 163 | ||
| 164 | if looks_like_separate_paths: | |
| 165 | # Split and process each pattern individually | |
| 166 | patterns: list[Pattern[str]] = [] | |
| 167 | for pattern in split_patterns: | |
| 168 | patterns.append( | |
| 169 | re.compile( | |
| 170 | str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\") | |
| 171 | + "|" | |
| 172 | + pathlib.PureWindowsPath(pattern).as_posix() | |
| 173 | ) | |
| 131 | 174 | ) |
| 175 | return patterns | |
| 176 | ||
| 177 | # Otherwise, treat the entire value as a single regex pattern | |
| 178 | return [ | |
| 179 | re.compile( | |
| 180 | str(pathlib.PureWindowsPath(value)).replace("\\", "\\\\") | |
| 181 | + "|" | |
| 182 | + pathlib.PureWindowsPath(value).as_posix() | |
| 132 | 183 | ) |
| 133 | return patterns | |
| 184 | ] | |
| 134 | 185 | |
| 135 | 186 | |
| 136 | 187 | _TYPE_TRANSFORMERS: dict[str, Callable[[str], _ArgumentTypes]] = { |
| 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.