Skip to content

Instantly share code, notes, and snippets.

@wgordon17
Created December 14, 2022 02:41
Show Gist options
  • Save wgordon17/f37e0500ba9998d0369d1c91ee1e3083 to your computer and use it in GitHub Desktop.
Save wgordon17/f37e0500ba9998d0369d1c91ee1e3083 to your computer and use it in GitHub Desktop.
def make_exe():
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_config_type_python_distribution.html
dist = default_python_distribution()
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_config_type_python_packaging_policy.html
policy = dist.make_python_packaging_policy()
policy.resources_location_fallback = "filesystem-relative:lib"
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_config_type_python_interpreter_config.html
python_config = dist.make_python_interpreter_config()
python_config.run_command = "import mu_repo; mu_repo.main()"
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_config_type_python_executable.html
exe = dist.to_python_executable(
name="mu",
packaging_policy=policy,
config=python_config,
)
# Workaround for __file__ usage
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_packaging_additional_files.html#installing-classified-resources-on-the-filesystem
for resource in exe.pip_download(["mu-repo==1.8.*"]):
resource.add_location = "filesystem-relative:lib"
exe.add_python_resource(resource)
return exe
def make_embedded_resources(exe):
# https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_config_type_python_embedded_resources.html
return exe.to_embedded_resources()
def make_install(exe):
# https://pyoxidizer.readthedocs.io/en/stable/tugger_starlark_type_file_manifest.html
files = FileManifest()
files.add_python_resource(".", 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment