diff --git a/build.py b/build.py new file mode 100644 index 0000000..da4c60d --- /dev/null +++ b/build.py @@ -0,0 +1,46 @@ +import os +import sys +import shutil +import subprocess +import PyInstaller.__main__ + +# Initialize constants +SCRIPT = "refactor.py" +ICON = "assets/icon.ico" +NAME = "cod_api_tool" +DIST_PATH = "bin/build" + +# Get absolute paths to data files +script_dir = os.path.abspath(os.path.dirname(__file__)) +charset_normalizer_data = os.path.join('deps', 'frequencies.json') +replacements_json = os.path.join(script_dir, 'data', 'replacements.json') + +# Verify replacements.json exists before building +if not os.path.exists(replacements_json): + print(f"ERROR: {replacements_json} not found. Make sure this file exists.") + sys.exit(1) + +# Activate the virtual environment +venv_activation_script = os.path.join(os.getcwd(), 'venv', 'Scripts', 'activate') +subprocess.call(venv_activation_script, shell=True) + +# Run PyInstaller +PyInstaller.__main__.run([ + SCRIPT, + '--name', NAME, + '--noconfirm', + '--onefile', + '--console', + '--icon', ICON, + '--distpath', DIST_PATH, + # This is the correct way to add the data file - preserve the directory structure + '--add-data', f"{charset_normalizer_data};charset_normalizer/assets", + '--add-data', f"{replacements_json};data" # Note: using 'data' as the destination folder +]) + +# Clean up the build directory and spec file +shutil.rmtree('build') +os.remove(f'{NAME}.spec') + +print(f"Build completed successfully. Executable is in {DIST_PATH}/{NAME}.exe") +input("Press Enter to continue...") \ No newline at end of file diff --git a/utils/build.bat b/utils/build.bat deleted file mode 100644 index 0a8d713..0000000 --- a/utils/build.bat +++ /dev/null @@ -1,10 +0,0 @@ -@echo off - -cd /d %~dp0 :: Change directory to the location of this batch file -call ../venv/Scripts/activate :: Activate the virtual environment -pyinstaller --noconfirm --onefile --console --icon "../assets/icon.ico" cod_api_tool.py --distpath="../build/bin" -n "cod_api_tool" - -rmdir /s /q build -del /q "cod_api_tool.spec" - -pause diff --git a/utils/build.py b/utils/build.py deleted file mode 100644 index a87bb13..0000000 --- a/utils/build.py +++ /dev/null @@ -1,36 +0,0 @@ -import os -import shutil -import subprocess -import PyInstaller.__main__ - -# Constants for your project -SCRIPT = "cod_api_tool.py" -ICON = "assets/icon.ico" -NAME = "cod_api_tool" -DIST_PATH = "bin" - -# Path to the 'frequencies.json' file within the charset_normalizer package -charset_normalizer_data = os.path.join('deps', 'frequencies.json') - -# Activate the virtual environment -venv_activation_script = os.path.join(os.getcwd(), 'venv', 'Scripts', 'activate') -subprocess.call(venv_activation_script, shell=True) - -# Run PyInstaller -PyInstaller.__main__.run([ - SCRIPT, - '--name', NAME, - '--noconfirm', - '--onefile', - '--console', - '--icon', ICON, - '--distpath', DIST_PATH, - '--add-data', f"{charset_normalizer_data};charset_normalizer/assets" -]) - -# Clean up the build directory and spec file -shutil.rmtree('build', ignore_errors=True) -os.remove('cod_api_tool.spec') - -# Optional: Pause at the end (like the 'pause' in batch script) -input("Press Enter to continue...")