-
Notifications
You must be signed in to change notification settings - Fork 51
CHORE: Add standalone mssql-python-odbc package for ODBC driver binaries #663
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 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8cee2e8
Add standalone mssql-python-odbc package for ODBC driver binaries
jahnvi480 69ca1b7
FIX: Robust ODBC driver fallback and address review feedback for pack…
jahnvi480 362b1df
FIX: Require complete odbc libs (driver + mssql-auth.dll) before usin…
jahnvi480 25ff315
Include vcredist (msvcp140.dll) in odbc package for full parity with …
jahnvi480 c3c3001
Address review: acquire GIL in GetOdbcLibsBaseDir, document driver-ve…
jahnvi480 d69ce14
Document deliberate vcredist/msvcp140.dll inclusion in odbc wheel
jahnvi480 40961b7
DOCS: Add CHANGELOG entry for the mssql-python-odbc package split
jahnvi480 74b6d62
Fix inaccurate setup_odbc.py docstring on libs packaging
jahnvi480 eb100db
Merge branch 'main' into jahnvi/odbc-package-split
jahnvi480 0884620
odbc: bump mssql-python-odbc package version 18.6.0 -> 18.6.2
jahnvi480 ab91887
Centralize ODBC driver version via single source of truth
jahnvi480 33a6084
Merge remote-tracking branch 'origin/main' into jahnvi/odbc-package-s…
jahnvi480 73733d4
Fix Linux pipeline uninstall parsing and ARM64 setup checks
jahnvi480 087b39b
Fix Linux pipeline version parsing quoting
jahnvi480 63a2117
Fix Linux pipeline host-side version parsing
jahnvi480 d9749ad
Fix Ubuntu Linux pipeline version parsing
jahnvi480 07888e9
Fix DRIVER_MAJOR_MINOR setup in all Linux uninstall steps
jahnvi480 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. | ||
| Licensed under the MIT license. | ||
|
|
||
| mssql_python_odbc — Microsoft ODBC Driver 18 for SQL Server binaries. | ||
|
|
||
| Internal implementation package for ``mssql-python``. It ships the | ||
| platform-specific ODBC driver binaries (``msodbcsql18``) and their supporting | ||
| libraries so that ``mssql-python`` does not have to bundle them in its own | ||
| wheel. It is not meant for direct consumption — install ``mssql-python`` | ||
| instead, which depends on this package. | ||
|
|
||
| The public surface is :func:`get_driver_path`, which returns the absolute path | ||
| to the ODBC driver shared library for the current platform/architecture. The | ||
| native ``mssql_python.ddbc_bindings`` extension resolves the same location in | ||
| C++ (see ``GetOdbcLibsBaseDir`` / ``GetDriverPathCpp``); this Python API mirrors | ||
| that logic for tooling, tests, and diagnostics. | ||
| """ | ||
|
|
||
| import os | ||
| import platform | ||
| import sys | ||
|
|
||
| __all__ = ["get_driver_path", "get_libs_dir", "__version__"] | ||
|
|
||
| # Version tracks the bundled Microsoft ODBC Driver 18 for SQL Server release. | ||
| __version__ = "18.6.0" | ||
|
|
||
| # Driver shared-library file names per platform (must match the names produced | ||
| # by the ODBC driver packaging and expected by the native loader). | ||
| _DRIVER_FILENAME = { | ||
| "windows": "msodbcsql18.dll", | ||
| "linux": "libmsodbcsql-18.6.so.2.1", | ||
| "macos": "libmsodbcsql.18.dylib", | ||
| } | ||
|
|
||
|
|
||
| def get_libs_dir() -> str: | ||
| """Return the absolute path to this package's ``libs/`` directory. | ||
|
|
||
| This is the root under which the platform-specific ODBC binaries live | ||
| (``libs/<platform>/<arch>/...``). It is the base the native loader appends | ||
| ``libs`` to when resolving the driver. | ||
| """ | ||
|
jahnvi480 marked this conversation as resolved.
|
||
| return os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs") | ||
|
|
||
|
|
||
| def _detect_arch() -> str: | ||
| """Return the architecture directory name for the current interpreter. | ||
|
|
||
| Mirrors the compile-time detection in ``GetDriverPathCpp``: | ||
| * Windows uses ``x64`` / ``x86`` / ``arm64``. | ||
| * Linux and macOS use ``x86_64`` / ``arm64``. | ||
| """ | ||
| machine = platform.machine().lower() | ||
|
|
||
| if sys.platform.startswith("win"): | ||
| if machine in ("amd64", "x86_64"): | ||
| return "x64" | ||
| if machine in ("arm64", "aarch64"): | ||
| return "arm64" | ||
| if machine in ("x86", "i386", "i686"): | ||
| return "x86" | ||
| raise OSError(f"Unsupported Windows architecture: {platform.machine()!r}") | ||
|
|
||
| # Linux / macOS | ||
| if machine in ("x86_64", "amd64"): | ||
| return "x86_64" | ||
| if machine in ("arm64", "aarch64"): | ||
| return "arm64" | ||
| raise OSError(f"Unsupported architecture: {platform.machine()!r}") | ||
|
|
||
|
|
||
| def _detect_linux_distro_family() -> str: | ||
| """Return the Linux distro family directory name. | ||
|
|
||
| Mirrors the ``/etc/*-release`` probing in ``GetDriverPathCpp`` so the Python | ||
| and C++ paths agree. | ||
| """ | ||
| if os.path.exists("/etc/alpine-release"): | ||
| return "alpine" | ||
| if os.path.exists("/etc/redhat-release") or os.path.exists("/etc/centos-release"): | ||
| return "rhel" | ||
| if os.path.exists("/etc/SuSE-release") or os.path.exists("/etc/SUSE-brand"): | ||
| return "suse" | ||
| return "debian_ubuntu" # default for Debian/Ubuntu and other glibc distros | ||
|
|
||
|
|
||
| def get_driver_path() -> str: | ||
|
jahnvi480 marked this conversation as resolved.
Outdated
|
||
| """Return the absolute path to the ODBC driver shared library. | ||
|
|
||
| Resolves the platform/architecture (and, on Linux, the distro family) and | ||
| returns the full path to ``msodbcsql18`` inside this package. | ||
|
|
||
| Raises: | ||
| OSError: if the platform/architecture is unsupported. | ||
| FileNotFoundError: if the resolved driver file is not present (e.g. the | ||
| package was built without this platform's binaries). | ||
| """ | ||
| libs_dir = get_libs_dir() | ||
| arch = _detect_arch() | ||
|
|
||
| if sys.platform.startswith("win"): | ||
| driver_path = os.path.join(libs_dir, "windows", arch, _DRIVER_FILENAME["windows"]) | ||
| elif sys.platform.startswith("darwin"): | ||
| driver_path = os.path.join( | ||
| libs_dir, "macos", arch, "lib", _DRIVER_FILENAME["macos"] | ||
| ) | ||
| elif sys.platform.startswith("linux"): | ||
| distro = _detect_linux_distro_family() | ||
| driver_path = os.path.join( | ||
| libs_dir, "linux", distro, arch, "lib", _DRIVER_FILENAME["linux"] | ||
| ) | ||
| else: | ||
| raise OSError(f"Unsupported platform: {sys.platform!r}") | ||
|
|
||
| if not os.path.isfile(driver_path): | ||
| raise FileNotFoundError( | ||
| f"ODBC driver not found at {driver_path!r}. The mssql-python-odbc " | ||
| f"package may not include binaries for this platform/architecture." | ||
| ) | ||
|
|
||
| return driver_path | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.