Skip to content

Commit efff14b

Browse files
committed
Further refine platform-specific setup.py support for macOS, win32, etc.
o Only use cx_Freeze on Windows; setuptools w/ PyInstaller on macOS o Compute build-deps and use for all sdist, wheel, and .app/.exe targets
1 parent 63349d2 commit efff14b

File tree

2 files changed

+129
-111
lines changed

2 files changed

+129
-111
lines changed

GNUmakefile

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,22 @@ build-check:
8989
signing-check:
9090
$(SIGNTOOL)
9191

92-
# Any build dependencies that can't be automatically deduced.
93-
deps: deps-txt
94-
9592
build: clean wheel app
9693

94+
# All the build dependencies that are dynamically deduced
95+
build-deps: build-deps-txt
9796

9897
#
9998
# org-mode products.
10099
#
101-
# deps-txt: All of the .txt files needed to build
100+
# deps-txt: All of the gui/.txt files needed to built, before the sdist, wheel or app
102101
#
103102
%.txt: %.org
104103
emacs $< --batch -f org-ascii-export-to-ascii --kill
105104

106105
GUI_TXT = $(patsubst %.org,%.txt,$(wildcard slip39/gui/*.org))
107106

108-
deps-txt: $(GUI_TXT) slip39/gui/SLIP-39.txt
107+
build-deps-txt: $(GUI_TXT) slip39/gui/SLIP-39.txt
109108

110109
slip39/gui/SLIP-39.txt:
111110
toilet --font ascii12 SLIP-39 > $@
@@ -126,7 +125,8 @@ $(VENV_LOCAL)/$(VENV_NAME):
126125
@echo; echo "*** Building $@ VirtualEnv..."
127126
@rm -rf $@ && $(PY3) -m venv $(VENV_OPTS) $@ \
128127
&& cd $@ && git clone $(GHUB_REPO) -b $(GHUB_BRCH) \
129-
&& . ./bin/activate && make -C $(GHUB_NAME) install-dev install
128+
&& . ./bin/activate \
129+
&& make -C $(GHUB_NAME) install-dev install
130130

131131
# Activate a given VirtualEnv, and go to its python-slip39 installation
132132
# o Creates a custom venv-activate.sh script in the venv, and uses it start
@@ -143,46 +143,46 @@ $(VENV_LOCAL)/$(VENV_NAME)-activate: $(VENV_LOCAL)/$(VENV_NAME)
143143
@bash --init-file $</venv-activate.sh -i
144144

145145

146-
wheel: deps dist/slip39-$(VERSION)-py3-none-any.whl
146+
wheel: dist/slip39-$(VERSION)-py3-none-any.whl
147147

148-
dist/slip39-$(VERSION)-py3-none-any.whl: build-check FORCE
148+
dist/slip39-$(VERSION)-py3-none-any.whl: build-check build-deps FORCE
149149
$(PY3) -m build
150150
@ls -last dist
151151

152152
# Install from wheel, including all optional extra dependencies
153153
install-dev:
154154
$(PY3) -m pip install --upgrade -r requirements-dev.txt
155155

156-
install: deps dist/slip39-$(VERSION)-py3-none-any.whl FORCE
156+
install: dist/slip39-$(VERSION)-py3-none-any.whl FORCE
157157
$(PY3) -m pip install --force-reinstall $<[gui,dev,serial,wallet]
158158

159159
# Building / Signing / Notarizing and Uploading the macOS App
160160
# o TODO: no signed and notarized package yet accepted for upload by macOS App Store
161-
msi: deps dist/slip39-$(VERSION)-win64.msi
162-
app: deps dist/SLIP-39.app
161+
msi: dist/slip39-$(VERSION)-win64.msi
162+
app: dist/SLIP-39.app
163163

164164
app-packages: app-zip-valid app-dmg-valid app-pkg-valid
165165
app-upload: app-dmg-upload
166166

167167

168168
# Generate, Sign and Package the macOS SLIP-39.app GUI for App Store or local/manual installation
169169
# o Try all the approaches of packaging a macOS App for App Store upload
170-
app-dmg: deps dist/SLIP-39-$(VERSION).dmg
171-
app-zip: deps dist/SLIP-39-$(VERSION).zip
172-
app-pkg: deps dist/SLIP-39-$(VERSION).pkg
170+
app-dmg: dist/SLIP-39-$(VERSION).dmg
171+
app-zip: dist/SLIP-39-$(VERSION).zip
172+
app-pkg: dist/SLIP-39-$(VERSION).pkg
173173

174-
app-dmg-valid: deps dist/SLIP-39-$(VERSION).dmg.valid
175-
app-zip-valid: deps dist/SLIP-39-$(VERSION).zip.valid
176-
app-pkg-valid: deps dist/SLIP-39-$(VERSION).pkg.valid
174+
app-dmg-valid: dist/SLIP-39-$(VERSION).dmg.valid
175+
app-zip-valid: dist/SLIP-39-$(VERSION).zip.valid
176+
app-pkg-valid: dist/SLIP-39-$(VERSION).pkg.valid
177177

178-
app-dmg-upload: deps dist/SLIP-39-$(VERSION).dmg.upload-package
179-
app-zip-upload: deps dist/SLIP-39-$(VERSION).zip.upload-package
180-
app-pkg-upload: deps dist/SLIP-39-$(VERSION).pkg.upload-package
178+
app-dmg-upload: dist/SLIP-39-$(VERSION).dmg.upload-package
179+
app-zip-upload: dist/SLIP-39-$(VERSION).zip.upload-package
180+
app-pkg-upload: dist/SLIP-39-$(VERSION).pkg.upload-package
181181

182182
#
183183
# Build the windows .msi installer. Must build and sign the .exe first
184184
#
185-
build/exe.$(CXFREEZE_EXT)/SLIP-39.exe:
185+
build/exe.$(CXFREEZE_EXT)/SLIP-39.exe: build-deps
186186
echo -e "\n\n*** Building $@"
187187
@$(PY3) setup.py build_exe > cx_Freeze.build_exe.log \
188188
&& echo -e "\n\n*** $@ Build successfully:" \
@@ -509,7 +509,8 @@ dist/SLIP-39.app-checkids: SLIP-39.spec
509509
# you find the one with the matching fingerprint. Grr... Repeat 'til check-signature works.
510510
dist/SLIP-39.app: SLIP-39-macOS.spec \
511511
SLIP-39.metadata/entitlements.plist \
512-
images/SLIP-39.icns
512+
images/SLIP-39.icns \
513+
build-deps
513514
@echo -e "\n\n*** Rebuilding $@, version $(VERSION)..."
514515
rm -rf build $@*
515516
sed -I "" -E "s/version=.*/version='$(VERSION)',/" $<

setup.py

Lines changed: 106 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,124 @@
1-
from cx_Freeze import setup, Executable
2-
31
import os
42
import sys
53
import glob
64
import fnmatch
75

8-
# cx_Freeze options
9-
# cx-freeze.readthedocs.io/en/latest/setup_script.html
10-
#
11-
base = None
6+
Executable = None
127
if sys.platform == 'win32':
13-
base = "Win32GUI"
14-
15-
company_name = "pjkundert"
16-
product_name = "python-slip39"
17-
icon_win = "images/SLIP-39.ico"
18-
19-
shortcut = (
20-
"DesktopShortcut", # Shortcut
21-
"DesktopFolder", # Directory_
22-
"SLIP-39", # Name
23-
"TARGETDIR", # Component_
24-
"[TARGETDIR]SLIP-39.exe", # Target
25-
None, # Arguments
26-
None, # Description
27-
None, # Hotkey
28-
None, # Icon
29-
None, # IconIndex
30-
None, # ShowCmd
31-
"TARGETDIR", # WkDir
32-
)
8+
# We use cx_Freeze for executable/installer packaging on Windows, only, for now.
9+
from cx_Freeze import setup, Executable
10+
print( f"sys.platform {sys.platform}: Using cx_Freeze.setup" )
11+
else:
12+
from setuptools import setup
13+
print( f"sys.platform {sys.platform}: Using setuptools.setup" )
3314

34-
msi_data = dict(
35-
Shortcut = [
36-
shortcut,
37-
],
38-
#Icon = [
39-
# icon_win,
40-
#]
41-
)
15+
#
16+
# For various platforms, extra setup options are required. Collect them here
17+
#
18+
extra_options = {}
4219

43-
bdist_msi_options = dict(
44-
add_to_path = True,
45-
data = msi_data,
46-
initial_target_dir = rf"[ProgramFilesFolder]\{company_name}\{product_name}",
47-
)
20+
#
21+
# cx_Freeze options -- Windows .exe/.msi support
22+
# cx-freeze.readthedocs.io/en/latest/setup_script.html
23+
#
24+
mainscript = "SLIP-39.py"
25+
copyright = "Copyright (c) 2022 Perry Kundert",
4826

49-
build_exe_options = dict(
50-
packages = [],
51-
excludes = [],
52-
include_msvcr = True,
53-
)
54-
executables = None
5527
if sys.platform == 'win32':
28+
company_name = "pjkundert"
29+
product_name = "python-slip39"
30+
icon_win = "images/SLIP-39.ico"
31+
32+
shortcut = (
33+
"DesktopShortcut", # Shortcut
34+
"DesktopFolder", # Directory_
35+
"SLIP-39", # Name
36+
"TARGETDIR", # Component_
37+
"[TARGETDIR]SLIP-39.exe", # Target
38+
None, # Arguments
39+
None, # Description
40+
None, # Hotkey
41+
None, # Icon
42+
None, # IconIndex
43+
None, # ShowCmd
44+
"TARGETDIR", # WkDir
45+
)
46+
47+
msi_data = dict(
48+
Shortcut = [
49+
shortcut,
50+
],
51+
#Icon = [
52+
# icon_win,
53+
#]
54+
)
55+
56+
bdist_msi_options = dict(
57+
add_to_path = True,
58+
data = msi_data,
59+
initial_target_dir = rf"[ProgramFilesFolder]\{company_name}\{product_name}",
60+
)
61+
62+
build_exe_options = dict(
63+
packages = [],
64+
excludes = [],
65+
include_msvcr = True,
66+
)
67+
5668
executables = [
5769
Executable(
58-
"SLIP-39.py",
59-
copyright = "Copyright (c) 2022 Perry Kundert",
60-
base = base,
61-
icon = icon_win,
70+
mainscript,
71+
copyright = copyright,
72+
base = "Win32GUI",
73+
icon = icon_win,
6274
),
6375
]
6476

77+
extra_options = dict(
78+
executables = executables,
79+
options = dict(
80+
bdist_msi = bdist_msi_options,
81+
build_exe = build_exe_options,
82+
)
83+
)
84+
85+
86+
'''
87+
if sys.platform == 'darwin':
88+
# For py2{app,exe} App Generation. TODO: Does not work; use PyInstaller instead
89+
extra_options = dict(
90+
setup_requires = [ 'py2app' ],
91+
app = [ mainscript ],
92+
# Cross-platform applications generally expect sys.argv to
93+
# be used for opening files.
94+
# Don't use this with GUI toolkits, the argv
95+
# emulator causes problems and toolkits generally have
96+
# hooks for responding to file-open events.
97+
options = dict(
98+
py2app = dict(
99+
argv_emulation = True,
100+
iconfile = 'images/SLIP39.icns',
101+
includes = 'tkinter',
102+
),
103+
),
104+
)
105+
elif sys.platform == 'win32':
106+
extra_options = dict(
107+
setup_requires = [ 'py2exe' ],
108+
app = [ mainscript ],
109+
)
110+
else:
111+
extra_options = dict(
112+
# Normally unix-like platforms will use "setup.py install"
113+
# and install the main script as such
114+
scripts = [ mainscript ],
115+
)
116+
'''
117+
65118

119+
#
120+
# All platforms
121+
#
66122
HERE = os.path.dirname( os.path.abspath( __file__ ))
67123

68124
# Must work if setup.py is run in the source distribution context, or from
@@ -245,40 +301,6 @@
245301
"Bug Tracker": "https://github.com/pjkundert/python-slip39/issues",
246302
}
247303

248-
'''
249-
# For py2{app,exe} App Generation. TODO: Does not work; use PyInstaller instead
250-
mainscript = "SLIP39.py"
251-
252-
if sys.platform == 'darwin':
253-
extra_options = dict(
254-
setup_requires = [ 'py2app' ],
255-
app = [ mainscript ],
256-
# Cross-platform applications generally expect sys.argv to
257-
# be used for opening files.
258-
# Don't use this with GUI toolkits, the argv
259-
# emulator causes problems and toolkits generally have
260-
# hooks for responding to file-open events.
261-
options = dict(
262-
py2app = dict(
263-
argv_emulation = True,
264-
iconfile = 'images/SLIP39.icns',
265-
includes = 'tkinter',
266-
),
267-
),
268-
)
269-
elif sys.platform == 'win32':
270-
extra_options = dict(
271-
setup_requires = [ 'py2exe' ],
272-
app = [ mainscript ],
273-
)
274-
else:
275-
extra_options = dict(
276-
# Normally unix-like platforms will use "setup.py install"
277-
# and install the main script as such
278-
scripts = [ mainscript ],
279-
)
280-
'''
281-
282304
setup(
283305
name = "slip39",
284306
version = __version__,
@@ -302,10 +324,5 @@
302324
url = "https://github.com/pjkundert/python-slip39",
303325
classifiers = classifiers,
304326
python_requires = ">=3.9",
305-
executables = executables,
306-
options = dict(
307-
bdist_msi = bdist_msi_options,
308-
build_exe = build_exe_options,
309-
),
310-
#**extra_options
327+
**extra_options
311328
)

0 commit comments

Comments
 (0)