-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathliferay_docker.py
More file actions
93 lines (74 loc) · 3.28 KB
/
Copy pathliferay_docker.py
File metadata and controls
93 lines (74 loc) · 3.28 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import signal
import sys
# --- SIGINT / CTRL+C Graceful Exit Handler ---
def _graceful_exit(sig, frame):
sys.stdout.write("\n\r")
sys.exit(0)
signal.signal(signal.SIGINT, _graceful_exit)
# --- Dev Environment Bootstrap Interceptor ---
# Allow `python liferay_docker.py dev-setup` to run even if third-party
# dependencies (like requests) or generated files (like ui_colors) are missing.
if len(sys.argv) > 1 and sys.argv[1] == "dev-setup":
import subprocess
from pathlib import Path
print("LDM Developer Environment Setup (Bootstrap)")
root = Path.cwd()
venv_dir = root / ".venv"
if not venv_dir.exists():
print("Creating virtual environment (.venv)...")
subprocess.run([sys.executable, "-m", "venv", ".venv"], check=True)
print("Virtual environment created.")
if os.name == "nt":
venv_python = venv_dir / "Scripts" / "python.exe"
venv_pip = venv_dir / "Scripts" / "pip.exe"
else:
venv_python = venv_dir / "bin" / "python3"
venv_pip = venv_dir / "bin" / "pip"
if not venv_python.exists():
print(f"Error: Could not find python in venv: {venv_python}")
sys.exit(1)
print("Installing dependencies...")
subprocess.run([str(venv_pip), "install", "--upgrade", "pip"], check=True)
if (root / "requirements.txt").exists():
subprocess.run([str(venv_pip), "install", "-r", "requirements.txt"], check=True)
if (root / "requirements-dev.txt").exists():
subprocess.run(
[str(venv_pip), "install", "-r", "requirements-dev.txt"], check=True
)
subprocess.run([str(venv_pip), "install", "-e", "."], check=True)
print("Generating UI Colors...")
if (root / "scripts" / "sync_colors.py").exists():
subprocess.run([str(venv_python), "scripts/sync_colors.py"], check=True)
print("Registering pre-commit hooks...")
subprocess.run([str(venv_python), "-m", "pre_commit", "install"], check=False)
print("\n✅ Development environment is ready!")
if os.name == "nt":
print("To activate, run: .\\.venv\\Scripts\\activate")
else:
print("To activate, run: source .venv/bin/activate")
sys.exit(0)
# --- Anti-Shadowing Logic ---
# If we are running as a standalone binary (frozen), we must ensure that
# we do not import modules from the current directory (shadowing), as
# this leads to incorrect version reporting and checksum failures.
if getattr(sys, "frozen", False):
# Get the internal bundle path (where the real ldm_core is)
bundle_dir = getattr(sys, "_MEIPASS", os.path.dirname(sys.executable))
# Remove any paths that point to the current working directory or external source
# We want to prioritize the internal bundle
sys.path = [p for p in sys.path if p != "" and p != os.getcwd()]
# Ensure bundle_dir is at the very front
if bundle_dir not in sys.path:
sys.path.insert(0, bundle_dir)
from ldm_core.cli import main # noqa: E402
from ldm_core.ui import UI # noqa: E402
if __name__ == "__main__":
if "-v" in sys.argv or "--verbose" in sys.argv:
UI.info("LDM: Initializing core (Hardened Edition 2026.04.08)")
try:
main()
except (KeyboardInterrupt, EOFError):
# Graceful exit for CTRL+C or CTRL+D
sys.stdout.write("\n\r")
sys.exit(0)