This commit is contained in:
Myhs-phz 2025-03-19 09:14:52 +00:00
parent ffe00a830d
commit b1c2f60d32

View File

@ -94,21 +94,21 @@ def check_and_rename(filepath):
return None, None return None, None
def update_imports(data): # def update_imports(data):
python_file, name_pairs = data # python_file, name_pairs = data
for filepath, new_file in name_pairs: # for filepath, new_file in name_pairs:
old_name = os.path.basename(filepath)[:-3] # old_name = os.path.basename(filepath)[:-3]
new_name = os.path.basename(new_file)[:-3] # new_name = os.path.basename(new_file)[:-3]
if not os.path.exists(python_file): # if not os.path.exists(python_file):
return # return
with open(python_file, 'r') as file: # with open(python_file, 'r') as file:
filedata = file.read() # filedata = file.read()
# Replace the old name with new name # # Replace the old name with new name
new_data = filedata.replace(old_name, new_name) # new_data = filedata.replace(old_name, new_name)
if filedata != new_data: # if filedata != new_data:
with open(python_file, 'w') as file: # with open(python_file, 'w') as file:
file.write(new_data) # file.write(new_data)
# print(f"Updated imports in {python_file}") # # print(f"Updated imports in {python_file}")
def main(): def main():
@ -134,11 +134,11 @@ def main():
return return
with Pool(16) as p: with Pool(16) as p:
p.starmap(os.rename, name_pairs) p.starmap(os.rename, name_pairs)
root_folder = 'configs' # root_folder = 'configs'
python_files = glob.glob(f'{root_folder}/**/*.py', recursive=True) # python_files = glob.glob(f'{root_folder}/**/*.py', recursive=True)
update_data = [(python_file, name_pairs) for python_file in python_files] # update_data = [(python_file, name_pairs) for python_file in python_files]
with Pool(16) as p: # with Pool(16) as p:
p.map(update_imports, update_data) # p.map(update_imports, update_data)
if __name__ == '__main__': if __name__ == '__main__':