This repository has been archived by the owner on Mar 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.py
61 lines (48 loc) · 2.52 KB
/
compile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sysconfig
import os
import shutil
import subprocess
site_packages_path = sysconfig.get_paths()["purelib"]
project_path = os.getcwd()
###---Modify (hack) source files---###
#Pyinstaller hook-shapely.py intervention
#Create new hook-shapely.py with custom folder dlls path
with open(os.path.join(project_path, "compile_aux", "boilerplate-hook-shapely.py"), 'r') as file :
filedata = file.read()
filedata = filedata.replace('XXX', os.path.join(project_path, "dlls"))
with open(os.path.join(project_path, "compile_aux", "hook-shapely.py"), 'w') as file:
file.write(filedata)
#Replace default hook-shapely.py with the new one
shutil.copyfile(os.path.join(project_path, "compile_aux", "hook-shapely.py"), os.path.join(site_packages_path, "_pyinstaller_hooks_contrib", "hooks", "stdhooks", "hook-shapely.py"))
#Replace paddle/dataset/image.py file from Paddle with modify one
shutil.copyfile(os.path.join(project_path, "compile_aux", "image.py"), os.path.join(site_packages_path, "paddle", "dataset", "image.py"))
###---Add new hooks---###
# Copy custom hook for Pyinstaller
shutil.copyfile(os.path.join(project_path, "compile_aux", "hook-paddle.py"), os.path.join(site_packages_path, "PyInstaller", "hooks", "hook-paddle.py"))
###---Verify the version of setuptools in global Python for avoid bug---###
command = "pip install --upgrade setuptools==59.8.0"
subprocess.run(command, capture_output=True, shell=True)
###---Compile with Pyinstaller---###
#Delete current output folders
try:
shutil.rmtree(os.path.join(project_path, "build"))
shutil.rmtree(os.path.join(project_path, "dist"))
except:
pass
#Run Pyinstaller in poetry env
command = "poetry shell && pyinstaller --clean --specpath ./ kavt.spec"
subprocess.run(command, capture_output=True, shell=True)
###---Complement de output compile folder with extra tools---###
#TODO: Optimizar, solo copiar lo necesario
#Copy fluid
try:
shutil.rmtree(os.path.join(project_path, "dist", "kavt", "paddle", "fluid"))
except:
pass
shutil.copytree(os.path.join(site_packages_path, "paddle", "fluid"), os.path.join(project_path, "dist", "kavt", "paddle", "fluid"))
#Copy Shapely
shutil.copytree(os.path.join(site_packages_path, "Shapely.libs"), os.path.join(project_path, "dist", "kavt", "Shapely.libs"))
#Copy ppocr
shutil.copytree(os.path.join(site_packages_path, "paddleocr", "ppocr"), os.path.join(project_path, "dist", "kavt", "ppocr"))
#Copy easyocr character
shutil.copytree(os.path.join(site_packages_path, "easyocr", "character"), os.path.join(project_path, "dist", "kavt", "easyocr", "character"))