-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathossdbtoolsservice_main.spec
145 lines (118 loc) · 4.19 KB
/
ossdbtoolsservice_main.spec
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# ossdbtoolsservice_main.spec
from PyInstaller.utils.hooks import collect_data_files, collect_all
import psycopg
import platform
import os
block_cipher = None
def collect_files(src_folder, dest_folder, file_ext=None):
collected_files = []
for root, dirs, files in os.walk(src_folder):
for file in files:
if not file_ext or file.endswith(file_ext):
src_path = os.path.join(root, file)
rel_path = os.path.relpath(root, src_folder)
dest_path = os.path.join(dest_folder, rel_path)
collected_files.append((src_path, dest_path))
return collected_files
hiddenimports = ["psycopg", "engineio.async_drivers.gevent", "xmlrpc.server"]
binaries = []
datas = []
# Include psycopg dependencies
datas += collect_data_files("psycopg")
# Collect all dependencies for debugpy
datas_debugpy, binaries_debugpy, hiddenimports_debugpy = collect_all("debugpy")
hiddenimports.extend(hiddenimports_debugpy)
datas.extend(datas_debugpy)
binaries.extend(binaries_debugpy)
# Include ossdbtoolsservice data files
def gather_service_data_files():
# Include ossdbtoolsservice data files, but filter pg_exes dynamically
all_datas = collect_data_files("ossdbtoolsservice", include_py_files=False)
# Determine the current OS
system = platform.system()
def filter_pg_exes(files, system) -> list:
"""Remove non-relevant pg_exes directories based on the OS."""
exclude_dirs = []
if system == "Windows":
exclude_dirs = ["pg_exes/mac", "pg_exes/linux"]
elif system == "Darwin":
exclude_dirs = ["pg_exes/win", "pg_exes/linux"]
elif system == "Linux":
exclude_dirs = ["pg_exes/win", "pg_exes/mac"]
filtered_files = []
for src, dest in files:
if not any(exclude in src.replace("\\", "/") for exclude in exclude_dirs):
filtered_files.append((src, dest))
return filtered_files
# Apply the filtering
return filter_pg_exes(all_datas, system)
datas += gather_service_data_files()
datas += [
(
"./ossdbtoolsservice/language/completion/packages/pgliterals/pgliterals.json",
"language/completion/packages/pgliterals",
)
]
datas += collect_files(
"./ossdbtoolsservice/chat/prompts", "ossdbtoolsservice/chat/prompts", ".md"
)
# Include sql and macros files under pgsmo/objects
src_folder = "./pgsmo/objects"
dest_folder = "./pgsmo/objects"
sql_files = collect_files(src_folder, dest_folder, ".sql")
macro_files = collect_files(src_folder, dest_folder, ".macros")
datas += sql_files
datas += macro_files
# Include zlib library for macOS ARM
if platform.system() == "Darwin" and platform.machine() == "arm64":
if os.path.exists("/usr/local/opt/zlib/lib/libz.dylib"):
binaries.append(("/usr/local/opt/zlib/lib/libz.dylib", "zlib"))
else:
print("Warning: zlib not found!")
# Include openssl libraries for macOS ARM
if platform.system() == "Darwin" and platform.machine() == "arm64":
openssl_dirs = [
"/opt/homebrew/opt/[email protected]/lib",
"/usr/local/opt/[email protected]/lib",
]
for openssl_dir in openssl_dirs:
if os.path.exists(openssl_dir):
break
for lib in ("libssl.1.1.dylib", "libcrypto.1.1.dylib"):
lib_path = os.path.join(openssl_dir, lib)
if os.path.exists(lib_path):
# Here we copy the dylib to the root of the bundle ('.').
# You can adjust the destination folder if needed.
binaries.append((lib_path, "."))
else:
print(f"Warning: {lib_path} not found!")
a = Analysis(
["ossdbtoolsservice/ossdbtoolsservice_main.py"],
pathex=[],
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name="ossdbtoolsservice_main",
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
)