@@ -37,39 +37,58 @@ def __init__(self, epsilon=0.2, beta=0.1):
3737 # Set up C function interfaces
3838 self ._setup_functions ()
3939
40+ # def _find_library_path(self):
41+ # """Find the path to the compiled library file."""
42+ # # Get the directory of the current file
43+ # current_dir = os.path.dirname(os.path.abspath(__file__))
44+
45+ # # Determine library name based on platform
46+ # if platform.system() == "Darwin":
47+ # lib_name = "libgrpo.dylib"
48+ # elif platform.system() == "Linux":
49+ # lib_name = "libgrpo.so"
50+ # elif platform.system() == "Windows":
51+ # lib_name = "libgrpo.dll"
52+ # else:
53+ # raise OSError(f"Unsupported operating system: {platform.system()}")
54+
55+ # # Possible locations for the library
56+ # possible_paths = [
57+ # os.path.join(current_dir, "c_src", lib_name),
58+ # os.path.join(current_dir, lib_name),
59+ # os.path.join(os.path.dirname(current_dir), "c_src", lib_name),
60+ # os.path.join(sys.prefix, "lib", lib_name),
61+ # ]
62+
63+ # # Find the first existing library file
64+ # for path in possible_paths:
65+ # if os.path.exists(path):
66+ # return path
67+
68+ # paths_str = "\n".join(possible_paths)
69+ # raise FileNotFoundError(
70+ # f"Could not find {lib_name}. Searched in:\n{paths_str}\n"
71+ # "Try reinstalling the package or building the C extension."
72+ # )
4073 def _find_library_path (self ):
41- """Find the path to the compiled library file."""
42- # Get the directory of the current file
4374 current_dir = os .path .dirname (os .path .abspath (__file__ ))
44-
45- # Determine library name based on platform
46- if platform .system () == "Darwin" :
47- lib_name = "libgrpo.dylib"
48- elif platform .system () == "Linux" :
49- lib_name = "libgrpo.so"
50- elif platform .system () == "Windows" :
51- lib_name = "libgrpo.dll"
52- else :
53- raise OSError (f"Unsupported operating system: { platform .system ()} " )
54-
55- # Possible locations for the library
56- possible_paths = [
57- os .path .join (current_dir , "c_src" , lib_name ),
58- os .path .join (current_dir , lib_name ),
59- os .path .join (os .path .dirname (current_dir ), "c_src" , lib_name ),
60- os .path .join (sys .prefix , "lib" , lib_name ),
75+ lib_name = {
76+ 'Windows' : 'libgrpo.dll' ,
77+ 'Darwin' : 'libgrpo.dylib' ,
78+ 'Linux' : 'libgrpo.so'
79+ }[platform .system ()]
80+
81+ search_paths = [
82+ os .path .join (current_dir , "c_src" ),
83+ current_dir ,
84+ os .path .join (os .path .dirname (current_dir ), "c_src" ),
85+ os .path .join (sys .prefix , "lib" )
6186 ]
62-
63- # Find the first existing library file
64- for path in possible_paths :
65- if os .path .exists (path ):
66- return path
67-
68- paths_str = "\n " .join (possible_paths )
69- raise FileNotFoundError (
70- f"Could not find { lib_name } . Searched in:\n { paths_str } \n "
71- "Try reinstalling the package or building the C extension."
72- )
87+
88+ for path in search_paths :
89+ full_path = os .path .normpath (os .path .join (path , lib_name ))
90+ if os .path .exists (full_path ):
91+ return full_path
7392
7493 def _load_library (self ):
7594 """Load the compiled C library."""
0 commit comments