-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
65 lines (48 loc) · 1.84 KB
/
Copy pathrun.py
File metadata and controls
65 lines (48 loc) · 1.84 KB
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
61
62
63
64
65
import atexit
import os
import subprocess
from dotenv import load_dotenv
load_dotenv()
subprocesses = []
PORT = os.environ.get("PIGGY_PORT", 5001)
@atexit.register
def cleanup():
print("\nSo long and thanks for all the fish!")
for p in subprocesses:
p.terminate()
p.wait()
def checkout_branch():
branch = os.environ.get("PIGGYBANK_BRANCH", "test-output")
print("Checking out branch: " + branch)
if "piggybank" in branch:
cmd = f"cd piggybank && git fetch && git checkout {branch}"
else:
cmd = f"cd piggybank && git stash && git fetch && git checkout {branch} && git pull"
subprocess.run(cmd, shell=True, check=True)
if __name__ == "__main__":
# Debug
import logging
# Reduce the amount of logging from werkzeug
log = logging.getLogger("werkzeug")
log.setLevel(logging.ERROR)
# Set the environment variables for testing
os.environ["USE_CACHE"] = "0"
os.environ["FLASK_DEBUG"] = "1"
# Run these once on the first run
if os.environ.get("WERKZEUG_RUN_MAIN") != "true":
# This code will run only once, not in the reloaded processes
checkout_branch()
subprocesses.append(subprocess.Popen("npx livereload piggy,piggybank -e html,css,js,md", shell=True))
print(f"Houston, we have lift-off! (http://localhost:{PORT})")
# Import after setting the environment variables for testing
from piggy.app import create_app
from piggy.devtools import inject_devtools
app = create_app(debug=os.environ.get("FLASK_DEBUG", False) == "1")
inject_devtools(app)
app.run(port=PORT)
else:
# Production
from piggy.app import create_app
# TODO: Re-enable (requires branch to be published) (or a env to pass the branch with a PAT)
# checkout_branch("output")
app = create_app(debug=os.environ.get("FLASK_DEBUG", False) == "1")