# Buggy code
def resolveEntryPoint(entryPoint):
    """
    Returns the path to the given entry point (see setup.py) that *should* work on a worker. The
    return value may be an absolute or a relative path.
    """
    if hasattr(sys, "real_prefix"):
        # Inside a virtualenv we will use absolute paths to the entrypoints. For clusters this
        # means that if Toil is installed in a virtualenv on the leader, it must be installed in
        # a virtualenv located at the same path on the worker.
        path = os.path.join(os.path.dirname(sys.executable), entryPoint)
        assert os.path.isfile(path)
        assert os.access(path, os.X_OK)
        return path
    else:
        # Outside a virtualenv it is hard to predict where the entry points got installed. It is
        # the reponsibility of the user to ensure that they are present on PATH and point to the
        # correct version of Toil. This is still better than an absolute path because it gives
        # the user control over Toil's location on both leader and workers.
        return entryPoint


# Traceback (AssertionError)
INFO:toil.leader:Starting the main loop
Traceback (most recent call last):
File "./piptest/bin/toil-rnaseq", line 11, in <module>
sys.exit(main())
File "/home/mesosbox/piptest/local/lib/python2.7/site-packages/toil_scripts/rnaseq_cgl/rnaseq_cgl_pipeline.py", line 638, in main
Job.Runner.startToil(Job.wrapJobFn(map_job, download_sample, samples, config), args)
File "/usr/local/lib/python2.7/dist-packages/toil/job.py", line 445, in startToil
return mainLoop(config, batchSystem, jobStore, rootJob, jobCache=jobCache)
File "/usr/local/lib/python2.7/dist-packages/toil/leader.py", line 392, in mainLoop
jobWrapper.cores, jobWrapper.disk)
File "/usr/local/lib/python2.7/dist-packages/toil/leader.py", line 101, in issueJob
jobCommand = ' '.join((resolveEntryPoint('_toil_worker'), self.jobStoreString, jobStoreID))
File "/usr/local/lib/python2.7/dist-packages/toil/__init__.py", line 45, in resolveEntryPoint
assert os.path.isfile(path)
AssertionError

# Fixed code
def resolveEntryPoint(entryPoint):
    """
    Returns the path to the given entry point (see setup.py) that *should* work on a worker. The
    return value may be an absolute or a relative path.
    """
    if hasattr(sys, "real_prefix"):
        path = os.path.join(os.path.dirname(sys.executable), entryPoint)
        # Inside a virtualenv we try to use absolute paths to the entrypoints.
        if os.path.isfile(path):
            # If the entrypoint is present, Toil must have been installed into the virtualenv (as
            # opposed to being included via --system-site-packages). For clusters this means that
            # if Toil is installed in a virtualenv on the leader, it must be installed in
            # a virtualenv located at the same path on each worker as well.
            assert os.access(path, os.X_OK)
            return path
        else:
            # For virtualenv's that have the toil package directory on their sys.path but whose
            # bin directory lacks the Toil entrypoints, i.e. where Toil is included via
            # --system-site-packages, we rely on PATH just as if we weren't in a virtualenv.
            return entryPoint
    else:
        # Outside a virtualenv it is hard to predict where the entry points got installed. It is
        # the reponsibility of the user to ensure that they are present on PATH and point to the
        # correct version of Toil. This is still better than an absolute path because it gives
        # the user control over Toil's location on both leader and workers.
        return entryPoint