https://github.com/enriquesoria/update-django-environ-sample
"Keep your env.sample up to date when using django-environ", a tool and pre-commit hook.
https://github.com/enriquesoria/update-django-environ-sample
django django-environ env pre-commit pre-commit-hook
Last synced: about 1 month ago
JSON representation
"Keep your env.sample up to date when using django-environ", a tool and pre-commit hook.
- Host: GitHub
- URL: https://github.com/enriquesoria/update-django-environ-sample
- Owner: EnriqueSoria
- License: mit
- Created: 2022-11-01T19:18:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-02T08:08:55.000Z (over 2 years ago)
- Last Synced: 2025-04-12T23:53:25.978Z (about 1 month ago)
- Topics: django, django-environ, env, pre-commit, pre-commit-hook
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# update-django-environ-sample
Keep your env.sample up to date when using [django-environ](https://github.com/joke2k/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)
```python
# 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
```python
# settings.py
from environ import Env
from environment_defaults import ENV_DEFAULTSenv = Env(**ENV_DEFAULTS)
```- And ensure you are accessing it using `env("VAR_NAME")` instead of `env.str("VAR_NAME")`
```python
# 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
```yaml
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
```