diff --git a/src/hello_python/build.py b/src/hello_python/build.py index 3368ad8..d68331c 100644 --- a/src/hello_python/build.py +++ b/src/hello_python/build.py @@ -50,10 +50,10 @@ def build(self) -> Path: "pyinstaller", "--noconfirm", "--clean", - "--onefile", + "--onedir", "--windowed", - "--hidden-import", - "PyQt5.sip", + "--collect-all", + "PyQt5", "--name", self.name, "--distpath", @@ -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 diff --git a/tests/test_build.py b/tests/test_build.py index 2da74fa..f0f4f24 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -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", @@ -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" diff --git a/tests/test_build_class.py b/tests/test_build_class.py index 2408147..16f8f5c 100644 --- a/tests/test_build_class.py +++ b/tests/test_build_class.py @@ -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() @@ -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")