File size: 1,075 Bytes
7d397b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pydantic
import os
import fileinput

def replace_string_in_files(folder_path, old_str, new_str):
    for subdir, dirs, files in os.walk(folder_path):
        for file in files:
            file_path = os.path.join(subdir, file)

            # Check if the file is a text file (you can modify this condition based on your needs)
            if file.endswith(".txt") or file.endswith(".py"):
                # Open the file in place for editing
                with fileinput.FileInput(file_path, inplace=True) as f:
                    for line in f:
                        # Replace the old string with the new string
                        print(line.replace(old_str, new_str), end='')


def use_pydantic_v1():
    module_file_path = pydantic.__file__
    module_file_path = module_file_path.split('pydantic')[0] + 'haystack'  
    with open(module_file_path+'/schema.py','r') as f:
        haystack_schema_file = f.read()

    if 'from pydantic.v1' not in haystack_schema_file:
        replace_string_in_files(module_file_path, 'from pydantic', 'from pydantic.v1')