-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyoxidizer.bzl
85 lines (56 loc) · 2.82 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
# 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.
PYOXIDIZER_BUILD_DIR = VARS.get("PYOXIDIZER_BUILD_DIR", "build")
# Configuration files consist of functions which define build "targets."
# This function creates a Python executable and installs it in a destination
# directory.
def make_exe():
dist = default_python_distribution()
policy = dist.make_python_packaging_policy()
policy.allow_files = True
policy.extension_module_filter = "all"
policy.include_distribution_sources = True
policy.include_distribution_resources = False
policy.include_test = False
policy.resources_location = "in-memory"
policy.resources_location_fallback = "filesystem-relative:lib"
python_config = dist.make_python_interpreter_config()
# Automatically calls `multiprocessing.set_start_method()` with an
# appropriate value when OxidizedFinder imports the `multiprocessing`
# module.
python_config.multiprocessing_start_method = 'auto'
# In version 0.19, there is a bug in the handling of the 'spawn' start method.
# This should be fixed in future versions but for now, I will call 'freeze_support'
# myself in the python code by using a different entry point for pyoxidizer.
python_config.multiprocessing_auto_dispatch = False
# Evaluate a string as Python code when the interpreter starts.
python_config.run_command = "from app import pyoxidizer_main; pyoxidizer_main()"
# Produce a PythonExecutable from a Python distribution, embedded
# resources, and other options. The returned object represents the
# standalone executable that will be built.
exe = dist.to_python_executable(
name="monopoly",
packaging_policy=policy,
config=python_config,
)
exe.add_python_resources(exe.pip_install(["--use-pep517", CWD]))
exe.add_python_resources(exe.pip_install(["--use-pep517", "-r", "requirements-runtime.txt"]))
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
# Tell PyOxidizer about the build targets defined above.
register_target("exe", make_exe)
register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True)
register_target("install", make_install, depends=["exe"], default=True)
set_build_path(CWD + "/" + PYOXIDIZER_BUILD_DIR)
# Resolve whatever targets the invoker of this configuration file is requesting
# be resolved.
resolve_targets()