-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathsetup.py
160 lines (136 loc) · 4.84 KB
/
setup.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
__author__ = "receyuki"
__filename__ = "setup.py"
__copyright__ = "Copyright 2023"
__email__ = "[email protected]"
"""
Create executables file for macOS and Windows
Usage:
macOS:
python setup.py py2app
windows:
python setup.py
"""
import platform
import toml
from pathlib import Path
from packaging import version
import os
# from sd_prompt_reader.__version__ import VERSION
def get_version():
path = Path(__file__).resolve().parents[0] / "pyproject.toml"
pyproject = toml.loads(open(str(path)).read())
return version.parse(pyproject["tool"]["poetry"]["version"])
def prepend_to_file(filename, line):
with open(filename, "r+") as file:
content = file.read()
file.seek(0)
file.write(line + "\n" + content)
VERSION = get_version().base_version
version_file = Path(__file__).resolve().parents[0] / "sd_prompt_reader/__version__.py"
with open(version_file, "w") as file:
file.write('VERSION = "' + str(get_version()) + '"\n')
if platform.system() == "Windows":
import pyinstaller_versionfile
pyinstaller_versionfile.create_versionfile(
output_file="file_version_info.txt",
version=get_version().base_version,
file_description="SD Prompt Reader",
internal_name="SD Prompt Reader",
legal_copyright="Copyright © 2023 receyuki All rights reserved.",
original_filename="SD Prompt Reader.exe",
product_name="SD Prompt Reader",
translations=[1033, 1200],
)
import PyInstaller.__main__
PyInstaller.__main__.run(["--clean", "win.spec"])
elif platform.system() == "Darwin":
from pathlib import Path
from setuptools import setup
import tkinter as tk
import shutil
import os
APP = ["main.py"]
DATA_FILES = []
CFBundleDocumentTypes = [
dict(
CFBundleTypeExtensions=["png", "jpg", "jpeg", "webp"],
CFBundleTypeName="Image File",
CFBundleTypeRole="Viewer",
),
]
OPTIONS = {
"iconfile": "sd_prompt_reader/resources/icon.icns",
"plist": {
"CFBundleName": "SD Prompt Reader",
"CFBundleDisplayName": "SD Prompt Reader",
"CFBundleVersion": str(get_version()),
"CFBundleShortVersionString": get_version().base_version,
"CFBundleIdentifier": "com.receyuki.sd-prompt-reader",
"NSHumanReadableCopyright": "Copyright © 2023 receyuki All rights reserved.",
"CFBundleDocumentTypes": CFBundleDocumentTypes,
},
"includes": [
"pyperclip",
"PIL",
"tkinter",
"tkinterdnd2",
"os",
"customtkinter",
"plyer",
"pyobjus",
"plyer.platforms.macosx.notification",
"tcl8",
"tcl8.6",
"charset_normalizer.md__mypyc",
"PIL.WebPImagePlugin",
"sd_prompt_reader",
],
"packages": ["sd_prompt_reader.resources"],
}
setup(
name="SD Prompt Reader",
app=APP,
data_files=DATA_FILES,
options={"py2app": OPTIONS},
setup_requires=["py2app"],
)
root = tk.Tk()
root.overrideredirect(True)
root.withdraw()
tcl_dir = Path(root.tk.exprstring("$tcl_library"))
tk_dir = Path(root.tk.exprstring("$tk_library"))
root.destroy()
os.makedirs("./dist/SD Prompt Reader.app/Contents/lib", exist_ok=True)
print(f"Copying TK from: {tk_dir}")
shutil.copytree(
tk_dir, f"./dist/SD Prompt Reader.app/Contents/lib/{tk_dir.parts[-1]}"
)
print(f"Copying TCL from: {tcl_dir}")
shutil.copytree(
tcl_dir, f"./dist/SD Prompt Reader.app/Contents/lib/{tcl_dir.parts[-1]}"
)
shutil.copy(
"__error__.sh", "./dist/SD Prompt Reader.app/Contents/Resources/__error__.sh"
)
# Ignore warning about py2app in CLI
file_path = "./dist/SD Prompt Reader.app/Contents/Resources/__boot__.py"
line_to_add = 'import warnings\nwarnings.filterwarnings("ignore", category=DeprecationWarning)\n'
prepend_to_file(file_path, line_to_add)
# Update poetry dependencies
skip_packages = ["pyinstaller", "pyinstaller-hooks-contrib", "py2app"]
with open("requirements.txt", "r") as file:
lines = file.readlines()
for line in lines:
skip = any(skip_package in line for skip_package in skip_packages)
if not skip:
if "; sys_platform == 'darwin'" in line:
package_name = line.split(";")[0].strip()
command = f"poetry add {package_name} --platform darwin"
else:
package_details = line.split(";")[0].strip()
command = f"poetry add {package_details}"
os.system(command)
print(f"Added: {line.strip()}")
else:
print(f"Skipped: {line.strip()}")
print("Dependencies have been processed.")