Skip to content

Add option to reuse shell #1115

@richard-hajek

Description

@richard-hajek

I think it would be beneficial to allow for execution of an entire task in a single shell.

Motivation

It is currently very difficult to use Python's venvs or conda, due to the shell being reset on each command. The recommended way is to use absolute paths inside the venv, such as venv/bin/python instead of source venv/bin/activate;python. This however increasing the friction for newcomers and not all problems of this kind have similar solutions.

My current Taskfile, looks like this:

[...]
tasks:
  build:
    cmds:
      - mamba env create -f environment.yaml || true
      - mamba env update -f environment.yaml --prune
      - bash -c "
        source conda_init;
        mamba activate csidrl;
        poetry install;
        cd lib/SATNet;
        python setup.py install;
        "

Which is ugly and complicated. This approach also complicates cross-platform implementations.

There are other workarounds, such as in #512. There would be other uses of this feature, for example resolving #204.

Proposal

For a task, add subshell boolean. This boolean would be by default true, ensuring compatibility. On false, this option would make go-task invoke all cmds in a single mvdan.cc/sh/v3/interp. When false, this option would also cause all task: cmds to run in the same interp.

The unclear question is a treatment of deps. The current behavior would see them running in different shells, which may produce some confusion. The consistent behavior with the rest of this proposal would however sacrifice concurrency for simplicity and make deps run linearly after each other in the same shell (when subshell: false only). This behavior would also resolve #204. Neither of these options would result in consistent behavior throughout the go-task though.

Advantages

My humble opinion

I believe that each of the advantages by themselves would be a strong-enough for this feature to be accepted, but there are some issues.

Even though this feature may simplify some workflows, the added complexity may not be worth it. The code base as I understand it also wildly doesn't support this, so it would be a major change. I am willing to take a crack at it though.

Neither of these options would result in consistent behavior throughout the go-task though.

In my personal opinion, both options are better than the current behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions