hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Please, add env-file config option to import .env files

Open Ae-Mc opened this issue 11 months ago • 7 comments

I want to use env-file in environment section like so:

[envs.alembic]
env-file = ".env"

instead of using env-vars. It's useful for passing sensitive data that shouldn't be uploaded to vcs like passwords, secrets, etc.

Now I done it with wrapper-hack: src/utils/run_in_env.py:

from dotenv import load_dotenv
import subprocess
import sys

load_dotenv("./.env")
if len(sys.argv) > 2:
    args = sys.argv[1:]
    p = subprocess.Popen(args)
else:
    p = subprocess.Popen(sys.argv[1], shell=True)

exit(p.wait())

hatch.toml:

[envs.default.scripts]
run_in_env = "python src/utils/run_in_env.py"
[envs.alembic.scripts]
migrate = [
    "run_in_env alembic revision --autogenerate -m {args}",
    "run_in_env alembic upgrade head",
]

Ae-Mc avatar Mar 13 '24 17:03 Ae-Mc