-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy path_ibm_db_register_dll.py
More file actions
38 lines (33 loc) · 1.42 KB
/
_ibm_db_register_dll.py
File metadata and controls
38 lines (33 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Auto-generated by ibm_db setup.py
# Registers clidriver DLL directory for Python 3.8+ on Windows.
# This module is imported at startup via ibm_db_dll.pth.
import os, sys, site, sysconfig
if sys.platform == "win32" and hasattr(os, "add_dll_directory"):
candidates = []
# 1. IBM_DB_HOME environment variable (highest priority)
ibm_home = os.environ.get("IBM_DB_HOME")
if ibm_home:
candidates.append(os.path.join(ibm_home.strip('"'), "bin"))
else:
# 2. User site-packages/clidriver (pip install --user)
try:
usp = site.getusersitepackages()
if usp:
candidates.append(os.path.join(usp, "clidriver", "bin"))
except Exception:
pass
# 3. System site-packages/clidriver (standard pip install)
candidates.append(
os.path.join(sysconfig.get_path("purelib"), "clidriver", "bin")
)
# 4. PATH entries that look like DB2/clidriver installs
for d in os.environ.get("PATH", "").split(";"):
if d and os.path.basename(d).lower() == "bin":
if (os.path.isfile(os.path.join(d, "db2cli.exe")) or
os.path.isdir(os.path.join(os.path.dirname(d), "license"))):
candidates.append(d)
# Register the first valid DLL directory
for p in candidates:
if p and os.path.isdir(p):
os.add_dll_directory(p)
break