-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Amend `.gitignore`s for `.env`, and `.envrc` * Refactor environment variables in `.env`, `.secrets`, and `.envrc` To make `direnv` optional, move all variables from `.envrc` to `.env` in a `variable=value` format. Refactor `.secrets` to the same format. Use the `dotenv` and `dotenv_if_exists` `direnv` functions to load both `.env` and `.secrets`, as `direnv` will be optional, but still useful for folks who have it installed! * Update tests due to changes to `.envrc` and `.env` Also added `python-dotenv` as a requirement to enable this testing, and the use of `.env` and `.secrets` going forward. * Update README, structure/README and loading_environment_variabels for python-dotenv change * Update loading_environment_variables.md for python-dotenv * Fixing broken link in loading environment variable Fixing broken link in loading environment variables * Fix typo in documentation * Update requirments Add coverage[toml] to requirements * fix internal link in contributing * Address comments after peer review * Remove coverage[toml] from requirments * Add window make equivalent (#58) Add make.bat file and update flake8 pre-commit hook Co-authored-by: ESKYoung <[email protected]>
- Loading branch information
Showing
15 changed files
with
224 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,6 @@ celerybeat.pid | |
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ pre-commit | |
pytest | ||
pytest-mock | ||
pytest-xdist | ||
python-dotenv | ||
Sphinx | ||
toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Environment variables go here, and can be read in by Python using the `python-dotenv` | ||
# package, and `os.getenv`: | ||
# | ||
# ------------------------------------------------------------------------------------ | ||
# from dotenv import load_dotenv | ||
# import os | ||
# | ||
# # Load the environment variables from the `.env` file, overriding any system | ||
# # environment variables | ||
# load_dotenv(override=True) | ||
# | ||
# # Load secrets from the `.secrets` file, overriding any system environment variables | ||
# load_dotenv(".secrets", override=True) | ||
# | ||
# # Example variable | ||
# EXAMPLE_VARIABLE = os.getenv("EXAMPLE_VARIABLE") | ||
# ------------------------------------------------------------------------------------ | ||
# | ||
# For folder/file path environment variables, use relative paths. | ||
# | ||
# DO NOT STORE SECRETS HERE - this file is version-controlled! You should store secrets | ||
# in the untracked `.secrets` file. | ||
|
||
|
||
# Add environment variables for the `data` directories | ||
DIR_DATA=./data | ||
DIR_DATA_EXTERNAL=./data/external | ||
DIR_DATA_RAW=./data/raw | ||
DIR_DATA_INTERIM=./data/interim | ||
DIR_DATA_PROCESSED=./data/processed | ||
|
||
# Add environment variables for the `docs` directory | ||
DIR_DOCS=./docs | ||
|
||
# Add environment variables for the `notebooks` directory | ||
DIR_NOTEBOOKS=./notebooks | ||
|
||
# Add environment variables for the `outputs` directory | ||
DIR_OUTPUTS=./outputs | ||
|
||
# Add environment variables for the `src` directories | ||
DIR_SRC=./src | ||
DIR_SRC_MAKE_DATA=./src/make_data | ||
DIR_SRC_MAKE_FEATURES=./src/make_features | ||
DIR_SRC_MAKE_MODELS=./src/make_models | ||
DIR_SRC_MAKE_VISUALISATIONS=./src/make_visualisations | ||
DIR_SRC_UTILS=./src/utils | ||
|
||
# Add environment variables for the `tests` directory | ||
DIR_TESTS=./tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
# Environment variables go here, and can be read in by Python using `os.getenv`: | ||
# Orchestration file to load environment variables from the `.env` and `.secrets` files. | ||
# | ||
# -------------------------------------------------------- | ||
# Only used by systems with `direnv` (https://direnv.net/) installed. Environment | ||
# variables can be read in by Python using `os.getenv` _without_ using `python-dotenv`: | ||
# | ||
# ------------------------------------------------------------------------------------ | ||
# import os | ||
# | ||
# # Example variable | ||
# EXAMPLE_VARIABLE = os.getenv("EXAMPLE_VARIABLE") | ||
# -------------------------------------------------------- | ||
# | ||
# To ensure the `sed` command below works correctly, make sure all file paths in environment variables are absolute | ||
# (recommended), or are relative paths using other environment variables (works for Python users only). Environment | ||
# variable names are expected to contain letters, numbers or underscores only. | ||
# ------------------------------------------------------------------------------------ | ||
# | ||
# DO NOT STORE SECRETS HERE - this file is version-controlled! You should store secrets in a `.secrets` file, which is | ||
# not version-controlled - this can then be sourced here, using `source_env ".secrets"`. | ||
|
||
# Extract the variables to `.env` if required. Note `.env` is NOT version-controlled, so `.secrets` will not be | ||
# committed | ||
sed -n 's/^export \(.*\)$/\1/p' .envrc .secrets | sed -e 's?$(pwd)?'"$(pwd)"'?g' | sed -e 's?$\([a-zA-Z0-9_]\{1,\}\)?${\1}?g' > .env | ||
# DO NOT STORE SECRETS HERE - this file is version-controlled! You should store secrets | ||
# in the untracked `.secrets` file. This is loaded here using the `dotenv_if_exists` | ||
# command. | ||
|
||
# Add the working directory to `PYTHONPATH`; allows Jupyter notebooks in the `notebooks` folder to import `src` | ||
# Add the working directory to `PYTHONPATH`; allows Jupyter notebooks in the | ||
# `notebooks` folder to import `src` | ||
export PYTHONPATH="$PYTHONPATH:$(pwd)" | ||
|
||
# Import secrets from an untracked file `.secrets` | ||
source_env ".secrets" | ||
|
||
# Add environment variables for the `data` directories | ||
export DIR_DATA=$(pwd)/data | ||
export DIR_DATA_EXTERNAL=$(pwd)/data/external | ||
export DIR_DATA_RAW=$(pwd)/data/raw | ||
export DIR_DATA_INTERIM=$(pwd)/data/interim | ||
export DIR_DATA_PROCESSED=$(pwd)/data/processed | ||
|
||
# Add environment variables for the `docs` directory | ||
export DIR_DOCS=$(pwd)/docs | ||
|
||
# Add environment variables for the `notebooks` directory | ||
export DIR_NOTEBOOKS=$(pwd)/notebooks | ||
|
||
# Add environment variables for the `outputs` directory | ||
export DIR_OUTPUTS=$(pwd)/outputs | ||
|
||
# Add environment variables for the `src` directories | ||
export DIR_SRC=$(pwd)/src | ||
export DIR_SRC_MAKE_DATA=$(pwd)/src/make_data | ||
export DIR_SRC_MAKE_FEATURES=$(pwd)/src/make_features | ||
export DIR_SRC_MAKE_MODELS=$(pwd)/src/make_models | ||
export DIR_SRC_MAKE_VISUALISATIONS=$(pwd)/src/make_visualisations | ||
export DIR_SRC_UTILS=$(pwd)/src/utils | ||
|
||
# Add environment variables for the `tests` directory | ||
export DIR_TESTS=$(pwd)/tests | ||
# Load the `.env` file, and `.secrets` (if it exists) | ||
dotenv .env | ||
dotenv_if_exists .secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,6 @@ celerybeat.pid | |
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
# Secrets and credentials should be stored here as environmental variables. For example: | ||
# | ||
# # Google Cloud authentication credentials | ||
# export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials.json" | ||
# GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json | ||
# | ||
# These environment variables can then be read in by Python using `os.getenv`: | ||
# These environment variables can then be read in by Python using the `python-dotenv` | ||
# package, and `os.getenv`: | ||
# | ||
# -------------------------------------------------------- | ||
# ------------------------------------------------------------------------------------ | ||
# from dotenv import load_dotenv | ||
# import os | ||
# | ||
# # Load secrets from the `.secrets` file, overriding any system environment variables | ||
# load_dotenv(".secrets", override=True) | ||
# | ||
# # Google Cloud authentication credentials | ||
# GOOGLE_APPLICATION_CREDENTIALS = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") | ||
# -------------------------------------------------------- | ||
# ------------------------------------------------------------------------------------ | ||
# | ||
# This file is NOT version-controlled! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.