Skip to content
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

Feature Request: wraps_task works from the command line #103

Open
ktthross opened this issue Sep 12, 2024 · 2 comments
Open

Feature Request: wraps_task works from the command line #103

ktthross opened this issue Sep 12, 2024 · 2 comments

Comments

@ktthross
Copy link

Running on:

(challenger_deep) ubuntu@ip-10-65-199-196:~/example$ redun --version
0.22.0

I am sharing two files. The first is the simplest wraps_task I can think of.

from redun.task import wraps_task

def simple_wrap():
    @wraps_task()
    def _wrapper(inner_task):
        def wrapper(*task_args, **task_kwargs):
            return inner_task.func(*task_args, **task_kwargs)
        return wrapper
    return _wrapper

Next is three functions which I intend to call as the first function redun executes.

from simple_wrap import simple_wrap
from redun import task

redun_namespace = "example.command_line_task"

@simple_wrap()
def cli_task(arg):
    return arg

@simple_wrap()
def call_cli_task():
    return cli_task("foo")

@task()
def non_wrapped(arg):
    return arg

When I run the non_wrapped task I get the expected behavior

(challenger_deep) ubuntu@ip-10-65-199-196:~/example$ redun run --no-cache command_line_task.py non_wrapped --arg foo
[redun] redun :: version 0.22.0
[redun] config dir: /home/ubuntu/example/.redun
[redun] Start Execution 57295ef6-45ef-4b41-859f-e445e29dc929:  redun run --no-cache command_line_task.py non_wrapped --arg foo
[redun] Run    Job b1b6501d:  example.command_line_task.non_wrapped(arg='foo') on default
[redun] 
[redun] | JOB STATUS 2024/09/12 17:33:30
[redun] | TASK                                  PENDING RUNNING  FAILED  CACHED    DONE   TOTAL
[redun] | 
[redun] | ALL                                         0       0       0       0       1       1
[redun] | example.command_line_task.non_wrapped       0       0       0       0       1       1
[redun] 
[redun] 
[redun] Execution duration: 0.02 seconds
'foo'

When I run the wrapped cli_task I get an error when redun trys to parse the input arguments

(challenger_deep) ubuntu@ip-10-65-199-196:~/example$ redun run command_line_task.py cli_task --arg foo
[redun] redun :: version 0.22.0
[redun] config dir: /home/ubuntu/example/.redun
usage: example.command_line_task.cli_task [-h] [--task-args TASK_ARGS] [--task-kwargs TASK_KWARGS] {help,info} ...
example.command_line_task.cli_task: error: argument {help,info}: invalid choice: 'foo' (choose from 'help', 'info')

When I have a task with no arguments to run the task it works as expected but I can't ever pass arguments into the task.

(challenger_deep) ubuntu@ip-10-65-199-196:~/example$ redun run --no-cache command_line_task.py call_cli_task
[redun] redun :: version 0.22.0
[redun] config dir: /home/ubuntu/example/.redun
[redun] Start Execution f93c9d9e-3f0e-4c38-b3eb-c5279084955f:  redun run --no-cache command_line_task.py call_cli_task
[redun] Run    Job d10d3376:  example.command_line_task.call_cli_task(task_args=<class 'inspect._empty'>, task_kwargs=<class 'inspect._empty'>) on default
[redun] Run    Job 9e664195:  example.command_line_task.cli_task(task_args='foo', task_kwargs=<class 'inspect._empty'>) on default
[redun] 
[redun] | JOB STATUS 2024/09/12 17:35:37
[redun] | TASK                                    PENDING RUNNING  FAILED  CACHED    DONE   TOTAL
[redun] | 
[redun] | ALL                                           0       0       0       0       2       2
[redun] | example.command_line_task.call_cli_task       0       0       0       0       1       1
[redun] | example.command_line_task.cli_task            0       0       0       0       1       1
[redun] 
[redun] 
[redun] Execution duration: 0.03 seconds
'foo'

I recognize that the solution to this is to specially write command line tasks which are not wrapped. It would be really cool if I could call a wrapped task from the command line however.

Thanks!

@mattrasmus
Copy link
Collaborator

Thanks for posting this @ktthross. This is a very reasonable request. We're thinking through a possible way for the outer task to inherit the signature of the inner task. This will then allow the CLI invoking (which uses the task signature to auto-create the CLI options) to work as expected.

@ktthross
Copy link
Author

Thanks for taking at look at this. If there is anything I can do to help please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants