-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpyoxidizer.bzl
121 lines (101 loc) · 4.96 KB
/
pyoxidizer.bzl
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
# This file defines how PyOxidizer application building and packaging is
# performed. See PyOxidizer's documentation at
# https://pyoxidizer.readthedocs.io/en/stable/ for details of this
# configuration file format.
def resource_callback(policy, resource):
if type(resource) in ("File"):
if "pywin" in resource.path or "pypiwin" in resource.path:
resource.add_location = "filesystem-relative:lib"
resource.add_include = True
if type(resource) in ("PythonExtensionModule"):
if resource.name in ["_ssl", "win32.win32file", "win32.win32pipe"]:
resource.add_location = "filesystem-relative:lib"
resource.add_include = True
elif type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"):
if resource.name in ["pywin32_bootstrap", "pythoncom", "pypiwin32", "pywin32", "pythonwin", "win32", "win32com", "win32comext"]:
resource.add_location = "filesystem-relative:lib"
resource.add_include = True
def make_exe():
dist = default_python_distribution()
policy = dist.make_python_packaging_policy()
policy.allow_in_memory_shared_library_loading = True
policy.bytecode_optimize_level_one = True
policy.include_non_distribution_sources = False
policy.include_test = False
policy.resources_location = "in-memory"
policy.resources_location_fallback = "filesystem-relative:prefix"
python_config = dist.make_python_interpreter_config()
python_config.run_command = "from getdeck.__main__ import main; main()"
exe = dist.to_python_executable(
name="deck",
packaging_policy=policy,
config=python_config,
)
# linux, mac
exe.add_python_resources(exe.read_package_root(CWD, ["getdeck"]))
exe.add_python_resources(exe.pip_install(["--no-deps", "docker==6.0.0"]))
exe.add_python_resources(exe.pip_install(["--no-binary", "pydantic", "certifi==2022.06.15", "PyYAML", "pydantic", "kubernetes", "beiboot"]))
exe.add_python_resources(exe.pip_install(["semantic-version==2.9.0", "GitPython==3.1.27", "python-hosts==1.0.3"]))
exe.add_python_resources(exe.pip_install(["cli-tracker"]))
return exe
def make_win_exe():
dist = default_python_distribution()
policy = dist.make_python_packaging_policy()
policy.allow_in_memory_shared_library_loading = True
policy.bytecode_optimize_level_one = True
policy.extension_module_filter = "all"
policy.include_file_resources = True
policy.include_test = False
policy.resources_location = "in-memory"
policy.resources_location_fallback = "filesystem-relative:lib"
policy.allow_files = True
policy.file_scanner_emit_files = True
policy.register_resource_callback(resource_callback)
python_config = dist.make_python_interpreter_config()
python_config.module_search_paths = ["$ORIGIN", "$ORIGIN/lib"]
python_config.run_command = "from getdeck.__main__ import main; main()"
exe = dist.to_python_executable(
name="deck",
packaging_policy=policy,
config=python_config,
)
# windows
exe.add_python_resources(exe.read_package_root(CWD, ["getdeck"]))
exe.add_python_resources(exe.pip_install(["--no-deps", "docker==6.0.0"]))
exe.add_python_resources(exe.pip_install(["--no-binary", "pydantic", "certifi==2022.06.15", "PyYAML", "pydantic", "kubernetes", "beiboot"]))
exe.add_python_resources(exe.pip_install(["semantic-version==2.9.0", "GitPython==3.1.27", "python-hosts==1.0.3"]))
exe.add_python_resources(exe.pip_install(["pywin32"]))
exe.add_python_resources(exe.pip_install(["cli-tracker"]))
exe.windows_runtime_dlls_mode = "always"
return exe
def make_embedded_resources(exe):
return exe.to_embedded_resources()
def make_install(exe):
# Create an object that represents our installed application file layout.
files = FileManifest()
# Add the generated executable to our install layout in the root directory.
files.add_python_resource(".", exe)
return files
def make_msi(exe):
# See the full docs for more. But this will convert your Python executable
# into a `WiXMSIBuilder` Starlark type, which will be converted to a Windows
# .msi installer when it is built.
return exe.to_wix_msi_builder(
# Simple identifier of your app.
"myapp",
# The name of your application.
"My Application",
# The version of your application.
"1.0",
# The author/manufacturer of your application.
"Alice Jones"
)
# Tell PyOxidizer about the build targets defined above.
register_target("exe", make_exe)
register_target("winexe", make_win_exe)
register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True)
register_target("wininstall", make_install, depends=["winexe"], default=True)
register_target("msi_installer", make_msi, depends=["winexe"])
# Resolve whatever targets the invoker of this configuration file is requesting
# be resolved.
resolve_targets()