Skip to content

Commit

Permalink
Refactor build_app function to remove development mode handling and s…
Browse files Browse the repository at this point in the history
…implify spec file management
  • Loading branch information
valentin-marquez committed Mar 6, 2025
1 parent d663555 commit 512bb31
Showing 1 changed file with 5 additions and 41 deletions.
46 changes: 5 additions & 41 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,22 @@ def clean():
return False


def build_app(version=None, dev=False):
def build_app(version=None):
"""Build the VLC Discord RP application executable"""
print("Building VLC Discord Rich Presence application...")

# Update version_info.txt if version is provided
if version:
update_version_info(version)

# Modify app.spec for console mode based on dev flag
spec_file_path = os.path.join("spec", "app.spec")
if os.path.exists(spec_file_path):
# Read the spec file
with open(spec_file_path, "r") as f:
spec_content = f.read()

# Backup original spec file
with open(f"{spec_file_path}.bak", "w") as f:
f.write(spec_content)

# Set console mode according to dev flag
if dev:
print("Development mode: Building with console window...")
spec_content = re.sub(r"console=(True|False)", "console=True", spec_content)
else:
print("Release mode: Building without console window...")
spec_content = re.sub(
r"console=(True|False)", "console=False", spec_content
)

# Write modified spec file
with open(spec_file_path, "w") as f:
f.write(spec_content)

# Run PyInstaller for the main application
try:
subprocess.run(["pyinstaller", "--clean", "spec/app.spec"], check=True)
print("Application build complete!")
success = os.path.exists(os.path.join("dist", "VLC Discord Presence.exe"))
return os.path.exists(os.path.join("dist", "VLC Discord Presence.exe"))
except subprocess.CalledProcessError:
print("Application build failed!")
success = False

# Restore original spec file if modified
if os.path.exists(f"{spec_file_path}.bak"):
shutil.move(f"{spec_file_path}.bak", spec_file_path)

return success
return False


def update_version_info(version):
Expand Down Expand Up @@ -211,18 +180,13 @@ def package():
"--version",
help="Version number to update in version_info.txt",
)
parser.add_argument(
"--dev",
action="store_true",
help="Build in development mode with console window enabled",
)

args = parser.parse_args()

if args.command == "clean":
clean()
elif args.command == "build":
build_app(version=args.version, dev=args.dev)
build_app(version=args.version)
elif args.command == "installer":
build_installer()
elif args.command == "package":
Expand All @@ -232,7 +196,7 @@ def package():
elif args.command == "all":
if not clean():
exit(1)
if not build_app(args.version, dev=args.dev):
if not build_app(args.version):
exit(1)
if not build_installer():
exit(1)
Expand Down

0 comments on commit 512bb31

Please sign in to comment.