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

Option to specify a custom interpreter #1292

Closed
aucampia opened this issue Aug 2, 2023 · 2 comments
Closed

Option to specify a custom interpreter #1292

aucampia opened this issue Aug 2, 2023 · 2 comments
Labels
state: duplicate Duplicates another issue.

Comments

@aucampia
Copy link

aucampia commented Aug 2, 2023

I have had a couple of situations where I wanted to run commands with a different interpreter than mvdan.cc/sh/v3/cmd/gosh. Two examples are:

Small python snippets that I want executed with the python interpreter:

tasks:
  _rimraf:
    # This task is a utility task for recursively removing directories, it is
    # similar to rm -rf but not identical and it should work wherever there is
    # a python interpreter. The name is inspired by
    # <https://www.npmjs.com/package/rimraf>.
    - cmd: |
        {{.PYTHON}} -c '
        from pathlib import Path;
        import sys, shutil;
        for path in sys.argv[1:]:
          if Path(path).exists():
            sys.stderr.write(f"removing {path}\n")
            shutil.rmtree(path, ignore_errors=True)
        ' {{.RIMRAF_TARGET}}

Commands I want to execute on a LXD container:

tasks:
  nomad:clean:jobs:
    desc: Delete all Nomad jobs
    cmds:
      - cmd: lxc exec -t kron-cluster-sandbox -- bash -l -c {{ .CMD | shellQuote }}
        ignore_error: true
    vars:
      CMD: |
        set -x -euo pipefail

        nomad job inspect -json | jq -r ".[].ID" | xargs -I{} -t nomad job stop -yes {}
        nomad system gc

I feel these two cases would be a bit more elegant if I could specify the interpreter separately from the command without having to pass the command as either an environment variable or a shell escaped string.

This is a rather minor request though, clearly there are serviceable workarounds that get the job done, but having something similar to the interpreter setting from poethepoet may help.

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 2, 2023
@Hades32
Copy link

Hades32 commented Aug 4, 2023

this would also help with using task on Windows so I could simply force it to use Bash instead of PowerShell

@pd93 pd93 added proposal and removed state: needs triage Waiting to be triaged by a maintainer. labels Aug 4, 2023
@pd93
Copy link
Member

pd93 commented Aug 4, 2023

@aucampia Thanks for opening this. I couldn't find the issue when you asked on Discord, but now that I've had more time to search, I think this is a duplicate of #448. I'm going to post my response over there and close this. If you and @Hades32 could add a 👍 and any comments over there too, that would help keep everything together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: duplicate Duplicates another issue.
Projects
None yet
Development

No branches or pull requests

4 participants