Skip to content

Commit

Permalink
pyproject.toml: add post-build hooks to relocate binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlettman committed Aug 17, 2024
1 parent 7d568fa commit 14b0faf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hooks/pyinstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import shutil
from pathlib import Path


def post_build(interface) -> None:
"""Pyinstaller post build hook. Relocate binary to root of dist directory."""

interface.write_line(" - <b>Relocating binaries</b>")
for script in interface.pyproject_data["tool"]["poetry-pyinstaller-plugin"]["scripts"]:
source = Path("dist", "pyinstaller", interface.platform, script)
destination = Path("dist", f"{script}")

if destination.exists():
shutil.rmtree(destination) # remove existing

shutil.move(f"{source}", f"{destination}")
interface.write_line(
f" - Updated "
f"<success>{source}</success> -> "
f"<success>{destination}</success>"
)

interface.write_line(" - <b>Cleaning</b>")
shutil.rmtree(Path("build"))
interface.write_line(" - Removed build directory")
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ version = "6.7.0"
# disable compression
disable-upx = true

# ran after all builds are done
post-build = "hooks.pyinstaller:post_build"

[tool.poetry-pyinstaller-plugin.scripts]
jockey = { source = "src/jockey/__main__.py", type = "onefile", bundle = false }

Expand Down

0 comments on commit 14b0faf

Please sign in to comment.