I'd like to use direnv from within a Python tool I'm writing. So I want to be able to run something like:
subprocess.check_call(["direnv", "exec", ".", "my-command"])
So that I can allow the user to have made use of a .envrc file. The biggest blocker to this that I'm having is the need for direnv allow ..
Is there any way that direnv can be configured by the user to avoid the need for direnv allow . on each directory?
If the command was to fail, for example there is a typo on the .envrc. How would you display that to the user?
The best thing to do is to let the user run the command after inspecting the .envrc. Anything else would circumvent the purpose of that protection and put the user at risk.
Yeah thanks I can see why that's necessary.
New question - is there any way for me to neatly check from a script for whether direnv considers a .envrc to be allowed or not? I found direnv status, but ideally I'd like a command that returns 0 if the .envrc is allowed, and 1 otherwise. Does such a command exist?
This is so that I could prompt the user to approve the .envrc so my script can continue.
Looking at what the VSCode plugin does, it looks like they are parsing the output when it fails. Probably the most robust way though. https://github.com/rubymaniac/vscode-direnv/blob/014f12bb5295b6e6a37c7dda97d8bfc1ee8b40ab/src/main.ts#L36
I wouldn't be against adding a direnv status --json that contains that type of information.
related: https://github.com/direnv/direnv/issues/244#issuecomment-520487528
Most helpful comment
If the command was to fail, for example there is a typo on the
.envrc. How would you display that to the user?The best thing to do is to let the user run the command after inspecting the
.envrc. Anything else would circumvent the purpose of that protection and put the user at risk.