Parse a version string (i.e. ``"3.7"``) to a list of TargetVersion. If parsing fails, will raise a packaging.version.InvalidVersion error. If the parsed version cannot be mapped to a valid TargetVersion, returns None.
(requires_python: str)
| 154 | |
| 155 | |
| 156 | def parse_req_python_version(requires_python: str) -> Optional[List[TargetVersion]]: |
| 157 | """Parse a version string (i.e. ``"3.7"``) to a list of TargetVersion. |
| 158 | |
| 159 | If parsing fails, will raise a packaging.version.InvalidVersion error. |
| 160 | If the parsed version cannot be mapped to a valid TargetVersion, returns None. |
| 161 | """ |
| 162 | version = Version(requires_python) |
| 163 | if version.release[0] != 3: |
| 164 | return None |
| 165 | try: |
| 166 | return [TargetVersion(version.release[1])] |
| 167 | except (IndexError, ValueError): |
| 168 | return None |
| 169 | |
| 170 | |
| 171 | def parse_req_python_specifier(requires_python: str) -> Optional[List[TargetVersion]]: |
no test coverage detected