I edited all of the system/shell commands in the server/server.py and server/utils.py files to use subprocess rather than os.system, and added conditional logic in most of the utility functions that made system changes to ensure that the correct commands are executed if the system is windows, etc.
for example, here's how the run_command_in_project_venv function was defined:
def run_command_in_project_venv(project_folder_path, command):
assert os.path.exists(
os.path.join(project_folder_path, "venv")
), f"Virtualenv does not exist in project folder: {project_folder_path}"
assert (
os.system(
f". {os.path.join(project_folder_path, 'venv', 'bin', 'activate')} && {command}"
)
== 0
)
and here's what it looks like now:
def run_command_in_project_venv(project_folder_path, command):
if os.name == "nt": # Check if running on Windows
venv_activate = os.path.join(project_folder_path, "venv", "Scripts", "activate.bat")
else:
venv_activate = os.path.join(project_folder_path, "venv", "bin", "activate")
assert os.path.exists(venv_activate), f"Virtualenv does not exist in project folder: {project_folder_path}"
if os.name == "nt":
command = f"call {venv_activate} && {command}"
else:
command = f". {venv_activate} && {command}"
# assert subprocess.call(command, shell=True) == 0
# Run the command using subprocess and capture stdout
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# Log the stdout
print(stdout.decode())
assert process.returncode == 0
I kept comments for all the previous system-level os.system commands for the sake of easily seeing what changed in the files.
what changed?
I edited all of the system/shell commands in the server/server.py and server/utils.py files to use subprocess rather than os.system, and added conditional logic in most of the utility functions that made system changes to ensure that the correct commands are executed if the system is windows, etc.
for example, here's how the
run_command_in_project_venv
function was defined:and here's what it looks like now:
I kept comments for all the previous system-level os.system commands for the sake of easily seeing what changed in the files.