Skip to content

"Keep your env.sample up to date when using django-environ", a tool and pre-commit hook.

License

Notifications You must be signed in to change notification settings

EnriqueSoria/update-django-environ-sample

Repository files navigation

update-django-environ-sample

Keep your env.sample up to date when using django-environ

Usage

  • Put every env var with its configuration in a ENV_DEFAULTS variable, in a separate python file named environment_defaults.py (exactly this file name)
# environment_defaults.py
ENV_DEFAULTS = dict(
    VARIABLE_WITH_DEFAULT_VALUE=(str, "default value"),
    VARIABLE_WITHOUT_DEFAULT_VALUE=str,
)
  • Instantiate Env with ENV_DEFAULTS on your Django settings file
# settings.py
from environ import Env
from environment_defaults import ENV_DEFAULTS

env = Env(**ENV_DEFAULTS)
  • And ensure you are accessing it using env("VAR_NAME") instead of env.str("VAR_NAME")
# settings.py
value = env("VARIABLE_WITH_DEFAULT_VALUE")
value = env("VARIABLE_WITHOUT_DEFAULT_VALUE")
  • Add this pre-commit so your env.sample gets updated on each commit
repos:
  - repo: https://github.com/EnriqueSoria/update-django-environ-sample
    rev: 'vX.X.X'  # Pick a release version
    hooks:
      - id: update-django-environ-sample
        args: [ "-p", "myapp/" ]  # Path where your environment_defaults.py is located

About

"Keep your env.sample up to date when using django-environ", a tool and pre-commit hook.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages