Skip to content

Commit 1b3f884

Browse files
committed
Refactor
Refactor
1 parent ea983b4 commit 1b3f884

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

automation_editor/utils/exception/exception_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# ui exception
1919
wrong_test_data_format_exception_tag: str = "get the wrong test data format"
2020
# exec exception
21-
exec_error: str = "ITE exec error"
21+
exec_error: str = "AutomationEditor exec error"
2222
file_not_fond_error: str = "File not found"
2323
compiler_not_found_error: str = "Compiler not found"
2424
not_install_package_error: str = "not install required package"

automation_editor/utils/test_executor/task_process_manager.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import os
12
import queue
23
import shutil
34
import subprocess
5+
import sys
46
import threading
57
import typing
8+
from pathlib import Path
69
from queue import Queue
710
from threading import Thread
811

912
from PySide6.QtCore import QTimer
1013
from PySide6.QtWidgets import QTextEdit, QWidget
1114
from je_editor import error_color, output_color
1215

16+
from automation_editor.utils.exception.exception_tags import compiler_not_found_error
17+
from automation_editor.utils.exception.exceptions import ITEExecException
18+
1319

1420
class TaskProcessManager(object):
1521
def __init__(
@@ -37,9 +43,31 @@ def __init__(
3743

3844
def start_test_process(self, package: str, exec_str: str):
3945
# try to find file and compiler
40-
compiler_path = shutil.which("python")
46+
if sys.platform in ["win32", "cygwin", "msys"]:
47+
venv_path = Path(os.getcwd() + "/venv/Scripts")
48+
else:
49+
venv_path = Path(os.getcwd() + "/venv/bin")
50+
if venv_path.is_dir() and venv_path.exists():
51+
compiler_path = shutil.which(
52+
cmd="python3",
53+
path=str(venv_path)
54+
)
55+
else:
56+
compiler_path = shutil.which(cmd="python3")
57+
if compiler_path is None:
58+
if sys.platform in ["win32", "cygwin", "msys"]:
59+
venv_path = Path(os.getcwd() + "/venv/Scripts")
60+
else:
61+
venv_path = Path(os.getcwd() + "/venv/bin")
62+
if venv_path.is_dir() and venv_path.exists():
63+
compiler_path = shutil.which(
64+
cmd="python",
65+
path=str(venv_path)
66+
)
67+
else:
68+
compiler_path = shutil.which(cmd="python")
4169
if compiler_path is None:
42-
compiler_path = shutil.which("python3")
70+
raise ITEExecException(compiler_not_found_error)
4371
self.process = subprocess.Popen(
4472
[
4573
compiler_path,
@@ -110,6 +138,8 @@ def exit_program(self):
110138
self.print_and_clear_queue()
111139
if self.process is not None:
112140
self.process.terminate()
141+
print(f"Task exit with code {self.process.returncode}")
142+
self.process = None
113143

114144
def print_and_clear_queue(self):
115145
try:
@@ -123,7 +153,6 @@ def print_and_clear_queue(self):
123153
if std_err:
124154
self.code_result.append(std_err)
125155
self.code_result.setTextColor(output_color)
126-
print(f"Task exit with code {self.process.returncode}")
127156
except queue.Empty:
128157
pass
129158
self.run_output_queue = queue.Queue()

0 commit comments

Comments
 (0)