-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (29 loc) · 1.18 KB
/
utils.py
File metadata and controls
39 lines (29 loc) · 1.18 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
import os
import sys
def get_resource_path(relative_path: str) -> str:
if getattr(sys, 'frozen', False):
base_path = os.path.dirname(sys.executable)
else:
script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(script_dir)
if os.path.basename(script_dir) == "app" and os.path.exists(os.path.join(parent_dir, "compute_type.txt")):
base_path = script_dir
else:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def get_install_dir() -> str:
script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(script_dir)
if os.path.basename(script_dir) == "app" and os.path.exists(os.path.join(parent_dir, "compute_type.txt")):
return parent_dir
return script_dir
def is_gpu_install() -> bool:
install_dir = get_install_dir()
compute_type_file = os.path.join(install_dir, "compute_type.txt")
if os.path.exists(compute_type_file):
try:
with open(compute_type_file, 'r') as f:
return f.read().strip().lower() == "gpu"
except Exception:
pass
return True