theskumar / theskumar/python-dotenv

Feature Request: Automatically copy `default.env` to `.env`

オープン
#644 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
8.9k
フォーク
581
PR マージ指標
30日以内にマージされた PR はありません

説明

When using python-dotenv or similar systems, I often find myself writing instructions for other developers that look like this:

pip install -r requirements.txt
cp default.env .env
python entrypoint.py

This is because I want to exclude .env from version control, since I expect individual devs to mess with it. But I want to supply a ready-to-go env file for developers.

But I don't like this. Ideally, I don't want the developers to even have to think about .env at all if it's not relevant to them. For example, the developer might be part of our frontend team and she doesn't know/care about how we configure backend services, she just needs a copy of this running on her dev box to do her actual job. Or maybe the person who's working on this is already in the middle of learning several other things, and the last thing they need is the additional cognitive overhead of having to think about how .env works.

The above instructions are sufficiently stereotypical that they could easily be implemented into the package, provided that nobody was concerned about the additional complexity, and or considered this too out-of-scope for the package.

Here's what we do: add one additional parameter to load_dotenv and class DotEnv called init_dotenv_path which defaults to None. Now, if we attempt to load the file, if dotenv_path is not undefined, but it is a file path which does not exist, and if init_dotenv_path is defined and is a file path which does exist, then we copy init_dotenv_path to dotenv_path and try to load the file again.

Now as a user, I would just write e.g.

load_dotenv(init_dotenv_path='default.env')

And now a developer doesn't even need to know about env files to run the project.

It might also be a good idea for the logger to emit "copying default.env to .env" if this code path was used (possibly only if set to verbose).

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Start with the load_dotenv function and DotEnv class named in the issue, then trace how dotenv_path is checked and loaded. Define the behavior for init_dotenv_path when the destination is missing, including the requested optional log message, and verify that the copied file is loaded afterward.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。