Skip to content

Commit

Permalink
Allow extension to be installed in any directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwalder committed Jun 25, 2024
1 parent 3f2fff3 commit 3f2ff99
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions nodes/sampler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import logging
import os
from abc import ABC, abstractproperty
from collections.abc import Iterable
from pathlib import Path

from dynamicprompts.sampling_context import SamplingContext
from dynamicprompts.wildcards import WildcardManager
Expand Down Expand Up @@ -37,24 +37,18 @@ def __init__(self, *args, **kwargs):
self._wildcard_manager = WildcardManager(path=wildcards_folder)
self._current_prompt = None

def _find_wildcards_folder(self) -> Path | None:
def _find_wildcards_folder(self):
"""
Find the wildcards folder.
First look in the comfy_dynamicprompts folder, then in the custom_nodes folder, then in the Comfui base folder.
"""
from folder_paths import base_path, folder_names_and_paths
install_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
wildcard_path = os.path.join(install_dir, "wildcards")

wildcard_path = Path(base_path) / "wildcards"

if wildcard_path.exists():
if os.path.exists(wildcard_path):
return wildcard_path

extension_path = (
Path(folder_names_and_paths["custom_nodes"][0][0])
/ "comfyui-dynamicprompts"
)
wildcard_path = extension_path / "wildcards"
wildcard_path.mkdir(parents=True, exist_ok=True)
wildcard_path = os.path.join(wildcard_path)
os.mkdir(wildcard_path)

return wildcard_path

Expand Down Expand Up @@ -108,5 +102,4 @@ def get_prompt(self, text: str, seed: int, autorefresh: str) -> tuple[str]:
return (str(new_prompt),)

@abstractproperty
def context(self) -> SamplingContext:
...
def context(self) -> SamplingContext: ...

0 comments on commit 3f2ff99

Please sign in to comment.