diff --git a/build_scripts/build_exe.py b/build_scripts/build_exe.py index 54ef942..4f88848 100644 --- a/build_scripts/build_exe.py +++ b/build_scripts/build_exe.py @@ -8,7 +8,49 @@ PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) ENTRY_POINT = os.path.join(PROJECT_ROOT, "src", "mind_reader", "app.py") -def build(): +def make_archive(source_dir, output_archive): + seven_zip_cmd = shutil.which("7z") or shutil.which("7za") + + default_7z_paths = [ + r"C:\Program Files\7-Zip\7z.exe", + r"C:\Program Files (x86)\7-Zip\7z.exe", + ] + + for path in default_7z_paths: + if os.path.exists(path): + seven_zip_cmd = path + break + + if seven_zip_cmd: + print(f"\nCreating 7z archive using {seven_zip_cmd}...") + + cmd = [ + seven_zip_cmd, + "a", + "-t7z", + "-mx=9", + "-m0=lzma2", + output_archive, + os.path.join(source_dir, "*"), + ] + + result = subprocess.run(cmd) + + if result.returncode == 0: + print(f"Archive successfully created: {output_archive}") + else: + print("Error while archiving with 7-Zip!") + + else: + print("\n7-Zip not found in system! Falling back to standard zip...") + zip_base = output_archive.replace(".7z", "") + archive_path = shutil.make_archive( + base_name=zip_base, format="zip", root_dir=source_dir + ) + print(f"Standard ZIP created: {archive_path}") + + +def build(archive=False): cmd = [ sys.executable, "-m", @@ -29,9 +71,16 @@ def build(): if result.returncode == 0: dist_path = os.path.join(PROJECT_ROOT, "dist", "MindReader") print("\nBuild completed!") - print(f"{dist_path}") + print(f"App dir: {dist_path}") + + if archive: + archive_target = os.path.join( + PROJECT_ROOT, "dist", "MindReader-win64.7z" + ) + make_archive(dist_path, archive_target) + else: - print("\nError!") + print("\nError during build!") def clean(): @@ -59,9 +108,10 @@ def clean(): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--clean-only", action="store_true") + parser.add_argument("--archive", action="store_true") args = parser.parse_args() if args.clean_only: clean() else: - build() + build(archive=args.archive)