Skip to content

Commit ae4e047

Browse files
authored
v3.0.1
hot fix!
1 parent edddddf commit ae4e047

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/initialize.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import yaml
33
import platform
44
import ctranslate2
5-
import os
6-
import shutil
75
from pathlib import Path
86

97
def get_compute_device_info():
@@ -62,22 +60,10 @@ def update_config_file(**system_info):
6260
with open(full_config_path, 'w') as stream:
6361
yaml.safe_dump(config_data, stream)
6462

65-
def move_custom_pdf_loader():
66-
current_dir = Path.cwd()
67-
user_manual_pdf_path = current_dir / "User_Manual" / "PDF.py"
68-
lib_pdf_path = current_dir / "Lib" / "site-packages" / "langchain" / "document_loaders" / "parsers" / "PDF.py"
69-
70-
user_manual_pdf_size = user_manual_pdf_path.stat().st_size
71-
lib_pdf_size = lib_pdf_path.stat().st_size
72-
73-
if user_manual_pdf_size != lib_pdf_size:
74-
shutil.copy(user_manual_pdf_path, lib_pdf_path)
75-
7663
def main():
7764
compute_device_info = get_compute_device_info()
7865
platform_info = get_platform_info()
7966
update_config_file(Compute_Device=compute_device_info, Platform_Info=platform_info)
80-
move_custom_pdf_loader()
8167

8268
if __name__ == "__main__":
8369
main()

src/replace_pdf.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import shutil
22
from pathlib import Path
3+
import hashlib
34

45
def find_all_target_directories_with_file(base_path, target_folder, target_file):
56
found_directories = []
@@ -20,6 +21,14 @@ def find_closest_directory(directories, base_directory):
2021
depths = [(dir, get_directory_depth(dir, base_directory)) for dir in directories]
2122
return min(depths, key=lambda x: x[1])[0]
2223

24+
def hash_file(filepath):
25+
"""Compute the SHA-256 hash of a file."""
26+
hasher = hashlib.sha256()
27+
with open(filepath, 'rb') as f:
28+
buf = f.read()
29+
hasher.update(buf)
30+
return hasher.hexdigest()
31+
2332
def replace_pdf_in_parsers():
2433
script_dir = Path(__file__).parent
2534
user_manual_pdf_path = script_dir / "User_Manual" / "PDF.py"
@@ -28,7 +37,7 @@ def replace_pdf_in_parsers():
2837
print("No 'pdf.py' file found in 'User_Manual' directory.")
2938
return
3039

31-
base_dir = script_dir.parent.parent # Move up two levels from the script's location
40+
base_dir = script_dir.parent # Move up one level from the script's location
3241
target_folder = "parsers"
3342
target_file = "pdf.py"
3443
found_paths = find_all_target_directories_with_file(base_dir, target_folder, target_file)
@@ -44,16 +53,16 @@ def replace_pdf_in_parsers():
4453
print(f"Chosen 'parsers' directory based on path depth: {closest_parsers_path}")
4554
chosen_pdf_path = closest_parsers_path / target_file
4655

47-
# File size comparison and replacement
48-
user_manual_pdf_size = user_manual_pdf_path.stat().st_size
49-
chosen_pdf_size = chosen_pdf_path.stat().st_size
56+
# Hash comparison and replacement
57+
user_manual_pdf_hash = hash_file(user_manual_pdf_path)
58+
chosen_pdf_hash = hash_file(chosen_pdf_path)
5059

51-
if user_manual_pdf_size != chosen_pdf_size:
60+
if user_manual_pdf_hash != chosen_pdf_hash:
5261
print("Replacing the existing pdf.py with the new one...")
5362
shutil.copy(user_manual_pdf_path, chosen_pdf_path)
5463
print(f"PDF.py replaced at: {chosen_pdf_path}")
5564
else:
56-
print("No replacement needed. The files are of the same size.")
65+
print("No replacement needed. The files are identical.")
5766

5867
if __name__ == "__main__":
5968
replace_pdf_in_parsers()

0 commit comments

Comments
 (0)