fix(build.py): fixed build script not including replacements.json
This commit is contained in:
parent
590f4cc3bd
commit
26f4c50049
46
build.py
Normal file
46
build.py
Normal file
@ -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...")
|
@ -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
|
@ -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...")
|
Loading…
x
Reference in New Issue
Block a user