Skip to content

Commit

Permalink
Restore Always OR interpreter constraints when given list
Browse files Browse the repository at this point in the history
Per pex-tool#655 (comment), Chris is okay with always ORing. This is a much more consistent and simpler approach, so is ideal over the earlier conditional logic.
  • Loading branch information
Eric-Arellano committed Mar 7, 2019
1 parent 193c385 commit 6fc3cff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 6 additions & 10 deletions pex/interpreter_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ def validate_constraints(constraints):
die("Compatibility requirements are not formatted properly: %s" % str(e))


def matched_interpreters(interpreters, constraints, meet_all_constraints=False):
"""Given some filters, yield any interpreter that matches at least one of them, or all of them
if meet_all_constraints is set to True.
def matched_interpreters(interpreters, constraints):
"""Given some filters, yield any interpreter that matches at least one of them.
:param interpreters: a list of PythonInterpreter objects for filtering
:param constraints: A sequence of strings that constrain the interpreter compatibility for this
pex. Each string uses the Requirement-style format, e.g. 'CPython>=3' or '>=2.7,<3' for requirements
agnostic to interpreter class. Multiple requirement strings may be combined into a list, such as
['CPython>=2.7,<3', 'CPython>=3.4'], to either OR or AND the requirements depending on `meet_all_constraints`.
:param meet_all_constraints: whether to match against all filters (AND).
Defaults to matching interpreters that match at least one filter (OR).
pex. Each string uses the Requirement-style format, e.g. 'CPython>=3' or '>=2.7,<3' for
requirements agnostic to interpreter class. Multiple requirement strings may be combined
into a list to OR the constraints, such as ['CPython>=2.7,<3', 'CPython>=3.4'].
:return interpreter: returns a generator that yields compatible interpreters
"""
check = all if meet_all_constraints else any
for interpreter in interpreters:
if check(interpreter.identity.matches(filt) for filt in constraints):
if any(interpreter.identity.matches(filt) for filt in constraints):
TRACER.log("Constraints on interpreters: %s, Matching Interpreter: %s"
% (constraints, interpreter.binary), V=3)
yield interpreter
6 changes: 2 additions & 4 deletions pex/pex_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def find_compatible_interpreters(pex_python_path, compatibility_constraints):
# get all qualifying interpreters found in $PATH
interpreters = PythonInterpreter.all()

return list(matched_interpreters(
interpreters, compatibility_constraints, meet_all_constraints=meet_all_constraints))
return list(matched_interpreters(interpreters, compatibility_constraints))


def _select_pex_python_interpreter(target_python, compatibility_constraints):
Expand All @@ -100,8 +99,7 @@ def _select_pex_python_interpreter(target_python, compatibility_constraints):
die('Failed to find interpreter specified by PEX_PYTHON: %s' % target)
if compatibility_constraints:
pi = PythonInterpreter.from_binary(target)
# AND the interpreter constraints
if not list(matched_interpreters([pi], compatibility_constraints, meet_all_constraints=True)):
if not list(matched_interpreters([pi], compatibility_constraints)):
die('Interpreter specified by PEX_PYTHON (%s) is not compatible with specified '
'interpreter constraints: %s' % (target, str(compatibility_constraints)))
if not os.path.exists(target):
Expand Down

0 comments on commit 6fc3cff

Please sign in to comment.