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

Support virtual environments (or multiple cmds) #106

Open
thomas-lochner opened this issue Oct 15, 2024 · 6 comments
Open

Support virtual environments (or multiple cmds) #106

thomas-lochner opened this issue Oct 15, 2024 · 6 comments

Comments

@thomas-lochner
Copy link

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
Copy link
Member

@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
Copy link
Member

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
Copy link
Author

@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
Copy link
Member

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
Copy link
Member

@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.

@thomas-lochner
Copy link
Author

thomas-lochner commented Nov 20, 2024

@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.

@bmingles Sorry this took me a bit to get to, but I did some testing, and this seems to be working! I hadn't considered doing that, and I'm currently having some trouble with my environment (completely unrelated to runonsave), but as far as I can tell this is giving the desired results. Thank you! I think this is a usable "workaround", you may close this issue if you'd like!

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

No branches or pull requests

2 participants