Feature request: custom merge logic or variables
還沒有人認領這個 Issue。
評估
研究方向
Start with the dotenv methods that accept the existing override parameter and trace how values from .env are applied to the environment. Define how a variable-to-callable API would coexist with current override and non-override behavior, using the LD_LIBRARY_PATH example as the target case. Done means custom merge logic can extend and normalize a colon-separated value without changing existing defaults.
由索引模型根據 Issue 內容生成。
描述
Hello, this is a feature request for enabling custom merge logic when the environment variables are updated with values read from .env file.
My use case is that I would like to append an element to a colon-separated list of paths. Typical colon-separated environment variables are PATH or LD_LIBRARY_PATH. So the reading of the .env file should neither override, nor leave the original environment variables, instead it should extend the list.
Currently I use the following pseudo-code for this:
cfg = dotenv_values()
path_elems = []
if 'LD_LIBRARY_PATH' in os.environ:
path_elems.extend(os.environ['LD_LIBRARY_PATH'].split(':'))
if 'LD_LIBRARY_PATH' in cfg:
path_elems.append(cfg['LD_LIBRARY_PATH'])
path_elems = list(OrderedDict.fromkeys(path_elems)) # remove duplicates
path = ':'.join(path_elems)
path = path.replace('::', ':') # remove empty elements
os.environ['LD_LIBRARY_PATH'] = path
I think such logic could be integrated into the dotenv library. This would require changing the API: instead of / apart the override parameter the dotenv methods could take a variable name -> callable dictionary, where the callable would take as parameters the current and the new value and handle the merge logic for the specified variable. Senseful default behavior could be configured to simulate the current override/not override functionality.
- 主要語言
- Python
- 星號
- 8.9k
- 分支
- 581
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
theskumar/python-dotenv 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
theskumar/python-dotenv#699 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 35/100
theskumar/python-dotenv#697 ·
-
難度 5/5 一週以上 新手友好度 28/100
theskumar/python-dotenv#693 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#683 · 4 則留言 ·
-
難度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#644 · 2 則留言 ·
查看 theskumar/python-dotenv 的全部 Issue
相似的 Issue
-
area/auth bug comp/agent P3 platform/discord type/security
難度 2/5 1-3 小時 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
難度 2/5 1-3 小時 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未關閉CI
難度 2/5 1-3 小時 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難度 2/5 1-3 小時 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難度 2/5 1-3 小時 新手友好度 88/100