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 530406a
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions nodes/sampler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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

logger = logging.getLogger(__name__)
EXTENSION_NAME = "comfyui-dynamicprompts"


class DPAbstractSamplerNode(ABC):
Expand Down Expand Up @@ -37,24 +38,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 +103,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 530406a

Please sign in to comment.