Add tutorial on how to use direnv with pixi
Direnv is a nice tool, that automatically runs a script defined in .envrc as soon as one is entering the directory. Zed supports it out of the box and vscode has an extension.
This is especially useful when pixi is used with languages other than Python. We should add a tutorial on how to set this up.
The Python VSCode extension has two modes when running things:
- running anything in debug mode. here, a shell command is being executed. as long as you ran
direnv allowbefore, it works even without the direnv extension - running tests invoke a subprocess directly without the extra shell. here, the direnv extension is needed
@baszalmstra please reopen
To use direnv with pixi is actually pretty useful. Just two line in .direnv file can do the trick:
watch_file pixi.lock
eval "$(pixi shell-hook)"
watch_file: simply looks for the changes, if made any reloads the variables accordingly. (See: https://github.com/direnv/direnv/blob/1418f217e5caf4af120b1a8482522a5c69edfd6e/stdlib.sh#L410C1-L410C48, no docs yet)
Even simplified with the VSCode extension:
- Go to command pallet > envrc > create a new .envrc file
- Now past those two line here.
Final result:
- Every time you open the project, the the pixi environment loads automatically!
I can open a PR in the docs if this is meaningful.
Yes, please @prady0t
We can close this as we already have the info in the docs: https://pixi.sh/latest/integration/third_party/direnv/