Skip to content

Commit 4c082ba

Browse files
committed
Auto-detect library in system paths - no manual SOCHDB_LIB_PATH needed
- Add /opt/homebrew/lib for macOS Apple Silicon - Add /opt/local/lib for MacPorts - Add ~/.sochdb/lib for user installations - Search system paths automatically - Improved error messages with installation instructions - Developers don't need to manually define environment variables
1 parent 9e131de commit 4c082ba

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/sochdb/database.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ def _find_library() -> str:
108108
os.path.join(pkg_dir, "..", "..", "..", "target", "debug"),
109109
])
110110

111-
# 7. System paths
112-
search_paths.extend(["/usr/local/lib", "/usr/lib"])
111+
# 7. System paths (no manual setup required)
112+
search_paths.extend([
113+
"/usr/local/lib",
114+
"/usr/lib",
115+
"/opt/homebrew/lib", # macOS Apple Silicon Homebrew
116+
"/opt/local/lib", # MacPorts
117+
os.path.expanduser("~/.sochdb/lib"), # User installation
118+
])
113119

114120
for path in search_paths:
115121
lib_path = os.path.join(path, lib_name)
@@ -118,8 +124,10 @@ def _find_library() -> str:
118124

119125
raise DatabaseError(
120126
f"Could not find {lib_name}. "
121-
f"Searched in: {', '.join(search_paths[:5])}... "
122-
"Set SOCHDB_LIB_PATH environment variable or install sochdb-client with pip."
127+
f"Searched in package paths, development builds, and system locations. "
128+
f"Install with: brew install sochdb (macOS) or pip install sochdb-client. "
129+
f"Or download from https://github.com/sochdb/sochdb/releases. "
130+
f"Alternatively, set SOCHDB_LIB_PATH environment variable to library path."
123131
)
124132

125133

src/sochdb/vector.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ def _find_library():
103103
# 5. Development builds
104104
os.path.join(pkg_dir, "..", "..", "..", "target", "release"),
105105
os.path.join(pkg_dir, "..", "..", "..", "target", "debug"),
106-
# 6. System paths
106+
# 6. System paths (no manual setup required)
107107
"/usr/local/lib",
108108
"/usr/lib",
109+
"/opt/homebrew/lib", # macOS Apple Silicon Homebrew
110+
"/opt/local/lib", # MacPorts
111+
os.path.expanduser("~/.sochdb/lib"), # User installation
109112
]
110113

111114
for path in search_paths:
@@ -136,7 +139,9 @@ def get_lib(cls):
136139
if path is None:
137140
raise ImportError(
138141
"Could not find libsochdb_index. "
139-
"Set SOCHDB_LIB_PATH environment variable."
142+
"Install with: brew install sochdb (macOS) or pip install sochdb-client. "
143+
"Or download from https://github.com/sochdb/sochdb/releases. "
144+
"Alternatively, set SOCHDB_LIB_PATH environment variable."
140145
)
141146
cls._lib = ctypes.CDLL(path)
142147
cls._setup_bindings()

0 commit comments

Comments
 (0)