File size: 1,933 Bytes
86d4cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56


import os
import glob

def generate_requirements():
    """
    Generate a comprehensive requirements.txt file by combining:
    1. The main requirements.txt from the root directory
    2. All requirements.txt files found in custom_nodes subfolders
    3. Adding the 'black' package
    
    Returns:
        str: The combined requirements as a string
    """
    requirements = set()
    
    # Get the ComfyUI root directory (2 levels up from this file)
    current_dir = os.path.dirname(os.path.abspath(__file__))
    comfy_root = os.path.dirname(os.path.dirname(current_dir))
    
    # 1. Read the main requirements.txt if it exists
    main_req_path = os.path.join(comfy_root, "requirements.txt")
    if os.path.exists(main_req_path):
        with open(main_req_path, 'r') as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith('#'):
                    requirements.add(line)
    
    # 2. Scan custom_nodes directory for requirements.txt files
    custom_nodes_dir = os.path.join(comfy_root, "custom_nodes")
    if os.path.exists(custom_nodes_dir):
        # Find all requirements.txt files in custom_nodes subdirectories
        req_files = glob.glob(os.path.join(custom_nodes_dir, "**/requirements.txt"), recursive=True)
        
        for req_file in req_files:
            with open(req_file, 'r') as f:
                for line in f:
                    line = line.strip()
                    if line and not line.startswith('#'):
                        requirements.add(line)
    
    # 3. Add the black package
    requirements.add('black')
    
    # Convert set to sorted list for consistent output
    sorted_requirements = sorted(list(requirements))
    
    # Join requirements with newlines
    return '\n'.join(sorted_requirements)

if __name__ == "__main__":
    # When run directly, print the requirements
    print(generate_requirements())