Skip to content

Commit

Permalink
Properly escape spaces in windows path
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Esser <[email protected]>
  • Loading branch information
florianesser-tng committed Dec 5, 2024
1 parent 457e5e2 commit 0d6d41f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions WebUI/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@ function spawnAPI(pythonExe: string, wordkDir: string, additionalEnvVariables: R
});

webProcess.stdout.on('data', (message) => {
if(message.startsWith('INFO')) {
if(message.toString().startsWith('INFO')) {
logger.info(`${message}`, 'ai-backend')
} else if (message.startsWith('WARN')) {
} else if (message.toString().startsWith('WARN')) {
logger.warn(`${message}`, 'ai-backend')
} else {
logger.error(`${message}`, 'ai-backend')
Expand Down
1 change: 1 addition & 0 deletions service/aipg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def get_support_graphics(env_type: str):
def call_subprocess(process_command: str) -> str:
args = shlex.split(process_command)
try:
logging.info(f"calling cmd process: {args}")
output = subprocess.check_output(args)
return output.decode("utf-8")
except subprocess.CalledProcessError as e:
Expand Down
25 changes: 16 additions & 9 deletions service/comfyui_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def _install_portable_git():
_fetch_portable_git(zipped_portable_git_target)
_unzip_portable_git(zipped_portable_git_target, git_target_dir)
assert is_git_installed(), "Failed to install git at expected location"
logging.info(f"successfully extracted git into {os.path.abspath(git_target_dir)}")
except Exception as e:
logging.error(f"failed to install git due to {e}. Cleaning up intermediate resources")
aipg_utils.remove_existing_filesystem_resource(zipped_portable_git_target)
Expand All @@ -48,8 +49,8 @@ def _fetch_portable_git(seven_zipped_portable_git_target):
for chunk in response.iter_content(chunk_size=1024):
file.write(chunk)
else:
logging.error(f"Failed fetching resources")
#TODO: raise exception
logging.error(f"Failed fetching resources from {git_download_url}")
raise Exception(f"fetching {git_download_url} failed with response: {response}")
except Exception as e:
logging.error(f"Failed to fetch portable git from ${git_download_url} with error {e}")
aipg_utils.remove_existing_filesystem_resource(seven_zipped_portable_git_target)
Expand All @@ -63,12 +64,13 @@ def get_unzipping_command():
logging.debug("using system tar to unzip.")
return f"tar -C {target_dir} -xf {zipped_git_path}"
except Exception:
logging.warn("falling back to powershell command to extract zip, as tar not in PATH")
logging.warning("falling back to powershell command to extract zip, as tar not in PATH")
return f"powershell -command 'Expand-Archive' -Force {zipped_git_path} {target_dir}"
try:
if not os.path.exists(zipped_git_path):
os.makedirs(zipped_git_path, exist_ok=True)
if not os.path.exists(target_dir):
os.makedirs(target_dir, exist_ok=True)
aipg_utils.call_subprocess(get_unzipping_command())
logging.info("Unzipped git successfully")
except Exception as e:
aipg_utils.remove_existing_filesystem_resource(zipped_git_path)
aipg_utils.remove_existing_filesystem_resource(target_dir)
Expand All @@ -78,13 +80,18 @@ def _install_git_repo(git_repo_url: str, target_dir: str):
try:
aipg_utils.remove_existing_filesystem_resource(target_dir)
aipg_utils.call_subprocess(f"{service_config.git.get('exePath')} clone {git_repo_url} {target_dir}")
logging.info(f"Cloned {git_repo_url} into {target_dir}")
except Exception as e:
logging.warning(f"git cloned failed with exception {e}. Cleaning up failed resources.")
aipg_utils.remove_existing_filesystem_resource(target_dir)
raise e

def _install_pip_requirements(requirements_txt_path: str):
if (os.path.exists(requirements_txt_path)):
aipg_utils.call_subprocess(f"{sys.executable} -m pip install -r {requirements_txt_path}")
logging.info(f"installing python requirements from {requirements_txt_path} using {sys.executable}")
if os.path.exists(requirements_txt_path):
python_exe_callable_path = "'" + str(sys.executable) + "'" # this returns the abs path and may contain spaces. Escape the spaces with "ticks"
aipg_utils.call_subprocess(f"{python_exe_callable_path} -m pip install -r '{requirements_txt_path}'")
logging.info(f"python requirements installation completed.")

Check failure on line 94 in service/comfyui_downloader.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

service/comfyui_downloader.py:94:22: F541 f-string without any placeholders
else:
logging.warning(f"specified {requirements_txt_path} does not exist.")

Expand All @@ -100,6 +107,8 @@ def install_comfyUI() -> bool:
return True
except Exception as e:
logging.error(f"comfyUI installation failed due to {e}")
if os.path.exists(service_config.comfyUIRootPath):
aipg_utils.remove_existing_filesystem_resource(service_config.comfyUIRootPath)
raise e


Expand All @@ -118,8 +127,6 @@ def download_custom_node(node_repo_data: ComfyUICustomNodesGithubRepoId):

_install_git_repo(expected_git_url, expected_custom_node_path)
_install_pip_requirements(potential_node_requirements)
logging.error(f"Failed to install custom comfy node {node_repo_data.username}/{node_repo_data.reponame} due to {e}")

return
except Exception as e:
logging.error(f"Failed to install custom comfy node {node_repo_data.username}/{node_repo_data.reponame} due to {e}")
Expand Down

0 comments on commit 0d6d41f

Please sign in to comment.