# Buggy code
def execute(self):
    # NB: Downstream product consumers may need the selected interpreter for use with
    # any type of importable Python target, including `PythonRequirementLibrary` targets
    # (for use with the `repl` goal, for instance). For interpreter selection,
    # we only care about targets with compatibility constraints.
    python_tgts_and_reqs = self.context.targets(
        lambda tgt: isinstance(tgt, (PythonTarget, PythonRequirementLibrary))
    )
    if not python_tgts_and_reqs:
        return
    python_tgts = [tgt for tgt in python_tgts_and_reqs if isinstance(tgt, PythonTarget)]
    fs = PythonInterpreterFingerprintStrategy()
    with self.invalidated(python_tgts, fingerprint_strategy=fs) as invalidation_check:
        # If there are no relevant targets, we still go through the motions of selecting
        # an interpreter, to prevent downstream tasks from having to check for this special case.
        if invalidation_check.all_vts:
            target_set_id = VersionedTargetSet.from_versioned_targets(
                invalidation_check.all_vts
            ).cache_key.hash
        else:
            target_set_id = "no_targets"
        interpreter_path_file = self._interpreter_path_file(target_set_id)
        if not os.path.exists(interpreter_path_file):
            self._create_interpreter_path_file(interpreter_path_file, python_tgts)

    interpreter = self._get_interpreter(interpreter_path_file)
    self.context.products.register_data(PythonInterpreter, interpreter)


# Traceback (OSError)
os.path.exists(os.readlink('python'))
False
subprocess.Popen(['./python', 'blah'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/opt/twitter_mde/package/python2.7/current/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/twitter_mde/package/python2.7/current/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

# Fixed code
def execute(self):
    # NB: Downstream product consumers may need the selected interpreter for use with
    # any type of importable Python target, including `PythonRequirementLibrary` targets
    # (for use with the `repl` goal, for instance). For interpreter selection,
    # we only care about targets with compatibility constraints.
    python_tgts_and_reqs = self.context.targets(
        lambda tgt: isinstance(tgt, (PythonTarget, PythonRequirementLibrary))
    )
    if not python_tgts_and_reqs:
        return
    python_tgts = [tgt for tgt in python_tgts_and_reqs if isinstance(tgt, PythonTarget)]
    fs = PythonInterpreterFingerprintStrategy()
    with self.invalidated(python_tgts, fingerprint_strategy=fs) as invalidation_check:
        # If there are no relevant targets, we still go through the motions of selecting
        # an interpreter, to prevent downstream tasks from having to check for this special case.
        if invalidation_check.all_vts:
            target_set_id = VersionedTargetSet.from_versioned_targets(
                invalidation_check.all_vts
            ).cache_key.hash
        else:
            target_set_id = "no_targets"
        interpreter_path_file = self._interpreter_path_file(target_set_id)
        if not os.path.exists(interpreter_path_file):
            self._create_interpreter_path_file(interpreter_path_file, python_tgts)
        else:
            if self._detect_and_purge_invalid_interpreter(interpreter_path_file):
                self._create_interpreter_path_file(interpreter_path_file, python_tgts)

    interpreter = self._get_interpreter(interpreter_path_file)
    self.context.products.register_data(PythonInterpreter, interpreter)