Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b349b2f147 |
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning 2.0.0](https://semver.org/spec/
|
||||
|
||||
### Added
|
||||
|
||||
- An aria2 on the same machine can be the downloader. With aria2 as the
|
||||
downloader, the Manager asks aria2 to save a file into `/models/...` or
|
||||
`/custom_nodes`, which is where the container of `docs/en/use_aria2.md`
|
||||
sees the folders of ComfyUI. An aria2 that runs on the same machine without
|
||||
a container cannot write there, and its downloads failed (#2999). With
|
||||
`COMFYUI_MANAGER_ARIA2_SAME_PATHS=true` the Manager gives aria2 each folder
|
||||
as ComfyUI sees it. Without the variable nothing changes.
|
||||
|
||||
- `dependency_management = off` turns off the changes that the Manager makes
|
||||
to Python packages on its own. On a Python that cannot be changed, such as
|
||||
one of Nix, Guix or a distribution, the Manager ran pip at every start and
|
||||
|
||||
@@ -85,10 +85,15 @@ def aria2_download_url(model_url: str, model_dir: str, filename: str):
|
||||
|
||||
local_path = os.path.join(model_dir, filename)
|
||||
|
||||
if model_dir.startswith(context.comfy_path):
|
||||
model_dir = model_dir[len(context.comfy_path) :]
|
||||
same_paths = os.environ.get('COMFYUI_MANAGER_ARIA2_SAME_PATHS', '').lower() == 'true'
|
||||
|
||||
download_dir = model_dir if model_dir.startswith('/') else os.path.join('/models', model_dir)
|
||||
if not same_paths and model_dir.startswith(context.comfy_path):
|
||||
rel = model_dir[len(context.comfy_path):]
|
||||
download_dir = rel if rel.startswith('/') else '/' + rel
|
||||
elif os.path.isabs(model_dir):
|
||||
download_dir = model_dir
|
||||
else:
|
||||
download_dir = os.path.join('/models', model_dir)
|
||||
|
||||
download = aria2_find_task(download_dir, filename)
|
||||
if download is not None and download.is_complete and os.path.exists(local_path):
|
||||
@@ -116,7 +121,7 @@ def aria2_download_url(model_url: str, model_dir: str, filename: str):
|
||||
raise Exception(f"aria2 failed to download '{model_url}' into '{download_dir}': {download.error_message}")
|
||||
if not os.path.exists(local_path):
|
||||
raise Exception(f"aria2 saved '{filename}' into its '{download_dir}', but the file is not at '{local_path}'. "
|
||||
"aria2 must see the ComfyUI folder as '/' (see docs/en/use_aria2.md).")
|
||||
"See docs/en/use_aria2.md for where aria2 must see the folders of ComfyUI.")
|
||||
|
||||
|
||||
def download_url_with_agent(url, save_path):
|
||||
|
||||
@@ -38,3 +38,13 @@ services:
|
||||
options:
|
||||
max-size: 1m
|
||||
```
|
||||
|
||||
## aria2 on the same machine, without a container
|
||||
|
||||
The Manager asks aria2 to save a file into `/models/...` or `/custom_nodes`. The container above sees the `models` and `custom_nodes` folders of ComfyUI there, through its volumes.
|
||||
|
||||
An aria2 that runs on the same machine as ComfyUI, without a container, sees these folders where ComfyUI sees them. For it, set one more variable. The Manager then gives aria2 each folder as it is.
|
||||
|
||||
```bash
|
||||
export COMFYUI_MANAGER_ARIA2_SAME_PATHS=true
|
||||
```
|
||||
|
||||
@@ -7,6 +7,8 @@ import pytest
|
||||
|
||||
from _install_flags_testutil import import_context
|
||||
|
||||
posix_folder = pytest.mark.skipif(os.name == 'nt', reason='the folder that aria2 gets is a POSIX path')
|
||||
|
||||
|
||||
class FakeDownload:
|
||||
def __init__(self, statuses, local_file=None, error_message=None, target=None):
|
||||
@@ -57,6 +59,7 @@ def md(tmp_path, monkeypatch):
|
||||
from comfyui_manager.common import context, manager_downloader
|
||||
monkeypatch.setattr(context, 'comfy_path', str(tmp_path))
|
||||
monkeypatch.setattr(time, 'sleep', lambda s: None)
|
||||
monkeypatch.delenv('COMFYUI_MANAGER_ARIA2_SAME_PATHS', raising=False)
|
||||
return manager_downloader
|
||||
|
||||
|
||||
@@ -81,6 +84,7 @@ def test_a_file_that_aria2_saved_elsewhere_raises(md, tmp_path, monkeypatch):
|
||||
install(md, tmp_path, monkeypatch, fake)
|
||||
|
||||
|
||||
@posix_folder
|
||||
def test_a_queued_download_is_waited_for(md, tmp_path, monkeypatch):
|
||||
download = FakeDownload(['waiting', 'active', 'complete'], local_file=local(tmp_path))
|
||||
fake = FakeAria2(download)
|
||||
@@ -89,6 +93,7 @@ def test_a_queued_download_is_waited_for(md, tmp_path, monkeypatch):
|
||||
assert fake.added == [{'dir': '/models/checkpoints', 'out': 'y.safetensors'}]
|
||||
|
||||
|
||||
@posix_folder
|
||||
def test_a_failed_earlier_download_is_not_reused(md, tmp_path, monkeypatch):
|
||||
old = FakeDownload(['error'], target='/models/checkpoints/y.safetensors')
|
||||
fake = FakeAria2(FakeDownload(['complete'], local_file=local(tmp_path)), existing=[old])
|
||||
@@ -96,9 +101,35 @@ def test_a_failed_earlier_download_is_not_reused(md, tmp_path, monkeypatch):
|
||||
assert len(fake.added) == 1
|
||||
|
||||
|
||||
@posix_folder
|
||||
def test_a_finished_earlier_download_whose_file_is_there_is_reused(md, tmp_path, monkeypatch):
|
||||
os.makedirs(os.path.dirname(local(tmp_path))); open(local(tmp_path), 'wb').close()
|
||||
old = FakeDownload(['complete'], target='/models/checkpoints/y.safetensors')
|
||||
fake = FakeAria2(FakeDownload(['complete']), existing=[old])
|
||||
install(md, tmp_path, monkeypatch, fake)
|
||||
assert fake.added == []
|
||||
|
||||
|
||||
def dir_given_to_aria2(md, monkeypatch, model_dir):
|
||||
fake = FakeAria2(FakeDownload(['complete'], local_file=os.path.join(model_dir, 'y.safetensors')))
|
||||
monkeypatch.setattr(md, 'aria2', fake)
|
||||
md.download_url('https://huggingface.co/x/y.safetensors', model_dir, 'y.safetensors')
|
||||
return fake.added[0]['dir']
|
||||
|
||||
|
||||
@posix_folder
|
||||
@pytest.mark.parametrize('setting', [None, 'false'])
|
||||
def test_by_default_aria2_gets_the_comfyui_folder_as_its_root(md, tmp_path, tmp_path_factory, monkeypatch, setting):
|
||||
if setting is not None:
|
||||
monkeypatch.setenv('COMFYUI_MANAGER_ARIA2_SAME_PATHS', setting)
|
||||
outside = str(tmp_path_factory.mktemp('outside') / 'checkpoints')
|
||||
assert dir_given_to_aria2(md, monkeypatch, str(tmp_path / 'models' / 'checkpoints')) == '/models/checkpoints'
|
||||
assert dir_given_to_aria2(md, monkeypatch, str(tmp_path / 'custom_nodes')) == '/custom_nodes'
|
||||
assert dir_given_to_aria2(md, monkeypatch, outside) == outside
|
||||
|
||||
|
||||
def test_with_same_paths_aria2_gets_each_folder_as_it_is(md, tmp_path, tmp_path_factory, monkeypatch):
|
||||
monkeypatch.setenv('COMFYUI_MANAGER_ARIA2_SAME_PATHS', 'true')
|
||||
for model_dir in (str(tmp_path / 'models' / 'checkpoints'), str(tmp_path / 'custom_nodes'),
|
||||
str(tmp_path_factory.mktemp('outside') / 'checkpoints')):
|
||||
assert dir_given_to_aria2(md, monkeypatch, model_dir) == model_dir
|
||||
|
||||
Reference in New Issue
Block a user