python-dotenv
python-dotenv copied to clipboard
Consider using bashlex
Hi.
I've been using .env files for a while, namely to setup variable and load python virtual environments, also with stuff like autoenv. This means that my .env files have bash code, like if statements, sourcing other scripts, commands, functions.
dotenvs limited reader code just uses a couple regexs that can't handle much more than export statements. And this is something some people might not be expecting.
Suggestion:
- use bashlex to parse the
.envfiles. https://github.com/idank/bashlex - gather variables defined only at the top level
- implement variable substitution (quite easy to implement) e.g.
${VARNAME:-fallback} - recursively source other sourced scripts, e.g.
.envincludes the linesource .envrc.
This would be a reimplementation of the module, so perhaps something for a major release ?