Skip to content

Allow Environment Shims #19132

@jamesstidard

Description

@jamesstidard

Hi,

There are command line tools that have commands to prepare the shell environment before executing commands. I'm not sure if there's a name for this, but some examples are things like pipenv run, op run, and asdf env.

The main one I'm interested in is 1Password's op run because I'd like to be able to remove the sensitive environment variables I have from my .env files in my projects.

Here's how you might run a pipenv Python project outside of VSCode at the moment using op run

# .env
PYTHONPATH=.
SECRET=op://development/my-service/password
# main.py
import os

print("SECRET", os.environ["SECRET"])
$ pipenv run op run -- python main.py
Loading .env environment variables...
SECRET <concealed by 1Password>

Here pipenv run loads variables found in the projects .env and shims the virtual environment python into the PATH. op run -- then replaces any environment variables with the op:// paths with secrets from the password manager (authenticating their access). python main.py is then executed in this shell environment.

I currently can't see a way of integrating this into my vscode workflow. I've tried:

Would love to have a way to work around this, either with a different method from above, or from dimming down the sanity checks vscode-python does on the "python" argument. Or even better first class support for these kind of environment shims, something complimentary to "python.env" and "python.envFile":

// settings.json
{
    "python.envCommand": ["op", "run", "--"],
}

Could maybe accept a list of commands, if you want to stack environments:

// settings.json
{
    "python.envCommand": [
        ["pipenv", "run"],
        ["op", "run", "--"],
        ["asdf", "run"],
    ],
}

Anyway, quite a niche feature request, I know. But would love to be able to have the ability to do this, and happy to put in the grunt work of implementation, if I can be pointed in the right direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-terminalcommunity askFeature request that the community expressed interest infeature-requestRequest for new features or functionalityinfo-neededIssue requires more information from posterneeds proposalNeed to make some design decisions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions