Combination of click
and switch
command in poe
#154
-
Hello @nat-n I am currently using Let's assume I have the following files in my
# p1.py
import click
@click.command()
@click.option(
"--foo",
type=str,
)
@click.option(
"--bar",
type=str,
)
def main(foo: str, bar: str) -> int:
s = f"pipeline ran with {foo=} and {bar=} ..."
print(s)
return 0
if __name__ == "__main__":
raise SystemExit(main())
and # p2.py
import click
@click.command()
@click.option(
"--baz",
type=str,
)
def main(baz: str) -> int:
s = f"pipeline ran with {baz=} ..."
print(s)
return 0
if __name__ == "__main__":
raise SystemExit(main()) So, normally if I wanna invoke the above pipelines in terminal, I would do:
Previously, I was using I am looking to figure out a way to propagate the # pyproject.toml
[tool.poe.tasks.run]
control.expr = "pipeline"
args = ["pipeline", "foo", "bar"]
[[tool.poe.tasks.run.switch]]
case = "p1"
# how to pass the args from terminal here ?
cmd = "python -m pipelines.p1"
So passing
Now, I dont know how can I have a Appreciate your thoughts .... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @amirhessam88, It sounds like maybe what you really want is two separate script tasks, rather an a single switch task? I haven't tested it but I suspect the following example will work as you intend because extra arguments will be set as [tool.poe.tasks.run-p1]
script = "pipelines.p1:main" Alternatively if you declare the arguments on the task then you'll benefit from the generated documentation in poe, though I'm not sure how this will interact with the the click decorated main function. [tool.poe.tasks.run-p2]
script = "pipelines.p2:main()"
args = ["baz"] If you primarily intend to run these pipeline tasks through poe then maybe you don't need click at all? Since poe supports all the basics in terms of declaring CLI arguments. One another potential benefit of having multiple tasks is that they'll work with autocomplete in most shells. That said if for some reason you really do want to use a switch task here, then I think you can just pass them in the command or script call like in either of the tasks in this example:
|
Beta Was this translation helpful? Give feedback.
Hey @amirhessam88,
I would expect using double quotes in the task definition to generally do what you want. The cmd task is intended to closely emulate bash syntax. There are some edge cases where it fails (because currently it relies on shlex which is too simplistic), but I'm actually working on a new parser at the moment to make it more robust and shell like.
Is there anything you can't achieve by defining the tasks like so?