MCPcopy
hub / github.com/pantsbuild/pants / is_python2

Function is_python2

src/python/pants/backend/python/rules/util.py:219–234  ·  view source on GitHub ↗

Checks if we should assume python2 code.

(
    compatibilities: Iterable[Optional[Iterable[str]]], python_setup: PythonSetup
)

Source from the content-addressed store, hash-verified

217
218
219def 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

Callers 3

test_is_python2Function · 0.90
test_is_not_python2Function · 0.90
run_setup_pysFunction · 0.90

Calls 1

iter_reqsFunction · 0.85

Tested by 2

test_is_python2Function · 0.72
test_is_not_python2Function · 0.72