2********************************************************************************
3@file generate_executable.py
4@brief Generate executable file
5********************************************************************************
15sys.path.append(os.path.join(os.path.dirname(__file__),
".."))
24log = logging.getLogger(
"GenerateExecutable")
25init_console_logging(logging.INFO)
28GIT_VERSION_PATH =
"../Source/Util"
29VERSION_FILE_NAME =
"version_info.txt"
30WARNING_FILE =
"PyInstaller_warnings.txt"
38 "darkdetect._mac_detect",
44 "No backend available"
48 "..\\Resources\\app.ico;Resources\\"
56def get_type_list(type_name: str, l_type_values: list[str]) -> list[str]:
59 @param type_name : type name
60 @param l_type_values : type values
64 for type_value
in l_type_values:
65 type_list.extend([f
"--{type_name}", type_value])
69if __name__ ==
"__main__":
72 command = [
r"..\.venv\Scripts\python",
"-m",
"PyInstaller",
"--clean"]
73 command.extend([
"--paths",
"..\\"])
75 command.extend([
"--icon",
"..\\Resources\\app.ico"])
76 command.extend([
"--version-file", f
"{WORKPATH}\\{VERSION_FILE_NAME}"])
77 command.extend(
get_type_list(
"hidden-import", L_HIDDEN_IMPORT))
78 command.extend(
get_type_list(
"exclude-module", L_EXCLUDE_MODULES))
79 command.extend([
"--name", __title__])
80 command.extend([
"--onefile",
"--noconsole",
"--noupx",])
81 command.extend([
"--distpath",
"bin"])
82 command.extend([
"--workpath", WORKPATH])
83 command.extend([
"../Source/app.py"])
85 generate_git_version_file(GIT_VERSION_PATH)
86 generate_version_file(VERSION_FILE_NAME, WORKPATH)
88 result = subprocess.run(command, stderr=subprocess.PIPE, text=
True, shell=
True, check=
False)
89 if result.returncode != 0:
90 result_report.append(
"Build executable failed!")
91 result_report.append(result.stderr)
93 possible_build_warnings = [line
for line
in result.stderr.split(
"\n")
if "WARNING" in line]
95 for warning
in possible_build_warnings:
97 for tolerate
in TOLERATED_WARNINGS:
98 if tolerate
in warning:
102 build_warnings.append(warning)
104 result_report.extend(build_warnings)
106 l_not_allowed_packages = check_included_packages()
107 if l_not_allowed_packages:
108 result_report.extend(l_not_allowed_packages)
109 log.info(result.stderr)
111 with open(WARNING_FILE, mode=
"w", encoding=
"utf-8")
as file:
112 report =
"\n".join(result_report)
117 log.error(
"FAILED build of executable")
120 s_spec_file = f
"{__title__}.spec"
121 if os.path.exists(s_spec_file):
122 os.remove(s_spec_file)
123 if os.path.exists(WORKPATH):
124 shutil.rmtree(WORKPATH)
125 log.info(
"SUCCESS build of executable")
list[str] get_type_list(str type_name, list[str] l_type_values)
get type list