示例#1
0
    def test_with_input(self):
        r = self.runner.clone()
        r.with_input("file:///tmp/input", "/mnt/input")
        r.with_input("file:///tmp/input2", "./input2")
        expected = [
            tes.Input(
                url="file:///tmp/input",
                path="/mnt/input",
                type="FILE"
            ),
            tes.Input(
                url="file:///tmp/input2",
                path="/tmp/tesseract/input2",
                type="FILE"
            )
        ]
        print("ACTUAL", r.input_files)
        print("EXPECTED", expected)
        self.assertEqual(
            r.input_files,
            expected
        )

        with self.assertRaises(ValueError):
            self.runner.with_input("fake://tmp/input", "/mnt/input")

        with self.assertRaises(ValueError):
            self.runner.with_input("file://tmp/input", "../input")
示例#2
0
 def create_input(self, name, d):
     if "contents" in d:
         return tes.Input(name=name,
                          description="cwl_input:%s" % (name),
                          path=d["path"],
                          content=d["contents"],
                          type=d["class"].upper())
     return tes.Input(name=name,
                      description="cwl_input:%s" % (name),
                      url=d["location"],
                      path=d["path"],
                      type=d["class"].upper())
示例#3
0
 def create_input_parameter(self, key, value):
     if "contents" in value:
         return tes.Input(name=key,
                          description="cwl_input:%s" % (key),
                          path=value["path"],
                          contents=value["contents"],
                          type=value["class"].upper())
     else:
         return tes.Input(name=key,
                          description="cwl_input:%s" % (key),
                          url=value["location"],
                          path=value["path"],
                          type=value["class"].upper())
示例#4
0
文件: tes.py 项目: psafont/cwl-tes
    def parse_listing(self, listing, inputs):
        for item in listing:

            if "writable" in item:
                raise UnsupportedRequirement(
                    "The TES spec does not allow for writable inputs")

            if "contents" in item:
                loc = self.fs_access.join(self.tmpdir, item["basename"])
                with self.fs_access.open(loc, "wb") as gen:
                    gen.write(item["contents"])
            else:
                loc = item["location"]

            parameter = tes.Input(
                name=item["basename"],
                description="InitialWorkDirRequirement:cwl_input:%s" %
                (item["basename"]),
                url=file_uri(loc),
                path=self.fs_access.join(self.docker_workdir,
                                         item["basename"]),
                type=item["class"].upper())
            inputs.append(parameter)

        return inputs
示例#5
0
    def with_input(self, url, path):
        u = urlparse(process_url(url))
        if u.scheme not in self.file_store.supported:
            raise ValueError("Unsupported scheme - must be one of %s" %
                             (self.file_store.supported))
        if u.scheme == "file" and self.file_store.scheme != "file":
            raise ValueError("please upload your input file to the file store")

        u = urlparse(path)
        if u.scheme not in ["file", ""]:
            raise ValueError("runtime path must be defined as a local path")
        if u.scheme == "file":
            path = os.path.join(u.netloc, u.path)

        if path.startswith("./"):
            pass
        elif not os.path.isabs(path):
            raise ValueError(
                "runtime path must be an absolute path or start with './'")

        self.input_files.append(
            tes.Input(path=os.path.join("/tmp/tesseract",
                                        re.sub("^./", "", path)),
                      url=url,
                      type="FILE"))
示例#6
0
    def _create_task_msg(self, input_cp_url, output_cp_url):
        runner = pkg_resources.resource_string(__name__, "resources/runner.py")
        if isinstance(runner, bytes):
            runner = runner.decode("utf8")

        cmd_install_reqs = "pip install %s" % (" ".join(self.libraries))
        cmd_tesseract = "python tesseract.py func.pickle"

        if len(self.libraries) == 0:
            cmd = cmd_tesseract
        else:
            cmd = cmd_install_reqs + " && " + cmd_tesseract

        task = tes.Task(name="tesseract remote execution",
                        inputs=self.input_files + [
                            tes.Input(name="pickled function",
                                      url=input_cp_url,
                                      path="/tmp/tesseract/func.pickle",
                                      type="FILE"),
                            tes.Input(name="tesseract runner script",
                                      path="/tmp/tesseract/tesseract.py",
                                      type="FILE",
                                      content=str(runner))
                        ],
                        outputs=self.output_files + [
                            tes.Output(name="pickled result",
                                       url=output_cp_url,
                                       path="/tmp/tesseract/result.pickle",
                                       type="FILE")
                        ],
                        resources=tes.Resources(cpu_cores=self.cpu_cores,
                                                ram_gb=self.ram_gb,
                                                disk_gb=self.disk_gb),
                        executors=[
                            tes.Executor(image=self.docker,
                                         command=["sh", "-c", cmd],
                                         stdout="/tmp/tesseract/stdout",
                                         stderr="/tmp/tesseract/stderr",
                                         workdir="/tmp/tesseract")
                        ])
        return task
示例#7
0
文件: tes.py 项目: tmooney/toil
    def _mount_local_path_if_possible(self, local_path: str,
                                      container_path: str) -> None:
        """
        Internal function. Should not be called outside this class.

        If a local path is somewhere the server thinks it can access, mount it
        into all the tasks.
        """
        # TODO: We aren't going to work well with linked imports if we're mounting the job store into the container...

        path_url = 'file://' + os.path.abspath(local_path)
        if os.path.exists(local_path) and self._server_can_mount(path_url):
            # We can access this file from the server. Probably.
            self.mounts.append(
                tes.Input(
                    url=path_url,
                    path=container_path,
                    type="DIRECTORY" if os.path.isdir(local_path) else "FILE"))