Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/hello_python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def build(self) -> Path:
"pyinstaller",
"--noconfirm",
"--clean",
"--onefile",
"--onedir",
Comment thread
RaymondSu-Public-Base marked this conversation as resolved.
Resolved
"--windowed",
"--hidden-import",
"PyQt5.sip",
"--collect-all",
"PyQt5",
"--name",
self.name,
"--distpath",
Expand All @@ -69,9 +69,9 @@ def build(self) -> Path:
raise RuntimeError(f"Build failed with exit code {result.returncode}")

if platform.system() == "Windows":
exe = self.dist_path / f"{self.name}.exe"
exe = self.dist_path / self.name / f"{self.name}.exe"
else:
exe = self.dist_path / self.name
exe = self.dist_path / self.name / self.name

print(f"Built executable: {exe}")
return exe
Expand Down
42 changes: 38 additions & 4 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def test_build_windows_executable(self, tmp_path: Path) -> None:
"PyInstaller",
"--noconfirm",
"--clean",
"--onefile",
"--onedir",
"--windowed",
"--hidden-import",
"PyQt5.sip",
"--collect-all",
"PyQt5",
"--name",
"hello-python-windows",
"--distpath",
Expand All @@ -104,6 +104,40 @@ def test_build_windows_executable(self, tmp_path: Path) -> None:
cwd=str(ROOT_DIR),
)
assert result.returncode == 0, f"Build failed:\n{result.stderr}"
exe = dist_path / "hello-python-windows.exe"
exe = dist_path / "hello-python-windows" / "hello-python-windows.exe"
assert exe.is_file(), "Executable not produced"
assert exe.stat().st_size > 0, "Executable is empty"

@pytest.mark.slow
@pytest.mark.skipif(platform.system() != "Linux", reason="Linux-only build test")
def test_build_linux_executable(self, tmp_path: Path) -> None:
dist_path = tmp_path / "dist" / "linux"
result = subprocess.run(
[
sys.executable,
"-m",
"PyInstaller",
"--noconfirm",
"--clean",
"--onedir",
"--windowed",
"--collect-all",
"PyQt5",
"--name",
"hello-python-linux",
"--distpath",
str(dist_path),
"--workpath",
str(tmp_path / "build"),
"--specpath",
str(tmp_path / "spec"),
str(ROOT_DIR / "src" / "hello_python" / "main.py"),
],
capture_output=True,
text=True,
cwd=str(ROOT_DIR),
)
assert result.returncode == 0, f"Build failed:\n{result.stderr}"
exe = dist_path / "hello-python-linux" / "hello-python-linux"
assert exe.is_file(), "Executable not produced"
assert exe.stat().st_size > 0, "Executable is empty"
14 changes: 9 additions & 5 deletions tests/test_build_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ def test_build_invokes_pyinstaller_with_correct_args(
builder = BuildExecutable(root_dir=tmp_path)
builder.dist_path.mkdir(parents=True)
if platform.system() == "Windows":
exe = builder.dist_path / f"{builder.name}.exe"
exe_dir = builder.dist_path / builder.name
exe_dir.mkdir(parents=True)
exe = exe_dir / f"{builder.name}.exe"
else:
exe = builder.dist_path / builder.name
exe_dir = builder.dist_path / builder.name
exe_dir.mkdir(parents=True)
exe = exe_dir / builder.name
exe.touch()

result = builder.build()
Expand All @@ -130,10 +134,10 @@ def test_build_invokes_pyinstaller_with_correct_args(
assert "pyinstaller" in cmd
assert "--noconfirm" in cmd
assert "--clean" in cmd
assert "--onefile" in cmd
assert "--onedir" in cmd
assert "--windowed" in cmd
assert "--hidden-import" in cmd
assert "PyQt5.sip" in cmd
assert "--collect-all" in cmd
assert "PyQt5" in cmd
assert str(builder.entry_point) in cmd

@patch("hello_python.build.subprocess.run")
Expand Down
Loading