q-and-a-tool / utils /check_pydantic_version.py
Sourabh Zanwar
added login, upload floater options(#8)
3ccc981 unverified
raw
history blame
1.08 kB
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')