Skip to content

Commit 2dac682

Browse files
authored
FEAT: Pytests for Dependencies (#139)
### ADO Work Item Reference <!-- Insert your ADO Work Item ID below (e.g. AB#37452) --> > [AB#37995](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37995) ------------------------------------------------------------------- ### Summary <!-- Insert your Copilot Generated Summary below --> This pull request introduces significant updates to the `mssql_python` package, focusing on architecture-specific dependency handling, documentation improvements, and comprehensive testing. Key changes include enhancements to the README for better clarity on platform-specific builds, removal of unused imports, and the addition of a new test file to validate dependencies across platforms. ### Documentation Updates: * [`mssql_python/pybind/README.md`](diffhunk://#diff-1429930017ef4a5b84d9331206c1ac47e546427b914986e531e3f04e45f4bb31L3-R22): Expanded documentation to include platform-specific architecture handling, runtime loading mechanisms, and dependency summaries for Windows, macOS, and Linux. Added detailed directory structure and naming conventions for Python extension modules. [[1]](diffhunk://#diff-1429930017ef4a5b84d9331206c1ac47e546427b914986e531e3f04e45f4bb31L3-R22) [[2]](diffhunk://#diff-1429930017ef4a5b84d9331206c1ac47e546427b914986e531e3f04e45f4bb31L28-R47) [[3]](diffhunk://#diff-1429930017ef4a5b84d9331206c1ac47e546427b914986e531e3f04e45f4bb31L62-R167) ### Code Cleanup: * [`tests/conftest.py`](diffhunk://#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128L12-R12): Removed unused `ddbc_bindings` import to streamline the test configuration file. ### Testing Enhancements: * [`tests/test_000_dependencies.py`](diffhunk://#diff-e489a2a29f29954dcd0b17a34b15e53ee2aa4fa1def0a5a466bcee81df59ddf0R1-R352): Added a new test file to validate platform-specific dependencies, architecture normalization, and runtime compatibility. Includes helper functions for detecting Linux distributions and verifying dependency files and Python extension modules. <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) -->
1 parent 4b8949b commit 2dac682

File tree

3 files changed

+459
-4
lines changed

3 files changed

+459
-4
lines changed

mssql_python/pybind/README.md

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Build Instructions for Developers
22

3-
This README provides instructions to build the DDBC Bindings PYD for your system (supports Windows x64 and arm64).
3+
This README provides instructions to build the DDBC Bindings for your system and documents the platform-specific dependencies.
4+
5+
## **Key Architecture Handling**
6+
7+
1. **Architecture Normalization** (from `mssql_python/ddbc_bindings.py`):
8+
- Windows: `win64/amd64/x64``x64`, `win32/x86``x86`, `arm64``arm64`
9+
- macOS: Always uses `universal2` for distribution
10+
- Linux: `x64/amd64``x86_64`, `arm64/aarch64``arm64`
11+
12+
2. **Build System Support**:
13+
- CMake handles universal binaries for macOS (`arm64;x86_64`)
14+
- Windows `mssql_python/pybind/build.bat` supports x64, x86, and ARM64
15+
- Linux builds are distribution-aware (Debian/Ubuntu vs RHEL)
16+
17+
3. **Runtime Loading**:
18+
- `LoadDriverLibrary()` in `mssql_python/pybind/ddbc_bindings.cpp` handles platform-specific loading
19+
- Windows uses `LoadLibraryW()`
20+
- macOS/Linux uses `dlopen()`
21+
22+
---
423

524
## Building on Windows
625
> Supporting Windows x64 & ARM64 only
@@ -25,7 +44,7 @@ This README provides instructions to build the DDBC Bindings PYD for your system
2544
- The script will:
2645
- Clean up existing build directories
2746
- Detect VS Build Tools Installation, and start compilation for your Python version and Windows architecture
28-
- Compile `ddbc_bindings.cpp` using CMake and create properly versioned PYD file (`ddbc_bindings.cp313-amd64.pyd`)
47+
- Compile `mssql_python/pybind/ddbc_bindings.cpp` using CMake and create properly versioned PYD file (`ddbc_bindings.cp313-amd64.pyd`)
2948
- Move the built PYD file to the parent `mssql_python` directory
3049

3150
## Building on MacOS
@@ -59,6 +78,90 @@ This README provides instructions to build the DDBC Bindings PYD for your system
5978
- Clean any existing build artifacts
6079
- Detect system architecture
6180
- Configure CMake with appropriate include/library paths
62-
- Compile `ddbc_bindings.cpp` using CMake
81+
- Compile `mssql_python/pybind/ddbc_bindings.cpp` using CMake
6382
- Generate the `.so` file (e.g., `ddbc_bindings.cp313-universal2.so`)
6483
- Copy the output SO file to the parent `mssql_python` directory
84+
85+
## Architecture Dependencies Summary
86+
87+
### **Directory Structure**
88+
```
89+
mssql_python/
90+
├── libs/
91+
│ ├── windows/
92+
│ │ ├── x64/
93+
│ │ ├── x86/
94+
│ │ └── arm64/
95+
│ ├── macos/
96+
│ │ ├── arm64/lib/
97+
│ │ └── x86_64/lib/
98+
│ └── linux/
99+
│ ├── debian_ubuntu/
100+
│ │ ├── x86_64/lib/
101+
│ │ └── arm64/lib/
102+
│ └── rhel/
103+
│ ├── x86_64/lib/
104+
│ └── arm64/lib/
105+
└── ddbc_bindings.cp{python_version}-{architecture}.{extension}
106+
```
107+
108+
### **Windows (.dll files)**
109+
Windows builds depend on these DLLs for different architectures:
110+
111+
**x64 (amd64):**
112+
- `msodbcsql18.dll` - Main driver
113+
- `msodbcdiag18.dll` - Diagnostic library
114+
- `mssql-auth.dll` - Authentication library (for Entra ID)
115+
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)
116+
117+
**x86 (win32):**
118+
- `msodbcsql18.dll` - Main driver
119+
- `msodbcdiag18.dll` - Diagnostic library
120+
- `mssql-auth.dll` - Authentication library
121+
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)
122+
123+
**ARM64:**
124+
- `msodbcsql18.dll` - Main driver
125+
- `msodbcdiag18.dll` - Diagnostic library
126+
- `mssql-auth.dll` - Authentication library
127+
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)
128+
129+
### **macOS (.dylib files)**
130+
macOS builds use universal2 binaries and depend on:
131+
132+
**Packaged Dependencies (arm64 & x86_64):**
133+
- `libmsodbcsql.18.dylib` - Main driver
134+
- `libodbcinst.2.dylib` - Installer library
135+
136+
### **Linux (.so files)**
137+
Linux builds support multiple distributions:
138+
139+
**Debian/Ubuntu x86_64:**
140+
- `libmsodbcsql-18.5.so.1.1` - Main driver
141+
- `libodbcinst.so.2` - Installer library
142+
143+
**Debian/Ubuntu ARM64:**
144+
- `libmsodbcsql-18.5.so.1.1` - Main driver
145+
- `libodbcinst.so.2` - Installer library
146+
147+
**RHEL/CentOS x86_64:**
148+
- `libmsodbcsql-18.5.so.1.1` - Main driver
149+
- `libodbcinst.so.2` - Installer library
150+
151+
**RHEL/CentOS ARM64:**
152+
- `libmsodbcsql-18.5.so.1.1` - Main driver
153+
- `libodbcinst.so.2` - Installer library
154+
155+
## **Python Extension Modules**
156+
Your build system generates architecture-specific Python extension modules:
157+
158+
**Naming Convention:** `ddbc_bindings.cp{python_version}-{architecture}.{extension}`
159+
160+
Examples:
161+
- Windows x64: `ddbc_bindings.cp311-amd64.pyd`
162+
- Windows x86: `ddbc_bindings.cp311-win32.pyd`
163+
- Windows ARM64: `ddbc_bindings.cp311-arm64.pyd`
164+
- macOS Universal: `ddbc_bindings.cp311-universal2.so`
165+
- Linux x86_64: `ddbc_bindings.cp311-x86_64.so`
166+
- Linux ARM64: `ddbc_bindings.cp311-arm64.so`
167+

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111
import os
12-
from mssql_python import connect, ddbc_bindings
12+
from mssql_python import connect
1313
import time
1414

1515
def pytest_configure(config):

0 commit comments

Comments
 (0)