-
Notifications
You must be signed in to change notification settings - Fork 203
Fix DLL load failure on Windows , update workflow and simplify sdist packaging #1053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de57b83
Fix: Replace %ls with %s and use PyUnicode_AsUTF8() in debug log mess…
Earammak abf5516
test release to testpypi 3.2.6.10
Earammak 772be30
test release to testpypi 3.2.6.10
Earammak a6e7ea2
Fix DLL load failure on Windows , update workflow and simplify sdist…
Earammak 0b808a7
Updated cibuildwheel 3.1.4 for windows 32-bit
Earammak 8ee0793
move clidriver fallback path logic into an else block when IBM_DB_HOM…
Earammak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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")) | ||
|
|
||
| # 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import _ibm_db_register_dll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """Inject ibm_db_dll.pth into a wheel so it lands in site-packages on install. | ||
|
|
||
| Usage: python scripts/inject_pth_into_wheel.py <wheel_dir> | ||
|
|
||
| Wheels are zip files. Files at the root level of a wheel (alongside .py | ||
| modules) are installed to site-packages. This script adds ibm_db_dll.pth | ||
| to every .whl file in the given directory. | ||
| """ | ||
| import os, sys, hashlib, base64, zipfile, glob, tempfile, shutil | ||
|
|
||
| PTH_FILENAME = 'ibm_db_dll.pth' | ||
| PTH_CONTENT = 'import _ibm_db_register_dll\n' | ||
|
|
||
|
|
||
| def _record_line(name, content_bytes): | ||
| """Build a RECORD entry: name,sha256=<digest>,<length>""" | ||
| digest = hashlib.sha256(content_bytes).digest() | ||
| b64 = base64.urlsafe_b64encode(digest).rstrip(b'=').decode('ascii') | ||
| return f'{name},sha256={b64},{len(content_bytes)}' | ||
|
|
||
|
|
||
| def inject_pth(whl_path): | ||
| """Add ibm_db_dll.pth to a wheel file and remove any misplaced copies.""" | ||
| with zipfile.ZipFile(whl_path, 'r') as zin: | ||
| names = zin.namelist() | ||
| # Skip if the .pth file is already at the wheel root | ||
| if PTH_FILENAME in names: | ||
| print(f' {PTH_FILENAME} already at root of {os.path.basename(whl_path)}, skipping') | ||
| return | ||
|
|
||
| tmp_fd, tmp_path = tempfile.mkstemp(suffix='.whl') | ||
| os.close(tmp_fd) | ||
|
|
||
| pth_bytes = PTH_CONTENT.encode('utf-8') | ||
| pth_record = _record_line(PTH_FILENAME, pth_bytes) | ||
|
|
||
| with zipfile.ZipFile(whl_path, 'r') as zin, \ | ||
| zipfile.ZipFile(tmp_path, 'w', zipfile.ZIP_DEFLATED) as zout: | ||
|
|
||
| for item in zin.infolist(): | ||
| # Drop any misplaced copies of the .pth file (absolute-path junk from data_files) | ||
| if item.filename != PTH_FILENAME and item.filename.endswith('/' + PTH_FILENAME): | ||
| print(f' Removing misplaced {item.filename}') | ||
| continue | ||
|
|
||
| data = zin.read(item.filename) | ||
|
|
||
| # Append our .pth entry to the RECORD file | ||
| if item.filename.endswith('/RECORD'): | ||
| data = data.rstrip(b'\n') + b'\n' + pth_record.encode('utf-8') + b'\n' | ||
|
|
||
| zout.writestr(item, data) | ||
|
|
||
| # Add the .pth file at the wheel root | ||
| zout.writestr(PTH_FILENAME, pth_bytes) | ||
|
|
||
| shutil.move(tmp_path, whl_path) | ||
| print(f' Injected {PTH_FILENAME} into {os.path.basename(whl_path)}') | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 2: | ||
| print(f'Usage: {sys.argv[0]} <wheel_dir>') | ||
| sys.exit(1) | ||
|
|
||
| wheel_dir = sys.argv[1] | ||
| wheels = glob.glob(os.path.join(wheel_dir, '*.whl')) | ||
|
|
||
| if not wheels: | ||
| print(f'No .whl files found in {wheel_dir}') | ||
| sys.exit(1) | ||
|
|
||
| for whl in wheels: | ||
| inject_pth(whl) | ||
|
|
||
| print(f'Done: processed {len(wheels)} wheel(s)') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bchoudhary6415 Other code should be inside else block if ibm_home is not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. will correct it.