|
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)
|
|
|
|
|
|
if file.endswith(".txt") or file.endswith(".py"):
|
|
|
|
with fileinput.FileInput(file_path, inplace=True) as f:
|
|
for line in f:
|
|
|
|
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') |