forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
60 lines (46 loc) · 1.79 KB
/
Tiltfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def dotenv(fn=".env", verbose=False, showValues=False):
# Check if file exists
if not os.path.exists(fn):
warn("Environment variables file not found: '%s'" % fn)
return
if verbose:
print("Loading environment variables from file: '%s'" % fn)
# Read file
f = read_file(fn)
# Split lines
lines = str(f).splitlines()
# Parse lines
for lineNumber in range(len(lines)):
# Set line by line number
line = lines[lineNumber]
# Skip comments
if line.startswith("#"):
continue # skip comments
# TODO: add support for comments at the end of the line
# Split key and value
v = line.split(
"=", # sep (separator)
1 # maxsplit (maximum number of splits to do)
)
# Check if key and value are present
if len(v) < 2:
if len(line) > 0:
fail("Invalid format for dotenv file: '%s' in '%s:%s'" % (line, fn, lineNumber+1))
continue # skip empty lines
# Remove whitespace around the varible name
varName = v[0].strip()
# Remove whitespace around the varible value
varValue = v[1].strip()
# if varValue starts and ends with quotes, remove them
if varValue.startswith('"') and varValue.endswith('"'):
varValue = varValue[1:-1]
elif varValue.startswith("'") and varValue.endswith("'"):
varValue = varValue[1:-1]
if verbose:
# Print if key is valid
if showValues:
print("Loading environment variable: %s=%s" % (varName, varValue))
else:
print("Loading environment variable: %s" % (varName))
# Set environment variable
os.putenv(varName, varValue)