Skip to content

Commit

Permalink
Add route to save uv-install settings and call uv install
Browse files Browse the repository at this point in the history
  • Loading branch information
yoland68 committed Sep 24, 2024
1 parent 326a7f1 commit 147b51a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
6 changes: 4 additions & 2 deletions glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ def write_config():
'downgrade_blacklist': get_config()['downgrade_blacklist'],
'security_level': get_config()['security_level'],
'skip_migration_check': get_config()['skip_migration_check'],
'use_uv_install': get_config()['use_uv_install'],
}
with open(config_path, 'w') as configfile:
config.write(configfile)
Expand Down Expand Up @@ -1507,7 +1508,8 @@ def read_config():
'model_download_by_agent': default_conf['model_download_by_agent'].lower() == 'true' if 'model_download_by_agent' in default_conf else False,
'downgrade_blacklist': default_conf['downgrade_blacklist'] if 'downgrade_blacklist' in default_conf else '',
'skip_migration_check': default_conf['skip_migration_check'].lower() == 'true' if 'skip_migration_check' in default_conf else False,
'security_level': security_level
'security_level': security_level,
'use_uv_install': default_conf['use_uv_install'].lower() == 'true' if 'use_uv_install' in default_conf else False,
}

except Exception:
Expand All @@ -1526,6 +1528,7 @@ def read_config():
'downgrade_blacklist': '',
'skip_migration_check': False,
'security_level': 'normal',
'use_uv_install': False,
}


Expand Down Expand Up @@ -1652,7 +1655,6 @@ def __win_check_git_pull(path):


def execute_install_script(url, repo_path, lazy_mode=False, instant_execution=False, no_deps=False):
# import ipdb; ipdb.set_trace()
install_script_path = os.path.join(repo_path, "install.py")
requirements_path = os.path.join(repo_path, "requirements.txt")

Expand Down
37 changes: 33 additions & 4 deletions glob/manager_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,34 @@ async def install_custom_node(request):
res = await core.unified_manager.install_by_id(node_name, version_spec, json_data['channel'], json_data['mode'], return_postinstall=skip_post_install, no_deps=no_deps)
# discard post install if skip_post_install mode

if no_deps:
core.call_cli_dependencies()

if res not in ['skip', 'enable', 'install-git', 'install-cnr', 'switch-cnr']:
return web.Response(status=400)

return web.Response(status=200)

@routes.post("/customnode/uv-install-deps")
async def uv_install_deps(request):
if not is_allowed_security_level('middle'):
print(SECURITY_MESSAGE_MIDDLE_OR_BELOW)
return web.Response(status=403)

json_data = await request.json()
node_id = json_data.get('id')
pip_dependencies = json_data.get('pip', [])

if not pip_dependencies:
return web.Response(status=400, text="No dependencies provided")

try:
result = core.call_cli_dependencies()
if result:
return web.Response(status=200, text="Dependencies installed successfully")
else:
return web.Response(status=500, text="Failed to install dependencies")
except Exception as e:
return web.Response(status=500, text=f"Error installing dependencies: {str(e)}")



@routes.post("/customnode/fix")
async def fix_custom_node(request):
Expand Down Expand Up @@ -895,6 +915,16 @@ async def channel_url_list(request):

return web.Response(status=200)

@routes.get("/manager/uv-install")
async def uv_install(request):
if "value" in request.rel_url.query:
value = request.rel_url.query['value'].lower() == 'true'
core.get_config()['use_uv_install'] = value
core.write_config()
return web.Response(status=200)
else:
return web.json_response({"use_uv_install": core.get_config().get('use_uv_install', False)}, status=200)


def add_target_blank(html_text):
pattern = r'(<a\s+href="[^"]*"\s*[^>]*)(>)'
Expand Down Expand Up @@ -959,7 +989,6 @@ def sanitize(data):


async def _confirm_try_install(sender, custom_node_url, msg):
import pdb; pdb.set_trace()
json_obj = await core.get_data_by_mode('default', 'custom-node-list.json')

sender = manager_util.sanitize_tag(sender)
Expand Down
29 changes: 29 additions & 0 deletions js/comfyui-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ class ManagerMenuDialog extends ComfyDialog {
uc_checkbox_text.style.cursor = "pointer";
this.update_check_checkbox.checked = true;

this.use_uv_install_checkbox = $el("input", { type: 'checkbox', id: "use_uv_install" }, [])
const use_uv_checkbox_text = $el("label", { for: "use_uv_install" }, [" Use UV Install"])
use_uv_checkbox_text.style.color = "var(--fg-color)";
use_uv_checkbox_text.style.cursor = "pointer";
this.use_uv_install_checkbox.checked = false;

// db mode
this.datasrc_combo = document.createElement("select");
this.datasrc_combo.setAttribute("title", "Configure where to retrieve node/model information. If set to 'local,' the channel is ignored, and if set to 'channel (remote),' it fetches the latest information each time the list is opened.");
Expand Down Expand Up @@ -809,10 +815,33 @@ class ManagerMenuDialog extends ComfyDialog {

}
});
api.fetchApi('/manager/uv-install')
.then(response => response.json())
.then(data => {
this.use_uv_install_checkbox.checked = data.use_uv_install;

this.use_uv_install_checkbox.addEventListener('change', function (event) {
api.fetchApi(`/manager/uv-install?value=${event.target.checked}`)
.then(response => {
if (response.status !== 200) {
console.error("Failed to update UV Install setting");
}
})
.catch(error => {
console.error("Error updating UV Install setting:", error);
});
});


})
.catch(error => {
console.error("Error fetching initial UV Install setting:", error);
});


return [
$el("div", {}, [this.update_check_checkbox, uc_checkbox_text]),
$el("div", {}, [this.use_uv_install_checkbox, use_uv_checkbox_text]),
$el("br", {}, []),
this.datasrc_combo,
channel_combo,
Expand Down
8 changes: 7 additions & 1 deletion js/custom-nodes-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ export class CustomNodesManager {

const res = await api.fetchApi(`/customnode/${api_mode}`, {
method: 'POST',
body: JSON.stringify({ ...data, noDeps: true })
body: JSON.stringify(manager_instance.use_uv_install_checkbox.checked ? { ...data, noDeps: true } : data)
});

if (res.error) {
Expand Down Expand Up @@ -1257,6 +1257,12 @@ export class CustomNodesManager {

}

if (manager_instance.use_uv_install_checkbox.checked) {
const res = await api.fetchApi(`/customnode/uv-install-deps`, {
method: 'POST',
});
}

target.classList.remove("cn-btn-loading");

if (errorMsg) {
Expand Down

0 comments on commit 147b51a

Please sign in to comment.