-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.py
More file actions
executable file
·75 lines (67 loc) · 3.08 KB
/
Copy pathplay.py
File metadata and controls
executable file
·75 lines (67 loc) · 3.08 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
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""Launcher for the Scorched Earth Python port.
Run from this directory: python play.py (windowed)
python play.py --fullscreen
If pygame is not in the current interpreter, this re-execs into the project
venv (../.venv) automatically.
"""
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
def _ensure_deps():
try:
import pygame # noqa: F401
import numpy # noqa: F401
return
except ImportError:
pass
# not available in this interpreter -> try the project venv and re-exec.
# A venv is identified by sys.prefix (its bin/python may symlink to the
# system binary, so comparing executable paths is unreliable).
venv_dir = os.path.normpath(os.path.join(HERE, "..", ".venv"))
venv_py = os.path.join(venv_dir, "bin", "python")
in_venv = os.path.realpath(sys.prefix) == os.path.realpath(venv_dir)
if os.path.exists(venv_py) and not in_venv:
os.execv(venv_py, [venv_py, os.path.abspath(__file__)] + sys.argv[1:])
sys.stderr.write(
"pygame/numpy not found in this Python.\n"
" Run with the project venv: ../.venv/bin/python play.py\n"
" or via the launcher: ./scorch.sh\n"
" or install deps: pip install -r requirements.txt\n")
sys.exit(1)
_ensure_deps()
from scorch.main import main
if __name__ == "__main__":
import traceback
try:
main()
except Exception:
# Top-level boundary (DTM 6.3b): persist the full traceback to crash.log
# for post-mortem, then re-raise so the failure still surfaces (non-zero
# exit + stderr trace). This is NOT suppression: the exception is
# re-raised unchanged. SystemExit/KeyboardInterrupt are BaseException,
# not Exception, so they propagate without being logged here.
#
# NOTE on double-logging: scorch.main's per-frame boundary already routes
# the exception through diag.log_exception (full traceback + GameState
# snapshot -> logs/scorch.log) BEFORE it reaches here. This handler is
# the outer net for failures OUTSIDE the frame loop (App.__init__, setup
# screens, etc.) and the durable plain-text artifact (crash.log) that
# needs no logging config. To avoid a redundant traceback in scorch.log,
# it emits only a one-line marker there, not a second full dump.
crash_path = os.path.join(HERE, "crash.log")
try:
from scorch import diag
diag.log.error("top-level crash (see crash.log); re-raising")
except Exception: # diag import/log must never mask the real error
pass
try:
with open(crash_path, "a") as fh:
fh.write("\n===== crash =====\n")
fh.write("argv: %r\n" % (sys.argv,))
traceback.print_exc(file=fh)
sys.stderr.write("\n[crash logged to %s]\n" % crash_path)
except OSError:
pass # never let crash-logging itself mask the real error
raise