This repository was archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyinstaller.spec
183 lines (163 loc) · 5.04 KB
/
pyinstaller.spec
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- mode: python -*-
from __future__ import print_function
import glob
import hashlib
import os
import shutil
import site
import stat
import sys
import time
from zipfile import ZIP_DEFLATED, ZipFile, ZipInfo
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-remove-tkinter-tcl
sys.modules["FixTk"] = None
options = [
# Enable unbuffered stdio:
("u", None, "OPTION"),
# Supress CryptographyDeprecationWarning (https://github.com/gridsync/gridsync/issues/313):
("W ignore::UserWarning", None, "OPTION"),
]
added_files = [
("COPYING.*", "."),
("CREDITS", "."),
("relnotes.txt", "."),
("src/allmydata/web/*.xhtml", "allmydata/web"),
("src/allmydata/web/static/*", "allmydata/web/static"),
("src/allmydata/web/static/css/*", "allmydata/web/static/css"),
("src/allmydata/web/static/img/*.png", "allmydata/web/static/img"),
]
hidden_imports = [
# Required for `tahoe run`/`tahoe daemonize`:
"allmydata.client",
"allmydata.introducer",
"allmydata.stats",
# Required always:
"cffi",
# Required previously, but possibly no longer necessary:
"six.moves.html_parser",
"yaml",
"zfec",
]
a = Analysis(
["static/tahoe.py"],
pathex=[],
binaries=None,
datas=added_files,
hiddenimports=hidden_imports,
hookspath=[],
runtime_hooks=[],
excludes=["FixTk", "tcl", "tk", "_tkinter", "tkinter", "Tkinter"],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=None,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=None)
exe = EXE(
pyz,
a.scripts,
options,
exclude_binaries=True,
name="tahoe",
debug=False,
strip=False,
upx=False,
console=True,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name="Tahoe-LAFS",
)
# These directories are not needed and the presence of the dot
# within them has broken macOS notarization in the past.
for path in glob.glob(
os.path.join("dist", "Tahoe-LAFS", "cryptography-*-py2.7.egg-info")
):
try:
shutil.rmtree(path)
except OSError:
pass
try:
shutil.rmtree(os.path.join("dist", "Tahoe-LAFS", "include", "python2.7"))
except OSError:
pass
try:
shutil.rmtree(os.path.join("dist", "Tahoe-LAFS", "lib", "python2.7"))
except OSError:
pass
# The (rustc compiled) python-challenge-bypass-ristretto library
# gets missed by PyInstaller for some reason so add it manually.
os.makedirs(os.path.join("dist", "Tahoe-LAFS", "challenge_bypass_ristretto"))
if hasattr(sys, "real_prefix"):
if sys.platform == "win32":
site_packages = site.getsitepackages()[1]
else:
site_packages = site.getsitepackages()[0]
else:
site_packages = site.getusersitepackages()
shutil.copy2(
glob.glob(
os.path.join(
site_packages, "challenge_bypass_ristretto", "_native__lib.*"
)
)[0],
os.path.join("dist", "Tahoe-LAFS", "challenge_bypass_ristretto"),
)
def make_deterministic_zip(
base_name,
root_dir=None,
base_dir=None,
timestamp=1609477200, # (2021, 1, 1, 0, 0, 0)
):
zipfile_path = os.path.abspath(base_name)
if not root_dir:
root_dir = os.getcwd()
if not base_dir:
base_dir = os.getcwd()
year, month, day, hour, minute, second, _, _, _ = time.localtime(timestamp)
date_time = (year, month, day, hour, minute, second)
cwd = os.getcwd()
os.chdir(root_dir)
paths = [base_dir + "/"]
for root, directories, files in os.walk(base_dir):
for file in files:
paths.append(os.path.join(root, file))
for directory in directories:
dirpath = os.path.join(root, directory)
if os.path.islink(dirpath):
paths.append(dirpath)
else:
paths.append(dirpath + "/")
with ZipFile(zipfile_path, "w", ZIP_DEFLATED) as zf:
for path in sorted(paths):
zinfo = ZipInfo(path)
zinfo.date_time = date_time
if path.endswith("/"):
zinfo.external_attr = (0o755 | stat.S_IFDIR) << 16
zf.writestr(zinfo, "")
elif os.path.islink(path):
zinfo.filename = path # To strip trailing "/" from dirs
zinfo.create_system = 3
zinfo.external_attr = (0o755 | stat.S_IFLNK) << 16
zf.writestr(zinfo, os.readlink(path))
else:
if os.access(path, os.X_OK):
zinfo.external_attr = (0o755 | stat.S_IFREG) << 16
else:
zinfo.external_attr = (0o644 | stat.S_IFREG) << 16
with open(path, "rb") as f:
zf.writestr(zinfo, f.read())
os.chdir(cwd)
def sha256sum(filepath):
hasher = hashlib.sha256()
with open(os.path.abspath(filepath), "rb") as f:
for block in iter(lambda: f.read(4096), b""):
hasher.update(block)
return hasher.hexdigest()
zip_path = os.path.join("dist", "Tahoe-LAFS.zip")
make_deterministic_zip(zip_path, "dist", "Tahoe-LAFS")
print("{} {}".format(sha256sum(zip_path), zip_path))