Skip to content

Commit

Permalink
Improvement #2: show all discovered interpreters
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Apr 26, 2019
1 parent 8ee32cb commit 9729ed4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/python/pants/backend/python/interpreter_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

# TODO: Move under subsystems/ .
class PythonInterpreterCache(Subsystem):
"""Finds python interpreters on the local system."""
"""Finds Python interpreters on the local system."""
options_scope = 'python-interpreter-cache'

@classmethod
def subsystem_dependencies(cls):
return super(PythonInterpreterCache, cls).subsystem_dependencies() + (PythonSetup,)

class UnsatisfiableInterpreterConstraintsError(TaskError):
"""Indicates a python interpreter matching given constraints could not be located."""
"""Indicates a Python interpreter matching given constraints could not be located."""

@staticmethod
def _matches(interpreter, filters=()):
Expand Down Expand Up @@ -89,17 +89,27 @@ def select_interpreter_for_targets(self, targets):

if not allowed_interpreters:
# Create a helpful error message.
all_interpreter_version_strings = sorted({
interpreter.version_string
# NB: self.setup requires filters to avoid using the global interpreter constraints.
# We allow any interpreter other than 3.0-3.3, which is known to choke with Pants.
for interpreter in self.setup(filters=("CPython<3", "CPython>=3.3", "PyPy"))
})
unique_compatibilities = {tuple(c) for c in tgts_by_compatibilities.keys()}
unique_compatibilities_strs = [','.join(x) for x in unique_compatibilities if x]
tgts_by_compatibilities_strs = [t[0].address.spec for t in tgts_by_compatibilities.values()]
raise self.UnsatisfiableInterpreterConstraintsError(dedent("""\
Unable to detect a suitable interpreter for compatibilities: {} (Conflicting targets: {})
To fix this, either modify your Python interpreter constraints by following
https://www.pantsbuild.org/python_readme.html#configure-the-python-version or install the
targeted interpreter on your system.""".format(
Pants detected these interpreter versions on your system: {}
Possible ways to fix this:
* Modify your Python interpreter constraints by following https://www.pantsbuild.org/python_readme.html#configure-the-python-version.
* Ensure the targeted Python version is installed and discoverable.
* Modify Pants' interpreter search paths via --pants-setup-interpreter-search-paths.""".format(
' && '.join(sorted(unique_compatibilities_strs)),
', '.join(tgts_by_compatibilities_strs)
', '.join(tgts_by_compatibilities_strs),
', '.join(all_interpreter_version_strings)
)))
# Return the lowest compatible interpreter.
return min(allowed_interpreters)
Expand Down

0 comments on commit 9729ed4

Please sign in to comment.