PMCC-BioinformaticsCore / janis-core

Core python modules for Janis Pipeline workflow assistant
GNU General Public License v3.0
4 stars 9 forks source link

returning a list fails #33

Closed drtconway closed 4 years ago

drtconway commented 4 years ago

Tool:

from typing import Any, Dict, List
from janis_core import PythonTool, ToolInput, TOutput, ToolMetadata
from janis_core import Array, Int, String

class Many(PythonTool):
    @staticmethod
    def code_block(count: Int, prefix: String) -> Dict[str, Any]:
        return {'out', [f'{prefix}.{i}' for i in range(count)]}

    def outputs(self) -> List[TOutput]:
        return [TOutput("out", Array(str))]

    def id(self) -> str:
        return "Many"

    def version(self):
        return "v0.1.0"

    def friendly_name(self):
        return "return an array of strings"

Invocation:

$ janis run -o foo many.py --count 10 --prefix wibble

Error:

$ cat foo/janis/execution/Many/30295bce-e4e5-4edb-a710-122a88beafa3/call-Many/execution/stderr
Traceback (most recent call last):
  File "Many-script.py", line 30, in <module>
    result = code_block(count=args.count, prefix=args.prefix)
  File "Many-script.py", line 25, in code_block
    return {'out', [f'{prefix}.{i}' for i in range(count)]}
TypeError: unhashable type: 'list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Many-script.py", line 32, in <module>
    except e:
NameError: name 'e' is not defined
illusional commented 4 years ago

Hi Tom, you've got a subtle syntax error, and I think we could probably do more to guide this in the right direction. Your code-block is returning a python set, and not a dictionary, you'll want a : instead of a ,:

return {'out': [f'{prefix}.{i}' for i in range(count)]}
drtconway commented 4 years ago

Lol. My bad. Thanks!

On Mon, 29 Jun 2020 at 12:45, Michael Franklin notifications@github.com wrote:

Hi Tom, you've got a subtle syntax error, and I think we could probably do more to guide this in the right direction. Your code-block is returning a python set, and not a dictionary, you'll want a : instead of a ,:

return {'out': [f'{prefix}.{i}' for i in range(count)]}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PMCC-BioinformaticsCore/janis-core/issues/33#issuecomment-650872015, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKBNUPDUCJSU3KAMRVKBTLRY756PANCNFSM4OK2M7BQ .

-- Thomas Conway drtomc@gmail.com My friends, love is better than anger. Hope is better than fear. Optimism is better than despair. So let us be loving, hopeful and optimistic. And we'll change the world. - Jack Layton