Skip to content

Commit abf5516

Browse files
committed
test release to testpypi 3.2.6.10
1 parent de57b83 commit abf5516

7 files changed

Lines changed: 180 additions & 25 deletions

File tree

.github/workflows/bld_wheels_and_upload.yml

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
name: Build and upload to PyPI
1+
name: Build and upload to PyPI
22
# Build on every workflow_dispatch, branch push, tag push, and pull request change
33
on:
44
workflow_dispatch:
55
pull_request:
66
push:
77
branches:
88
- master
9+
- fix_dll_error_issue
910
# Sequence of patterns matched against refs/tags
1011
tags:
1112
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
@@ -26,7 +27,10 @@ jobs:
2627
CIBW_BUILD: "*-win_amd64"
2728
CIBW_SKIP: "cp38-*"
2829

29-
- uses: actions/upload-artifact@v4.4.3
30+
- name: Inject ibm_db_dll.pth into wheels
31+
run: python scripts/inject_pth_into_wheel.py wheelhouse
32+
33+
- uses: actions/upload-artifact@v4
3034
with:
3135
name: ibmdb-wheels64-${{ matrix.os }}
3236
path: wheelhouse/*.whl
@@ -46,7 +50,10 @@ jobs:
4650
CIBW_BUILD: "*-win32"
4751
CIBW_SKIP: "cp38-*"
4852

49-
- uses: actions/upload-artifact@v4.4.3
53+
- name: Inject ibm_db_dll.pth into wheels
54+
run: python scripts/inject_pth_into_wheel.py wheelhouse
55+
56+
- uses: actions/upload-artifact@v4
5057
with:
5158
name: ibmdb-wheels32-${{ matrix.os }}
5259
path: wheelhouse/*.whl
@@ -81,7 +88,7 @@ jobs:
8188
--wheel-dir {dest_dir}
8289
{wheel}
8390

84-
- uses: actions/upload-artifact@v4.4.3
91+
- uses: actions/upload-artifact@v4
8592
with:
8693
name: ibmdb-wheels-${{ matrix.os }}
8794
path: wheelhouse/*.whl
@@ -101,7 +108,7 @@ jobs:
101108
CIBW_SKIP: "cp38-*"
102109
MACOSX_DEPLOYMENT_TARGET: 14.0
103110

104-
- uses: actions/upload-artifact@v4.4.3
111+
- uses: actions/upload-artifact@v4
105112
with:
106113
name: ibmdb-wheelsarm64
107114
path: wheelhouse/*.whl
@@ -122,7 +129,7 @@ jobs:
122129
CIBW_SKIP: "cp38-*"
123130
MACOSX_DEPLOYMENT_TARGET: 10.15
124131

125-
- uses: actions/upload-artifact@v4.4.3
132+
- uses: actions/upload-artifact@v4
126133
with:
127134
name: ibmdb-wheelsx86-${{ matrix.os }}
128135
path: wheelhouse/*.whl
@@ -136,26 +143,19 @@ jobs:
136143
run: python -m pip install --upgrade pip build
137144
- name: Build sdist
138145
run: python -m build --sdist --no-isolation
139-
- name: Package version
140-
id: version
141-
run: |
142-
cd dist
143-
pip install ibm_db*
144-
echo "VERSION=$(python -c 'import ibm_db; print(ibm_db.__version__)')" >> $GITHUB_OUTPUT
145-
- name: Build source distribution
146+
- name: Remove clidriver from sdist
146147
run: |
147-
PACKAGE="ibm_db-$VERSION"
148148
cd dist
149-
tar -xzf $PACKAGE.tar.gz
150-
rm -rf $PACKAGE/clidriver*
151-
rm -rf $PACKAGE.tar.gz
152-
tar -czf $PACKAGE.tar.gz $PACKAGE
153-
rm -rf $PACKAGE
154-
env:
155-
VERSION: ${{ steps.version.outputs.VERSION}}
149+
TARBALL=$(ls ibm?db-*.tar.gz | head -1)
150+
DIRNAME="${TARBALL%.tar.gz}"
151+
tar -xzf "$TARBALL"
152+
rm -rf "$DIRNAME"/clidriver*
153+
rm -rf "$TARBALL"
154+
tar -czf "$TARBALL" "$DIRNAME"
155+
rm -rf "$DIRNAME"
156156
157157
- name: Upload sdist
158-
uses: actions/upload-artifact@v4.4.3
158+
uses: actions/upload-artifact@v4
159159
with:
160160
name: ibmdb-sdist
161161
path: dist/*.tar.gz
@@ -182,3 +182,24 @@ jobs:
182182
- name: Publish distribution to PyPI
183183
if: startsWith(github.ref, 'refs/tags')
184184
uses: pypa/gh-action-pypi-publish@release/v1.12
185+
186+
upload_testpypi:
187+
needs: [build_wheels_windows_64, build_wheels_windows_32, build_wheels_linux, build_wheels_macos_arm64, build_wheels_macos_x86, build_sdist]
188+
runs-on: ubuntu-latest
189+
permissions:
190+
id-token: write
191+
192+
#upload to TestPyPI on push to test_dll_issue branch
193+
if: github.event_name == 'push' && github.ref == 'refs/heads/test_dll_issue'
194+
steps:
195+
- uses: actions/download-artifact@v5
196+
with:
197+
path: dist
198+
pattern: ibmdb-*
199+
merge-multiple: true
200+
201+
- name: Publish distribution to TestPyPI
202+
uses: pypa/gh-action-pypi-publish@release/v1.12
203+
with:
204+
repository-url: https://test.pypi.org/legacy/
205+
verbose: true

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
include ibm_db.h ibm_db.c
22
include CHANGES.md LICENSE README.md
33
include config.py.sample
4+
include ibm_db_dll.pth
5+
include _ibm_db_register_dll.py
46
recursive-include ibm_db_tests *.py *.png *.jpg
57
include MANIFEST.in
68
recursive-include clidriver *

_ibm_db_register_dll.py

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

ibm_db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
+--------------------------------------------------------------------------+
2323
*/
2424

