Skip to content

Commit

Permalink
Fix UnsatisfiableInterpreterConstraintsError. (#1024)
Browse files Browse the repository at this point in the history
Handle the case when there are no candidates and add a test for this.
  • Loading branch information
jsirois authored Aug 29, 2020
1 parent ca70a39 commit 026f5e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pex/interpreter_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ def create_message(self, preamble=None):
:return: A descriptive message useable for display to an end user.
:rtype: str
"""
preamble = "{}\n\n".format(preamble) if preamble else ""
if not self.candidates:
return "{}No interpreters could be found on the system.".format(preamble)
binary_column_width = max(len(candidate.binary) for candidate in self.candidates)
interpreters_format = "{{binary: >{}}} {{requirement}}".format(binary_column_width)
return (
"{preamble}"
"Examined the following interpreters:\n {interpreters}\n\n"
"None were compatible with the requested constraints:\n {constraints}"
).format(
preamble="{}\n\n".format(preamble) if preamble else "",
preamble=preamble,
interpreters="\n ".join(
interpreters_format.format(
binary=candidate.binary, requirement=candidate.identity.requirement
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pex_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def test_find_compatible_interpreters():
)


def test_find_compatible_interpreters_none():
with pytest.raises(UnsatisfiableInterpreterConstraintsError):
find_interpreters([os.path.devnull], ">2")


def test_find_compatible_interpreters_bias_current():
py36 = ensure_python_interpreter(PY36)
assert [os.path.realpath(sys.executable), py36] == find_interpreters([py36, sys.executable])
Expand Down

0 comments on commit 026f5e8

Please sign in to comment.