Skip to content

Commit 4566c6f

Browse files
committed
fea: add support for env var CLIDRIVER_VERSION for autodownload
1 parent 2d87fe5 commit 4566c6f

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,45 @@ pip install ibm_db
7777

7878
This will install ibm_db and ibm_db_dbi module.
7979

80-
**Note:**
81-
When we install ibm_db package on Linux, MacOS and Windows, `pip install ibm_db` command install
82-
prebuilt Wheel package that includes clidriver too and ignores `IBM_DB_HOME` or `IBM_DB_INSTALLER_URL`
83-
environment variables if set. Also, auto downloading of clidriver does not happen as clidriver is
84-
already present inside wheel package.
80+
- When we install ibm_db package on Linux, MacOS and Windows, `pip install ibm_db` command install
81+
prebuilt Wheel package that includes clidriver too and ignores `IBM_DB_HOME` or `IBM_DB_INSTALLER_URL`
82+
or `CLIDRIVER_VERSION` environment variables if set. Also, auto downloading of clidriver does not happen
83+
as clidriver is already present inside wheel package.
8584

86-
To inforce auto downloading of clidriver or to make setting of environment variable `IBM_DB_HOME`
87-
effective, install ibm_db from source distribution using below command:
85+
- For platforms not supported by python-wheel, ibm_db will get installed from souce distribution.
86+
GCC compiler is required on non-windows platform and VC++ compiler on Windows platform to
87+
install `ibm_db` from souce distribution.
88+
89+
- If `db2cli validate` command works in your system and installed db2 client/server
90+
has `include` directory, ibm_db installation from souce distribution will not download clidriver, but
91+
it will use the existing client/server from the system.
92+
93+
- To inforce auto downloading of clidriver _OR_ to make setting of environment variable `IBM_DB_HOME` or
94+
`IBM_DB_INSTALLER_URL` or `CLIDRIVER_VERSION` effective; install ibm_db from source distribution
95+
using below command:
8896

8997
```
9098
pip install ibm_db --no-binary :all: --no-cache-dir
9199
```
92100

93-
If you have to use your own URL for clidriver.tar.gz/.zip please set environment variable
101+
- If you want to use your own URL for clidriver.tar.gz/.zip please set below environment variable:
94102

95103
```
96-
IBM_DB_INSTALLER_URL=full_path_of_clidriver.tar.gz/.zip
104+
export IBM_DB_INSTALLER_URL=full_path_of_clidriver.tar.gz/.zip
105+
pip install ibm_db --no-binary :all: --no-cache-dir
97106
```
98107

99-
When ibm_db get installed from wheel package, you can find clidriver under site_packages directory
100-
of Python. You need to copy license file under `site_packages/clidriver/license` to be effective, if any.
108+
- To install using specific version of clidriver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/:
109+
110+
```
111+
export CLIDRIVER_VERSION=v11.5.9
112+
pip install ibm_db --no-binary :all: --no-cache-dir
113+
```
114+
115+
- ibm_db will override value of CLIDRIVER_VERSION to v12.1.0 for MacARM64 and to v11.5.9 for Macx64 platform.
116+
117+
- When ibm_db get installed from wheel package, you can find clidriver under site_packages directory
118+
of Python. You need to copy license file under `site_packages/clidriver/license` to be effective, if any.
101119

102120
**Note:** For windows after installing ibm_db, recieves the below error when we try to import ibm_db :
103121

@@ -135,7 +153,7 @@ if pip or pip3 does not exist, install it as:
135153
wget https://bootstrap.pypa.io/get-pip.py
136154
docker cp get-pip.py /root:<containerid>
137155
cd root
138-
python2 get-pip.py or python3 get-pip.py
156+
python3 get-pip.py
139157
140158
Install python ibm_db as:
141159
pip install ibm_db

setup.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ def print_exception( e, url):
286286
shutil.copy(prebuildPYDname, os.path.join(dllDir, 'ibm_db.dll'))
287287
prebuildIbmdbPYD = True
288288

289+
# Get version of clidriver for autodownload from environment variable CLIDRIVER_VERSION
290+
# Default version is v11.5.9
291+
clidriver_version = os.getenv("CLIDRIVER_VERSION", "v11.5.9")
292+
289293
if ((ibm_db_home == '') and (ibm_db_dir == '') and (ibm_db_lib == '')):
290294
if('win32' not in sys.platform):
291295
sys.stdout.write("Detected platform = " + sys.platform + ", uname = " + os.uname()[4] + "\n")
@@ -360,6 +364,11 @@ def print_exception( e, url):
360364
os_ = 'mac'
361365
cliFileName = 'macarm64_odbc_cli.tar.gz'
362366
arch_ = 'arm64'
367+
if(clidriver_version.startswith("v11")):
368+
clidriver_version = "v12.1.0"
369+
else:
370+
if(clidriver_version.startswith("v12")):
371+
clidriver_version = "v11.5.9"
363372
else:
364373
_printAndExit("Not a known platform for python ibm_db.")
365374

@@ -369,20 +378,21 @@ def print_exception( e, url):
369378
ibm_db_lib_runtime = os.path.join('$ORIGIN', 'clidriver', 'lib')
370379
ibm_db_dir = 'clidriver'
371380
ibm_db_lib = os.path.join(ibm_db_dir, 'lib')
381+
clidriver_version = clidriver_version + "/"
372382

373383
if not os.path.isdir('clidriver'):
374384
if 'IBM_DB_INSTALLER_URL' in os.environ:
375385
url = os.getenv('IBM_DB_INSTALLER_URL') + cliFileName
376386
else:
377-
url = 'https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/' + cliFileName
387+
url = 'https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/' + clidriver_version + cliFileName
378388
sys.stdout.write("Downloading %s\n" % (url))
379389
sys.stdout.flush()
380390
try:
381391
_downloadClidriver(url)
382392
except Exception as e:
383393
print_exception(e, url)
384394
try:
385-
git_url= 'https://github.com/ibmdb/db2drivers/raw/main/clidriver/' + cliFileName
395+
git_url= 'https://github.com/ibmdb/db2drivers/raw/main/clidriver/' + clidriver_version + cliFileName
386396
_downloadClidriver(git_url)
387397
except Exception as e:
388398
print_exception(e, git_url)

0 commit comments

Comments
 (0)