python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

Consider using bashlex

Open joaoe opened this issue 3 years ago • 0 comments

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 .env files. 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. .env includes the line source .envrc.

This would be a reimplementation of the module, so perhaps something for a major release ?

joaoe avatar May 12 '22 10:05 joaoe