emeraldwalk / vscode-runonsave

Visual Studio Code extension to run commands whenever a file is saved.
Apache License 2.0
176 stars 57 forks source link

Support virtual environments (or multiple `cmd`s) #106

Open thomas-lochner opened 3 weeks ago

thomas-lochner commented 3 weeks ago

First I'd like to express my appreciation for the work done here. My team uses this extension in our everyday workflow and it is of great use to us. Thank you!

Is your feature request related to a problem? Please describe. I've attempted to look for info on virtual environments, but have not been able to find anything. We'd like to run a command for a package inside our virtual environment, but instead it seems we must have the package installed globally. Please let me know if this is not the case!

Describe the solution you'd like I'd like to see the capability to specify a location of a virtual environment to be used before running a command. Another solution might also be to allow the cmd parameter to be a list, instead of a single command string.

Additional context

Either:

"emeraldwalk.runonsave": {
        "commands": [
            {
                "cmd": "cmd-available-in-my-venv"
                "match": ".*\\.sql",
            }
        "venvActivateLocation": "~/.venv/bin/activate"
        ],
    },

Or:

"emeraldwalk.runonsave": {
        "commands": [
            {
                "cmds": [
                          "source ~/.venv/bin/activate",
                          "cmd-available-in-my-venv"
                        ],
                "match": ".*\\.sql",
            }
        ],
    },
bmingles commented 3 weeks ago

@thomas-lochner

Introducing Python specific settings is probably not something I would implement since the extension is intentionally broad purpose and shouldn't really be aware of language specific things. I'd need to think if there is a more general pattern to allow bootstrapping the a runtime env that could be leveraged by Python but also other similar things.

That said, have you tried activating the venv outside of vscode and then running vscode from that shell process? I'd expect it should run in whatever environment is in the parent process, but I haven't tested this.

bmingles commented 3 weeks ago

multiple commands instead only one command #79 has a similar request for multiple commands for a match, so I could see doing that as well.

thomas-lochner commented 3 weeks ago

@thomas-lochner

Introducing Python specific settings is probably not something I would implement since the extension is intentionally broad purpose and shouldn't really be aware of language specific things. I'd need to think if there is a more general pattern to allow bootstrapping the a runtime env that could be leveraged by Python but also other similar things.

That said, have you tried activating the venv outside of vscode and then running vscode from that shell process? I'd expect it should run in whatever environment is in the parent process, but I haven't tested this.

Thank you very much for the (very) quick response! Your points make perfect sense to me. I haven't tried activating the venv and spawning VSCode from there, however I would like to find a more "repeatable" solution for this. We have our whole team using the extension, and I have been able to get everyone set up successfully by just having them install the Python package outside of their virtual environment. I would like to make it easier to get newcomers set up with the extension however, with out instructing/guiding them to install the package globally. This is not a pressing matter by any means, but I thought it might be a nice feature for the extension to have down the line.

bmingles commented 3 weeks ago

I’ll chew on this one a bit. The value of the request makes sense to me, just need to think through how to best support it holistically

bmingles commented 1 week ago

@thomas-lochner Curious if you've tried something like:

"emeraldwalk.runonsave": {
      "commands": [
          {
              "cmd": "source ~/.venv/bin/activate && cmd-available-in-my-venv",
              "match": ".*\\.sql",
          }
      ],
},

I'm investigating options to run multiple commands in the same context. The simplest may just be to support a cmds array and then && concatenate things behind the scenes, but would love to know if this actually produces the desired result.