ComfyWorkflows / ComfyUI-Launcher

Run any ComfyUI workflow w/ ZERO setup.
GNU Affero General Public License v3.0
541 stars 61 forks source link

(review required) windows support added #3

Closed dylanintech closed 7 months ago

dylanintech commented 7 months ago

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:

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.

thecooltechguy commented 7 months ago

I've pushed some commits to clean up stuff & fix some bugs

thecooltechguy commented 7 months ago

Merged this into #5 , so closing this