1+ import os
12import queue
23import shutil
34import subprocess
5+ import sys
46import threading
57import typing
8+ from pathlib import Path
69from queue import Queue
710from threading import Thread
811
912from PySide6 .QtCore import QTimer
1013from PySide6 .QtWidgets import QTextEdit , QWidget
1114from 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
1420class 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