Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,67 @@ whatever value a request carried and wrote it to `config.ini`. They answer 400
for a value that is not one of those the Manager's menu offers, and for a JSON
body without a `value`, which ended with status 500.

### A snapshot restore reports what failed, and restores the pinned commit

The summary of a restore listed a node pack as `INSTALLED`, `DISABLED` or
`ENABLED` without looking at the result of the step: a clone that failed, for
example because the directory already existed or the url could not be reached,
was `INSTALLED`. A step that fails is now listed as `FAILED`, and the Manager
itself is no longer listed as `DISABLED`. A registry that cannot be reached
ended the restore at the first node pack to install from it, and so did a
node pack whose directory could not be moved to disable or enable it; such a
node pack is listed as `FAILED`, and the restore goes on.

A git node pack that the restore had to clone stayed at the newest commit. It
is checked out at the commit of the snapshot, and its install script runs
after that. An installed git node pack that the registry does not know was
checked out only when cm-cli was run from `custom_nodes`, as a scheduled
restore does; it is checked out from any directory. The submodules of a git
node pack are brought to the commits that the commit of the snapshot names; a
submodule that was never fetched is fetched only when the node pack itself is
checked out.

A registry node pack that the restore had to install was unpacked, but its
requirements were not installed and its install script did not run. The
restore now runs them, and lists the node pack as `FAILED` when they fail.

A requirement or an install script that failed was taken as done until the
next start: the next node pack that names the requirement skipped it, and
installing or fixing the node pack again did not run the script. Both are
tried again.

A snapshot recorded no commit for a git node pack whose refs were packed, as
after `git gc`. The commit is read from `packed-refs` too. A `HEAD` that is
not UTF-8 raised an error where the commit of a node pack is read; the commit
of such a pack is now unknown.

### `git_exe` chooses the git executable

The path set as `git_exe` in `config.ini` was read but not used: git commands
kept running the `git` found on `PATH`. The Manager, cm-cli and the git helper
now run the configured executable, and it no longer has to be on `PATH`: the
Manager also starts when the only git is the one named by `git_exe`.

A value that is not a working git is reported in the log, and the default git
is used. The value is read as it is written: with a `%` in it, as in a path
of Windows, the Manager read every setting of `config.ini` as its default.
`git_exe` is used only when the configuration file is in a protected
directory, that is with a ComfyUI that has the System User API.

### Install requests with an unusable body are answered with 400

`/customnode/install/git_url` and `/customnode/install/pip` answered 500 when
the JSON body was not an object, or when `url` or `packages` was not a string.
They answer 400, as they do for a missing field.

### A scheduled snapshot restore works with `--base-directory`

With `--base-directory`, where `custom_nodes` is not inside the ComfyUI
directory, a snapshot restore scheduled for the next start failed with
`ModuleNotFoundError: No module named 'utils'`, and the request was dropped.
The restore now gets the path of ComfyUI, and the user directory and
`custom_nodes` directory the server uses.

### Console messages show paths, URLs and package names as they are

Manager printed many of its messages through rich, which reads square
Expand Down
39 changes: 20 additions & 19 deletions cm-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,26 @@ def set_no_deps(self, no_deps):
self.no_deps = no_deps

def set_user_directory(self, user_directory):
if user_directory is None:
return

extra_model_paths_yaml = os.path.join(user_directory, 'extra_model_paths.yaml')
if os.path.exists(extra_model_paths_yaml):
utils.extra_config.load_extra_path_config(extra_model_paths_yaml)

core.update_user_directory(user_directory)

if os.path.exists(core.manager_pip_overrides_path):
with open(core.manager_pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file:
cm_global.pip_overrides = json.load(json_file)

if os.path.exists(core.manager_pip_blacklist_path):
with open(core.manager_pip_blacklist_path, 'r', encoding="UTF-8", errors="ignore") as f:
for x in f.readlines():
y = x.strip()
if y != '':
cm_global.pip_blacklist.add(y)
if user_directory is not None:
extra_model_paths_yaml = os.path.join(user_directory, 'extra_model_paths.yaml')
if os.path.exists(extra_model_paths_yaml):
utils.extra_config.load_extra_path_config(extra_model_paths_yaml)

core.update_user_directory(user_directory)

if os.path.exists(core.manager_pip_overrides_path):
with open(core.manager_pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file:
cm_global.pip_overrides = json.load(json_file)

if os.path.exists(core.manager_pip_blacklist_path):
with open(core.manager_pip_blacklist_path, 'r', encoding="UTF-8", errors="ignore") as f:
for x in f.readlines():
y = x.strip()
if y != '':
cm_global.pip_blacklist.add(y)

# the configuration of the user directory is known from here on
core.setup_git_executable()

def update_custom_nodes_dir(self, target_dir):
import folder_paths
Expand Down
10 changes: 8 additions & 2 deletions git_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,14 @@ def restore_pip_snapshot(pips, options):


def setup_environment():
if git_exe_path is not None:
git.Git().update_environment(GIT_PYTHON_GIT_EXECUTABLE=git_exe_path)
if git_exe_path:
default_git = git.Git.GIT_PYTHON_GIT_EXECUTABLE
try:
git.refresh(git_exe_path)
except Exception:
# a program that is not git fails in more ways than a path that cannot be run, and stays selected
git.Git.GIT_PYTHON_GIT_EXECUTABLE = default_git
print(f"[ComfyUI-Manager] `git_exe = {git_exe_path}` is not a working git executable. The default git is used.", file=sys.stderr)


setup_environment()
Expand Down
27 changes: 19 additions & 8 deletions glob/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,32 @@ def is_git_repo(path: str) -> bool:
def get_commit_hash(fullpath):
git_head = os.path.join(fullpath, '.git', 'HEAD')
if os.path.exists(git_head):
with open(git_head) as f:
# a ref can be named in any bytes, so the files are read as bytes and the names compared as they are
with open(git_head, 'rb') as f:
line = f.readline()

if line.startswith("ref: "):
ref = os.path.join(fullpath, '.git', line[5:].strip())
if line.startswith(b"ref: "):
ref_name = line[5:].strip()
ref = os.path.join(os.fsencode(fullpath), b'.git', ref_name)
if os.path.exists(ref):
with open(ref) as f2:
return f2.readline().strip()
else:
return "unknown"
with open(ref, 'rb') as f2:
return f2.readline().strip().decode('ascii', errors='replace')

# after `git pack-refs` or `git gc` the ref is a line of packed-refs
packed_refs = os.path.join(fullpath, '.git', 'packed-refs')
if os.path.exists(packed_refs):
with open(packed_refs, 'rb') as f2:
for packed in f2:
fields = packed.split()
if len(fields) == 2 and fields[1] == ref_name:
return fields[0].decode('ascii', errors='replace')

return "unknown"
else:
# detached HEAD: the file holds the sha followed by a newline;
# without the strip the pinned hash carries that newline into
# snapshots, and the next restore's checkout of that hash fails
return line.strip()
return line.strip().decode('ascii', errors='replace')

return "unknown"

Expand Down
Loading
Loading