-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the way options are provided #28
Comments
This sounds fair. However, if If you are not planning to use def call(docker=None, singularity=None, working_dir=None, volumes=None, cwd=None, env=None, check_output=False):
call_kwargs = {}
if singularity and docker:
raise exceptions.UsageError("use docker or singularity, not both.")
if singularity or docker:
call_kwargs["check_output"] = check_output
# used for testing only
call_kwargs["remove_tmp_dir"] = getattr(self, "_rm_tmp_dir", True)
if working_dir:
call_kwargs["working_dir"] = working_dir
if volumes:
call_kwargs["volumes"] = volumes
if singularity:
call_kwargs["image"] = singularity
call_function = singularity_call
else:
call_kwargs["image"] = docker
call_function = docker_call
elif check_output:
call_function = subprocess.check_output
else:
call_function = subprocess.check_call
errors = (exceptions.ContainerError, subprocess.CalledProcessError, OSError)
try:
output = call_function(**call_kwargs)
except errors as error: # pylint: disable=catching-non-exception
raise exceptions.SystemCallError(error)
try:
return output.decode()
except AttributeError:
return output Then Am I understanding this correctly? |
Yes that's basically exactly what I want to do (and have done, in my WIP code)! I think that would be a big improvement. The only issue I've encountered so far is in solving point b). Toil doesn't seem to have a mechanism for adding arbitrary data to the config, and accessing it in jobs (see DataBiosphere/toil#3619). So something simple like "use singularity for container jobs" has to be passed to each job which is a pain. The closest I've got is to accessing |
I think I understand what you are trying to do. The toil_container/toil_container/parsers.py Lines 148 to 228 in 2afa800
Where the toil options are added in a parent class: toil_container/toil_container/parsers.py Lines 59 to 61 in 2afa800
One reason you might not be seeing # whalesay.py
from toil_container import ContainerJob
from toil_container import ContainerArgumentParser
class WhaleSayJob(ContainerJob):
def run(self, fileStore):
"""Run `cowsay` with Docker, Singularity or Subprocess."""
msg = self.call(["cowsay", self.options.msg], check_output=True)
fileStore.logToMaster(msg)
def main():
parser = ContainerArgumentParser()
parser.add_argument("-m", "--msg", default="Hello from the ocean!")
options = parser.parse_args()
job = WhaleSayJob(options=options)
ContainerJob.Runner.startToil(job, options)
if __name__ == "__main__":
main() If after checking this and confirming that |
update -- I just ran a quick test on this. So there is no |
Yes I noted that exact result above:
I'll just have to hope I get an answer back from the toil folk. |
toil_container version: 1.1.6
Python version: 3.9.4
Operating System: Ubuntu 20.10
Description
Currently the most useful entry point to
toil_container()
is thecall()
function ofContainerJob
. Unfortunately, it uses theoptions
dictionary, which is defined at initialization time. This means that:a) All options have to be known before the job actually runs. This is not always true, as bind mounts might be dynamic, and even the docker/singularity choice could be changed dynamically
b) We have to actually pass
options
every time we instantiate a job. This is verbose and not DRY.New feature
I propose that we:
containerJob.call
out into a static function such ascontainerCall()
.containerCall()
then takes the "options" (docker/singularity, mounts etc) as an argument, and does not rely onself.options
. This resolves my first point.containerJob
then usescontainerCall()
internally for backwards-compatibility (I have no intention to usecontainerJob
myself, though)containerCall()
pull its default options directly from the Toil config object, accessed throughself.jobStore.config
from any given job. These can still be overridden by arguments. This system means that, if you have--singularity
enabled, all jobs will automatically use singularity (by default) without having to passoptions
around (my second point above)The text was updated successfully, but these errors were encountered: