-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpyoxidizer.bzl
73 lines (61 loc) · 2.45 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
def force_fs_libs(policy, resource):
for lib in ["certifi", "poetry-plugin-export"]:
if (
resource.name == lib or
resource.name.startswith("{}.".format(lib)) or (
hasattr(resource, "package") and
resource.package == lib
)
):
resource.add_location = "filesystem-relative:lib"
def make_exe():
dist = default_python_distribution(python_version="3.10")
policy = dist.make_python_packaging_policy()
policy.resources_location_fallback = "filesystem-relative:lib"
policy.register_resource_callback(force_fs_libs)
config = dist.make_python_interpreter_config()
config.module_search_paths = ["$ORIGIN/lib"]
config.run_module = "poetry.console.application"
exe = dist.to_python_executable(
name="poetry",
packaging_policy=policy,
config=config,
)
for resource in exe.pip_install(["./vendor/poetry"]):
# skip patched packages
if resource.name == "poetry.core" or resource.name.startswith("poetry.core."):
continue
for lib in ["virtualenv"]:
if (
resource.name == lib or
resource.name.startswith("{}.".format(lib)) or (
hasattr(resource, "package") and
resource.package == lib
)
):
continue
# skip wheels
if resource.name.endswith(".whl"):
continue
exe.add_python_resource(resource)
exe.add_python_resources(exe.read_package_root("vendor/poetry-core/src", ["poetry"]))
exe.add_python_resources(exe.pip_install(["-r", "vendor/poetry-core/vendors/deps.txt"]))
exe.add_python_resources(exe.pip_install(["./vendor/importlib_metadata"]))
exe.add_python_resources(exe.pip_install(["./vendor/lark"]))
for resource in exe.pip_install(["./vendor/virtualenv"]):
# skip wheels
if resource.name.endswith(".whl"):
continue
exe.add_python_resource(resource)
return exe
def make_embedded_resources(exe):
return exe.to_embedded_resources()
def make_install(exe):
files = FileManifest()
entrypoint = "."
files.add_python_resource(entrypoint, exe)
return files
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)
resolve_targets()