From 2b5b58b11e70d37a30b8b471fdaef5e8e5f6a3bb Mon Sep 17 00:00:00 2001 From: dabecart Date: Mon, 12 Aug 2024 22:52:32 +0200 Subject: [PATCH] Fixed error that couldn't let linux run the program --- README.md | 20 ++++++++++++++++++-- src/BuildWidget.py | 2 ++ src/DataFields.py | 31 +++++++++++++++++++++---------- src/TestWidget.py | 4 +++- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 60446a0..d29d2ac 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ This project uses the following libraries: - To export test cases to `.xlsl` files I use [openpyxl](https://openpyxl.readthedocs.io/en/stable/), version 3.1.5. - To bundle the program as an executable file: [PyInstaller](https://pyinstaller.org/en/stable/), version 6.10.0. +You can use this command to install everything: + +``` +$ python3 -m pip install PyQt6 pyqtdarktheme openpyxl pyinstaller +``` + The project was built and tested on Python 3.10.8 64-bits. # To bundle as an executable @@ -38,7 +44,17 @@ The project was built and tested on Python 3.10.8 64-bits. Run the following: ``` -pyinstaller --onefile -w -i res/Logo.ico -n VVT src/Main.py +pyinstaller --onefile -w -i res/Logo.ico -n VVT src/Main.py --exclude PySide6 +``` + +The last exclude is optional, it's in case you also have installed PySide6 on your environment. + +# Developing on Linux + +To run the Python program in Linux (WSL), I had to install the following packages: + +``` +$ apt-get install ffmpeg libsm6 libxext6 libgl1-mesa-dev ``` -*This is a work in progress.* \ No newline at end of file +*This project is a work in progress.* \ No newline at end of file diff --git a/src/BuildWidget.py b/src/BuildWidget.py index 462dcbe..312477b 100644 --- a/src/BuildWidget.py +++ b/src/BuildWidget.py @@ -191,6 +191,8 @@ def onException(e: Exception): for arg in e.cmd: detailMessage += str(arg) + " " detailMessage += f'\nReturn code: {e.returncode}\nError output: {e.stderr.decode("utf-8")}' + else: + detailMessage += str(e) QMessageBox.critical(self, 'Fatal error while running test', f'A fatal error occurred. {detailMessage}') diff --git a/src/DataFields.py b/src/DataFields.py index 5d0c950..d53a090 100644 --- a/src/DataFields.py +++ b/src/DataFields.py @@ -19,6 +19,7 @@ from time import perf_counter from ast import literal_eval from re import sub +import os from datetime import datetime @@ -279,20 +280,30 @@ def test(self): # May throw a CalledProcessError exception in case the command is not OK. def _execute(self, resultOutputSave): commandArgs = shlex.split(self.runcode) - # So that the windowed application doesn't open a terminal to run the code. + # So that the windowed application doesn't open a terminal to run the code on Windows (nt). # Taken from here: # https://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/ - startupInfo = subprocess.STARTUPINFO() - startupInfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + if os.name == 'nt': + startupInfo = subprocess.STARTUPINFO() + startupInfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + for _ in range(self.repetitions): tOfExec = datetime.now().strftime("%d/%m/%Y %H:%M:%S.%f") - startTime = perf_counter() - runResult = subprocess.run(commandArgs, - stdout = subprocess.PIPE, - stderr = subprocess.PIPE, - cwd = Item.runningDirectory, - startupinfo = startupInfo) - executionTime = perf_counter() - startTime + if os.name == 'nt': + startTime = perf_counter() + runResult = subprocess.run(commandArgs, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + cwd = Item.runningDirectory, + startupinfo = startupInfo) + executionTime = perf_counter() - startTime + else: + startTime = perf_counter() + runResult = subprocess.run(commandArgs, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + cwd = Item.runningDirectory) + executionTime = perf_counter() - startTime # Taken from here: # https://stackoverflow.com/questions/24849998/how-to-catch-exception-output-from-python-subprocess-check-output diff --git a/src/TestWidget.py b/src/TestWidget.py index 8e2ca44..a1890af 100644 --- a/src/TestWidget.py +++ b/src/TestWidget.py @@ -164,7 +164,9 @@ def onException(e: Exception): for arg in e.cmd: detailMessage += str(arg) + " " detailMessage += f'\nReturn code: {e.returncode}\nError output: {e.stderr.decode("utf-8")}' - + else: + detailMessage += str(e) + QMessageBox.critical(self, 'Fatal error while running test', f'A fatal error occurred. {detailMessage}')