From fb2ea45e9d8cdf2706bd40ddf75ad0c8d9b8bbe2 Mon Sep 17 00:00:00 2001 From: Mirco Janisch Date: Sun, 15 Oct 2023 20:04:22 +0200 Subject: [PATCH] switched windows build script to cx_freeze --- build.linux.sh | 5 +++- build.windows.ps1 | 20 +++++++++++----- setup.py | 60 +++++++++++++++++------------------------------ 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/build.linux.sh b/build.linux.sh index b5d6694..ab0b33c 100644 --- a/build.linux.sh +++ b/build.linux.sh @@ -2,6 +2,10 @@ # May need to install apt install python3-venv +# Remove previous build +echo "Removing previous build..." +rm -rf dist/ + # Create a virtual environment echo "Creating a virtual environment..." python3 -m venv .venv @@ -23,4 +27,3 @@ cp -r media dist/ # Zipping the dist folder echo "Zipping the dist folder..." zip -r dist/smwc-browser.linux.amd64.zip dist/ - diff --git a/build.windows.ps1 b/build.windows.ps1 index 96c97d8..1283edf 100644 --- a/build.windows.ps1 +++ b/build.windows.ps1 @@ -1,6 +1,10 @@ # May need to run in order be be able to execute: # Set-ExecutionPolicy RemoteSigned +# Remove previous build +Write-Host "Removing previous build..." +Remove-Item -Path ".\build" -Recurse -Force + # Create a virtual environment Write-Host "Creating a virtual environment..." python -m venv .venv @@ -9,16 +13,20 @@ pip install -r requirements.txt -r requirements-dev.txt # Build the project Write-Host "Building the project..." -pyinstaller smwc-browser.spec +python .\setup.py build + +# Get the build folder +Write-Host "Getting the build folder..." +$buildFolder = Get-ChildItem -Path ".\build\exe.win-amd64*" -Directory | Select-Object -First 1 # Copy the config file Write-Host "Copying the config file..." -Copy-Item .\config.example.json .\dist\config.example.json +Copy-Item .\config.example.json $buildFolder\config.example.json # Copy the media folder Write-Host "Copying the media folder..." -Copy-Item .\media .\dist\media -Recurse +Copy-Item .\media $buildFolder\media -Recurse -# Zipping the dist folder -Write-Host "Zipping the dist folder..." -Compress-Archive -Path .\dist\ -DestinationPath .\dist\smwc-browser.windows.amd64.zip \ No newline at end of file +# Zipping the build folder +Write-Host "Zipping the build folder..." +Get-ChildItem -Path $buildFolder\* | Compress-Archive -DestinationPath ".\build\smwc-browser.windows.amd64.zip" \ No newline at end of file diff --git a/setup.py b/setup.py index dc3dacf..f2cb70c 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,24 @@ import os -# from cx_Freeze import setup, Executable - - -def find_all_scripts(directory): - script_list = [] - for root, _, files in os.walk(directory): - for file in files: - if file.endswith(".py"): - script_list.append(os.path.relpath(os.path.join(root, file))) - return script_list - - -def parse_requirements(requirements_file): - with open(requirements_file, mode="r", encoding="utf-8") as file: - return [line.strip() for line in file] - - -all_scripts = find_all_scripts("source") -print(all_scripts) - -required_modules = parse_requirements("requirements.txt") -print(required_modules) - - -# build_exe_options = {"packages": ["os"], "includes": ["tkinter"]} -# executables=[Executable("source/main.py", base=base)] - -# setup( -# name="smwc-browser", -# version="1.0", -# description="A browser for SMW Central", -# executables=[Executable(script) for script in all_scripts], -# options={ -# "build_exe": { -# "packages": required_modules, -# } -# }, -# ) +from cx_Freeze import setup, Executable + +# todo: needs some fine tuning +build_exe_options = { + "excludes": [ + "tkinter", + "unittest", + "asyncio", + "tk86t", + "tk8.6", + ], +} + +target = Executable(script="source/main.py", icon="resources\windows_icon.ico") + +setup( + name="smwc-browser", + version="1.0", + description="A browser for SMW Central", + executables=[target], + options={"build_exe": build_exe_options}, +)