Parse a specifier string (i.e. ``">=3.7,<3.10"``) to a list of TargetVersion. If parsing fails, will raise a packaging.specifiers.InvalidSpecifier error. If the parsed specifier cannot be mapped to a valid TargetVersion, returns None.
(requires_python: str)
| 169 | |
| 170 | |
| 171 | def parse_req_python_specifier(requires_python: str) -> Optional[List[TargetVersion]]: |
| 172 | """Parse a specifier string (i.e. ``">=3.7,<3.10"``) to a list of TargetVersion. |
| 173 | |
| 174 | If parsing fails, will raise a packaging.specifiers.InvalidSpecifier error. |
| 175 | If the parsed specifier cannot be mapped to a valid TargetVersion, returns None. |
| 176 | """ |
| 177 | specifier_set = strip_specifier_set(SpecifierSet(requires_python)) |
| 178 | if not specifier_set: |
| 179 | return None |
| 180 | |
| 181 | target_version_map = {f"3.{v.value}": v for v in TargetVersion} |
| 182 | compatible_versions: List[str] = list(specifier_set.filter(target_version_map)) |
| 183 | if compatible_versions: |
| 184 | return [target_version_map[v] for v in compatible_versions] |
| 185 | return None |
| 186 | |
| 187 | |
| 188 | def strip_specifier_set(specifier_set: SpecifierSet) -> SpecifierSet: |
no test coverage detected