Skip to content

Commit 448e9a9

Browse files
authored
Merge pull request #34 from microsoft/alpha
CHORE: Merge `alpha` into `main`
2 parents e0e5c9b + 575cde7 commit 448e9a9

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
[Documentation](https://github.com/microsoft/mssql-python/wiki) | [Release Notes](https://github.com/microsoft/mssql-python/releases) | [Roadmap](https://github.com/microsoft/mssql-python/blob/main/ROADMAP.md)
66

7+
> **Note:**
8+
> This project is currently in an alpha phase, meaning it is still under active development. We are looking to validate core functionalities and gather initial feedback before a broader public launch. Please use with caution and avoid production environments.
9+
>
710
## Installation
811

912
mssql-python can be installed with [pip](http://pypi.python.org/pypi/pip)
@@ -48,11 +51,12 @@ import mssql_python
4851

4952
# Establish a connection
5053
# Specify connection string
51-
connection = ("SERVER=<your_server_name>;DATABASE=<your_database_name>;UID=<your_user_name>;PWD=<your_password>;Encrypt=yes;")
54+
connection_string = "SERVER=<your_server_name>;DATABASE=<your_database_name>;UID=<your_user_name>;PWD=<your_password>;Encrypt=yes;"
55+
connection = mssql_python.connect(connection_string)
5256

5357
# Execute a query
5458
cursor = connection.cursor()
55-
cursor.execute("SELECT @@version")
59+
cursor.execute("SELECT * from customer")
5660
rows = cursor.fetchall()
5761

5862
for row in rows:

setup.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
import sys
3+
import subprocess
4+
from setuptools import setup, Extension, find_packages
5+
from setuptools.command.build_ext import build_ext
6+
7+
class CMakeExtension(Extension):
8+
def __init__(self, name, sourcedir=''):
9+
# No sources; CMake handles the build.
10+
super().__init__(name, sources=[])
11+
self.sourcedir = os.path.abspath(sourcedir)
12+
13+
class CMakeBuild(build_ext):
14+
def run(self):
15+
# Check if CMake is installed
16+
try:
17+
subprocess.check_output(['cmake', '--version'])
18+
except OSError:
19+
raise RuntimeError("CMake must be installed to build these extensions.")
20+
for ext in self.extensions:
21+
self.build_extension(ext)
22+
23+
def build_extension(self, ext):
24+
# Calculate the directory where the final .pyd will be placed (inside mssql_python)
25+
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
26+
cfg = 'Debug' if self.debug else 'Release'
27+
cmake_args = [
28+
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
29+
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=' + extdir,
30+
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=' + extdir,
31+
'-DPYTHON_EXECUTABLE=' + sys.executable,
32+
'-DCMAKE_BUILD_TYPE=' + cfg
33+
]
34+
build_args = ['--config', cfg]
35+
36+
if not os.path.exists(self.build_temp):
37+
os.makedirs(self.build_temp)
38+
39+
# Configure CMake project
40+
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp)
41+
# Build the target defined in your CMakeLists.txt
42+
subprocess.check_call(['cmake', '--build', '.', '--target', 'ddbc_bindings'] + build_args, cwd=self.build_temp)
43+
44+
setup(
45+
name='mssql-python',
46+
version='0.1.5',
47+
description='A Python library for interacting with Microsoft SQL Server',
48+
long_description=open('README.md', encoding='utf-8').read(),
49+
long_description_content_type='text/markdown',
50+
author='Microsoft Corporation',
51+
author_email='pysqldriver@microsoft.com',
52+
url='https://github.com/microsoft/mssql-python',
53+
packages=find_packages(),
54+
package_data={
55+
# Include DLL files inside mssql_python
56+
'mssql_python': ['libs/*', 'libs/**/*', '*.dll']
57+
},
58+
include_package_data=True,
59+
# Requires Python 3.13
60+
python_requires='==3.13.*',
61+
# Naming the extension as mssql_python.ddbc_bindings puts the .pyd directly in mssql_python
62+
ext_modules=[CMakeExtension('mssql_python.ddbc_bindings', sourcedir='mssql_python/pybind')],
63+
cmdclass={'build_ext': CMakeBuild},
64+
zip_safe=False,
65+
)

0 commit comments

Comments
 (0)