25-
#define MODULE_RELEASE "3.2.8"
25+
#define MODULE_RELEASE "3.2.6.10"
2626

2727
#include <Python.h>
2828
#include <datetime.h>

ibm_db_dll.pth

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import _ibm_db_register_dll

scripts/inject_pth_into_wheel.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Inject ibm_db_dll.pth into a wheel so it lands in site-packages on install.
2+
3+
Usage: python scripts/inject_pth_into_wheel.py <wheel_dir>
4+
5+
Wheels are zip files. Files at the root level of a wheel (alongside .py
6+
modules) are installed to site-packages. This script adds ibm_db_dll.pth
7+
to every .whl file in the given directory.
8+
"""
9+
import os, sys, hashlib, base64, zipfile, glob, tempfile, shutil
10+
11+
PTH_FILENAME = 'ibm_db_dll.pth'
12+
PTH_CONTENT = 'import _ibm_db_register_dll\n'
13+
14+
15+
def _record_line(name, content_bytes):
16+
"""Build a RECORD entry: name,sha256=<digest>,<length>"""
17+
digest = hashlib.sha256(content_bytes).digest()
18+
b64 = base64.urlsafe_b64encode(digest).rstrip(b'=').decode('ascii')
19+
return f'{name},sha256={b64},{len(content_bytes)}'
20+
21+
22+
def inject_pth(whl_path):
23+
"""Add ibm_db_dll.pth to a wheel file and remove any misplaced copies."""
24+
with zipfile.ZipFile(whl_path, 'r') as zin:
25+
names = zin.namelist()
26+
# Skip if the .pth file is already at the wheel root
27+
if PTH_FILENAME in names:
28+
print(f' {PTH_FILENAME} already at root of {os.path.basename(whl_path)}, skipping')
29+
return
30+
31+
tmp_fd, tmp_path = tempfile.mkstemp(suffix='.whl')
32+
os.close(tmp_fd)
33+
34+
pth_bytes = PTH_CONTENT.encode('utf-8')
35+
pth_record = _record_line(PTH_FILENAME, pth_bytes)
36+
37+
with zipfile.ZipFile(whl_path, 'r') as zin, \
38+
zipfile.ZipFile(tmp_path, 'w', zipfile.ZIP_DEFLATED) as zout:
39+
40+
for item in zin.infolist():
41+
# Drop any misplaced copies of the .pth file (absolute-path junk from data_files)
42+
if item.filename != PTH_FILENAME and item.filename.endswith('/' + PTH_FILENAME):
43+
print(f' Removing misplaced {item.filename}')
44+
continue
45+
46+
data = zin.read(item.filename)
47+
48+
# Append our .pth entry to the RECORD file
49+
if item.filename.endswith('/RECORD'):
50+
data = data.rstrip(b'\n') + b'\n' + pth_record.encode('utf-8') + b'\n'
51+
52+
zout.writestr(item, data)
53+
54+
# Add the .pth file at the wheel root
55+
zout.writestr(PTH_FILENAME, pth_bytes)
56+
57+
shutil.move(tmp_path, whl_path)
58+
print(f' Injected {PTH_FILENAME} into {os.path.basename(whl_path)}')
59+
60+
61+
def main():
62+
if len(sys.argv) != 2:
63+
print(f'Usage: {sys.argv[0]} <wheel_dir>')
64+
sys.exit(1)
65+
66+
wheel_dir = sys.argv[1]
67+
wheels = glob.glob(os.path.join(wheel_dir, '*.whl'))
68+
69+
if not wheels:
70+
print(f'No .whl files found in {wheel_dir}')
71+
sys.exit(1)
72+
73+
for whl in wheels:
74+
inject_pth(whl)
75+
76+
print(f'Done: processed {len(wheels)} wheel(s)')
77+
78+
79+
if __name__ == '__main__':
80+
main()

setup.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
from distutils.sysconfig import get_python_lib
2929
from setuptools import setup, find_packages, Extension
3030
from setuptools.command.build_ext import build_ext
31+
from setuptools.command.build_py import build_py
3132
from setuptools.command.install import install
3233

3334
PACKAGE = 'ibm_db'
34-
VERSION = '3.2.8'
35+
VERSION = '3.2.6.10'
3536
LICENSE = 'Apache License 2.0'
3637
readme = os.path.join(os.path.dirname(__file__),'README.md')
3738

@@ -501,7 +502,7 @@ def print_exception( e, url):
501502
(get_python_lib(), ['./LICENSE']),
502503
(get_python_lib(), ['./config.py.sample'])]
503504

504-
modules = ['ibm_db_dbi', 'testfunctions', 'ibmdb_tests', 'ibm_db_ctx']
505+
modules = ['ibm_db_dbi', 'testfunctions', 'ibmdb_tests', 'ibm_db_ctx', '_ibm_db_register_dll']
505506

506507
if 'zos' == sys.platform:
507508
ext_modules = _ext_modules(os.path.join(os.getcwd(), include_dir), library, ibm_db_lib, ibm_db_lib_runtime)
@@ -525,6 +526,18 @@ def print_exception( e, url):
525526
_checkGcc()
526527
_checkPythonHeaderFile()
527528

529+
# Custom build_py to include ibm_db_dll.pth at the wheel root
530+
# so it lands in site-packages and triggers DLL registration on startup.
531+
class _build_py_with_pth(build_py):
532+
def run(self):
533+
super().run()
534+
pth_src = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ibm_db_dll.pth')
535+
if os.path.isfile(pth_src):
536+
pth_dst = os.path.join(self.build_lib, 'ibm_db_dll.pth')
537+
self.copy_file(pth_src, pth_dst)
538+
539+
cmd_class['build_py'] = _build_py_with_pth
540+
528541
#'Operating System :: z/OS', pypi upload fails with error - Not a valid classifier
529542
setup( name = PACKAGE,
530543
version = VERSION,

0 commit comments

Comments
 (0)