Skip to content

Commit 21f6b98

Browse files
committed
bundle wkhtml binary for macOS app
1 parent 6ffcd74 commit 21f6b98

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

scripts/build_app.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
("templates", "./templates"),
1414
]
1515

16-
if sys.platform.startswith("win"):
17-
added_data_options = [f"--add-data={src};{dst}" for src, dst in added_files]
18-
else:
19-
added_data_options = [f"--add-data={src}:{dst}" for src, dst in added_files]
20-
2116

2217
def build_macos(
2318
one_file: bool,
19+
bundle_third_party: bool,
2420
):
2521
pyinstaller_options = [
2622
"--noconfirm",
@@ -32,7 +28,19 @@ def build_macos(
3228
else:
3329
pyinstaller_options += ["--onedir"]
3430

35-
options = pyinstaller_options + added_data_options
31+
if bundle_third_party:
32+
added_binaries = [
33+
("/usr/local/bin/wkhtmltopdf", "."),
34+
]
35+
added_binary_options = [
36+
f"--add-binary={src}:{dst}" for src, dst in added_binaries
37+
]
38+
else:
39+
added_binary_options = []
40+
41+
added_data_options = [f"--add-data={src}:{dst}" for src, dst in added_files]
42+
43+
options = pyinstaller_options + added_data_options + added_binary_options
3644

3745
logger.info(f"calling pyinstaller with options: {' '.join(options)}")
3846
subprocess.call(
@@ -55,6 +63,8 @@ def build_linux(
5563
else:
5664
pyinstaller_options += ["--onedir"]
5765

66+
added_data_options = [f"--add-data={src}:{dst}" for src, dst in added_files]
67+
5868
options = pyinstaller_options + added_data_options
5969

6070
logger.info(f"calling pyinstaller with options: {' '.join(options)}")
@@ -79,6 +89,8 @@ def build_windows(
7989
else:
8090
pyinstaller_options += ["--onedir"]
8191

92+
added_data_options = [f"--add-data={src};{dst}" for src, dst in added_files]
93+
8294
options = pyinstaller_options + added_data_options
8395

8496
logger.info(f"calling pyinstaller with options: {' '.join(options)}")
@@ -95,6 +107,9 @@ def main(
95107
one_file: bool = typer.Option(
96108
False, "--one-file", "-f", help="Build a single file executable"
97109
),
110+
bundle_third_party: bool = typer.Option(
111+
True, "--bundle-third-party", "-b", help="Bundle third party libraries"
112+
),
98113
):
99114
if install_dir:
100115
logger.info(f"removing app from {install_dir}")
@@ -110,6 +125,7 @@ def main(
110125
logger.info("building for macOS")
111126
build_macos(
112127
one_file=one_file,
128+
bundle_third_party=bundle_third_party,
113129
)
114130
elif sys.platform.startswith("win"):
115131
logger.info("building for Windows")

tuttle/rendering.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
"""Document rendering."""
22

3+
import os
4+
import sys
35
from pathlib import Path
46
import shutil
57
import glob
68

79
import jinja2
810
from babel.numbers import format_currency
911
import pandas
10-
import pdfkit
1112
from loguru import logger
1213

14+
# pdfkit needs wkhtmltopdf to be installed
15+
if getattr(sys, "frozen", False):
16+
os.environ["PATH"] = sys._MEIPASS + os.pathsep + os.environ["PATH"]
17+
import pdfkit
18+
19+
1320
from .model import User, Invoice, Timesheet, Project
1421
from .view import Timeline
1522

0 commit comments

Comments
 (0)