-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.py
More file actions
18 lines (15 loc) · 714 Bytes
/
helpers.py
File metadata and controls
18 lines (15 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re
# Convert .env data into python dict structure which can be used to set environment variables as os.environ.update(dict)
#
# Based on https://stackoverflow.com/questions/40216311/reading-in-environment-variables-from-an-environment-file
# @see https://docs.python.org/3/library/re.html
# @see https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions
def dot_env_vars(file_path):
reg = re.compile(r"^([^=]+)\=(.*)$|$")
with open(file_path, 'r') as file:
vars_dict = dict(
tuple(reg.findall(line))[0]
for line in file.readlines()
if not line.startswith('#') and (not len(line.strip()) == 0)
)
return vars_dict