Checks if we should assume python2 code.
(
compatibilities: Iterable[Optional[Iterable[str]]], python_setup: PythonSetup
)
| 217 | |
| 218 | |
| 219 | def is_python2( |
| 220 | compatibilities: Iterable[Optional[Iterable[str]]], python_setup: PythonSetup |
| 221 | ) -> bool: |
| 222 | """Checks if we should assume python2 code.""" |
| 223 | |
| 224 | def iter_reqs(): |
| 225 | for compatibility in compatibilities: |
| 226 | for constraint in python_setup.compatibility_or_constraints(compatibility): |
| 227 | yield parse_interpreter_constraint(constraint) |
| 228 | |
| 229 | for req in iter_reqs(): |
| 230 | for python_27_ver in range(0, 18): # The last python 2.7 version was 2.7.18. |
| 231 | if req.specifier.contains(f"2.7.{python_27_ver}"): |
| 232 | # At least one constraint limits us to Python 2, so assume that. |
| 233 | return True |
| 234 | return False |