theskumar / theskumar/python-dotenv

Consider using bashlex

Open
#403 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.9k
Forks
581
PR merge metrics
No merged PRs in 30d

Description

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 ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue proposes replacing dotenv's limited reader with bashlex. Start by locating the existing .env reader and reviewing bashlex's parsing model; done means top-level variables, ${VARNAME:-fallback} substitution, and recursive source handling work for files such as .env sourcing .envrc, with the scope suitable for a major release.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, python
Domain
devops, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.