Skip to content

Commit c14cced

Browse files
👷 [+ci] Update build scripts to produce working binary (#17)
2 parents bef720f + 31c562a commit c14cced

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

.github/workflows/CICD_impl.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ jobs:
6666
python-version: ${{ matrix.python_version }}
6767
enable-cache: true
6868

69+
- name: Install Dependencies
70+
run: uv sync --frozen
71+
6972
- name: Run pre-commit scripts
7073
run: uv run pre-commit run --verbose
7174

@@ -250,6 +253,9 @@ jobs:
250253
python-version: ${{ inputs.python_package_version }}
251254
enable-cache: true
252255

256+
- name: Install Dependencies
257+
run: uv sync --frozen
258+
253259
- name: Build Binary
254260
run: uv run python BuildBinary.py Build --verbose
255261

@@ -261,6 +267,8 @@ jobs:
261267
with:
262268
name: Binary.${{ matrix.os }}
263269
path: FileBackup-${{ env.PACKAGE_VERSION }}.*
270+
271+
# ----------------------------------------------------------------------
264272
validate_binary:
265273
needs: [python_package, build_binary]
266274

BuildBinary.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import os
22
import shutil
3+
import textwrap
4+
import uuid
35

46
from pathlib import Path
57
from typing import Annotated, Optional
68

79
import typer
810

11+
from dbrownell_Common.ContextlibEx import ExitStack
912
from dbrownell_Common import SubprocessEx
1013
from dbrownell_Common.Streams.DoneManager import DoneManager, Flags as DoneManagerFlags
14+
import inflect
1115
from typer.core import TyperGroup
1216

17+
import FileBackup
18+
1319

1420
# ----------------------------------------------------------------------
1521
class NaturalOrderGrouper(TyperGroup):
@@ -46,12 +52,49 @@ def Build(
4652
with DoneManager.CreateCommandLine(
4753
flags=DoneManagerFlags.Create(verbose=verbose, debug=debug),
4854
) as dm:
49-
command_line = "cxfreeze --script src/FileBackup/CommandLine/EntryPoint.py --target-name=FileBackup"
50-
51-
dm.WriteVerbose(f"Command line: {command_line}\n\n")
52-
53-
with dm.YieldStream() as stream:
54-
dm.result = SubprocessEx.Stream(command_line, stream)
55+
# inflect uses the typeguard library, which relies on inspect to read the source code of
56+
# inflect to enforce that arguments are the correct types when invoking functions. This
57+
# works fine when running the application normally, but does not work by default with
58+
# cx_Freeze because it does not include the source code of inflect in the built binary. This
59+
# means that typeguard can't determine the types of the arguments, which causes it to raise
60+
# an exception. The fix is to include the inflect source code in the built binary so that
61+
# typeguard can find the function's types and not raise an exception.
62+
inflect_filename = Path(inflect.__file__).relative_to(Path(__file__).parent)
63+
64+
configuration_filename = Path("setup{}.py".format(str(uuid.uuid4()).replace("-", "")))
65+
66+
configuration_filename.write_text(
67+
textwrap.dedent(
68+
f"""\
69+
from cx_Freeze import setup, Executable
70+
71+
setup(
72+
name = "FileBackup",
73+
version = "{FileBackup.__version__}",
74+
options = {{
75+
"build_exe": {{
76+
"include_files": [
77+
(r"{inflect_filename}", "lib/inflect/{inflect_filename.name}"),
78+
],
79+
"packages": []
80+
}},
81+
}},
82+
executables = [
83+
Executable(
84+
"src/FileBackup/CommandLine/EntryPoint.py",
85+
target_name="FileBackup",
86+
base=None,
87+
),
88+
],
89+
)
90+
""",
91+
),
92+
encoding="utf-8",
93+
)
94+
95+
with ExitStack(configuration_filename.unlink):
96+
with dm.YieldStream() as stream:
97+
dm.result = SubprocessEx.Stream(f'python "{configuration_filename}" build_exe', stream)
5598

5699

57100
# ----------------------------------------------------------------------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ keywords = [
2323
license = "MIT"
2424

2525
classifiers = [
26-
"Development Status :: 4 - Beta", # TODO
26+
"Development Status :: 4 - Beta",
2727
"Environment :: Console",
2828
"Intended Audience :: Developers",
2929
"Intended Audience :: End Users/Desktop",

0 commit comments

Comments
 (0)