From a93e2fff3c993d0097a0d9b000b900e74fbc5ad9 Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Sat, 19 Jul 2025 06:00:15 +0000 Subject: [PATCH 01/13] Dev Container setup --- .devcontainer/Dockerfile | 69 ++++++++++++++++++ .devcontainer/devcontainer.json | 76 ++++++++++++++++++++ .devcontainer/post-create.sh | 89 +++++++++++++++++++++++ .dockerignore | 120 ++++++++++++++++++++++++++++++++ 4 files changed, 354 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/post-create.sh create mode 100644 .dockerignore diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..9e8185356 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,69 @@ +# Use Python 3.11 with Debian Bullseye as the base image +FROM mcr.microsoft.com/devcontainers/python:3.10-bullseye + +# Set environment variables +ENV DEBIAN_FRONTEND=noninteractive +ENV PYTHONPATH=/workspaces/mssql-python +ENV CMAKE_BUILD_TYPE=Debug + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + # Build tools + build-essential \ + cmake \ + pkg-config \ + ninja-build \ + # Additional tools + curl \ + wget \ + git \ + vim \ + nano \ + htop \ + tree \ + jq \ + # Clean up + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Microsoft ODBC Driver for SQL Server +RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \ + && curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \ + && apt-get update \ + && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \ + && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Add mssql-tools to PATH +ENV PATH="$PATH:/opt/mssql-tools18/bin" + +# Upgrade pip and install common Python development tools +RUN python -m pip install --upgrade pip setuptools wheel \ + && pip install \ + black \ + flake8 \ + mypy \ + isort \ + pre-commit \ + twine \ + build \ + wheel \ + "pybind11[global]" \ + pytest-xdist \ + pytest-mock \ + "coverage[toml]" + +# Set the default user to vscode (created by the base image) +USER vscode + +# Set the working directory +WORKDIR /workspaces/mssql-python + +# Add helpful aliases to .bashrc +RUN echo 'alias ll="ls -alF"' >> ~/.bashrc \ + && echo 'alias la="ls -A"' >> ~/.bashrc \ + && echo 'alias l="ls -CF"' >> ~/.bashrc + +# Default command +CMD ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..a285a443f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,76 @@ +{ + "name": "MSSQL Python Driver", + "build": { + "dockerfile": "Dockerfile", + "context": "." + }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "cmake.configureOnOpen": false + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.pylint", + "ms-toolsai.jupyter", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + "github.copilot", + "github.copilot-chat", + "ms-vscode.test-adapter-converter", + "littlefoxteam.vscode-python-test-adapter", + "ms-azuretools.vscode-docker", + "ms-mssql.mssql", + ] + } + }, + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": true, + "configureZshAsDefaultShell": true, + "installOhMyZsh": true, + "upgradePackages": true, + "username": "vscode", + "userUid": "automatic", + "userGid": "automatic" + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash .devcontainer/post-create.sh", + // Use 'postStartCommand' to run commands after the container starts. + "postStartCommand": "", + // Configure tool-specific properties. + "remoteUser": "vscode", + // Set container environment variables + "containerEnv": { + "PYTHONPATH": "/workspaces/mssql-python", + "CMAKE_BUILD_TYPE": "Debug" + }, + // Mount the project directory + "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/mssql-python,type=bind,consistency=cached", + "workspaceFolder": "/workspaces/mssql-python", +} \ No newline at end of file diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100755 index 000000000..c95080b0a --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Post-create script for MSSQL Python Driver devcontainer +set -e + +echo "🚀 Setting up MSSQL Python Driver development environment..." + +# Update package lists +echo "📦 Updating package lists..." +sudo apt-get update + +# Install system dependencies required for the project +echo "🔧 Installing system dependencies..." +sudo apt-get install -y \ + python3 \ + python3-pip \ + python3-venv \ + python3-full \ + cmake \ + curl \ + wget \ + gnupg \ + software-properties-common \ + build-essential \ + python3-dev \ + pybind11-dev + +export TZ=UTC +ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone + +# Install Microsoft ODBC Driver for SQL Server (required for mssql connectivity) +echo "🗄️ Installing Microsoft ODBC Driver for SQL Server..." +curl -sSL -O https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb +sudo dpkg -i packages-microsoft-prod.deb || true +rm packages-microsoft-prod.deb + +sudo apt-get update +# Install the driver +ACCEPT_EULA=Y sudo apt-get install -y msodbcsql18 +# optional: for bcp and sqlcmd +ACCEPT_EULA=Y sudo apt-get install -y mssql-tools18 +# optional: for unixODBC development headers +sudo apt-get install -y unixodbc-dev + +# Create a Python virtual environment +echo "🐍 Creating Python virtual environment..." +python3 -m venv /workspaces/mssql-python/opt/venv +source /workspaces/mssql-python/opt/venv/bin/activate + +# Install dependencies in the virtual environment +python -m pip install --upgrade pip +python -m pip install -r requirements.txt + +# Make the virtual environment globally available +echo 'source /workspaces/mssql-python/opt/venv/bin/activate' >> ~/.bashrc + +source /workspaces/mssql-python/opt/venv/bin/activate + +# Install project dependencies +echo "📚 Installing project dependencies..." +pip install -r requirements.txt + +# Create useful aliases +echo "⚡ Setting up aliases..." +cat >> ~/.bashrc << 'EOF' + +# MSSQL Python Driver aliases +alias ll='ls -alF' +alias la='ls -A' +alias l='ls -CF' +alias clean='find . -type f -name "*.pyc" -delete && find . -type d -name "__pycache__" -delete' + +EOF + +# Set up git configuration (if not already configured) +echo "🔧 Configuring git..." +if [ -z "$(git config --global user.name)" ]; then + echo "Git user name not set. You may want to configure it with:" + echo " git config --global user.name 'Your Name'" +fi +if [ -z "$(git config --global user.email)" ]; then + echo "Git user email not set. You may want to configure it with:" + echo " git config --global user.email 'your.email@example.com'" +fi + +# Display information about the environment +echo "" +echo "✅ Development environment setup complete!" + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..06ca55f4a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,120 @@ +# Git +.git +.gitignore +.gitattributes + +# Python +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env +pip-log.txt +pip-delete-this-directory.txt +.tox +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.git +.mypy_cache +.pytest_cache +.hypothesis + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Documentation +docs/_build/ + +# PyBuilder +target/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Temporary files +*.tmp +*.temp +*.log + +# Node.js (if any) +node_modules/ +npm-debug.log* + +# CMake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile +*.cmake + +# Build artifacts +*.so +*.dll +*.dylib +*.pdb +*.obj +*.exe + +# Test results +test-results/ +.pytest_cache/ + +# Azure DevOps +.azure/ From 2383b7bc7a11140fe5acd80efa2c60120d8f5845 Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Sat, 19 Jul 2025 06:36:59 +0000 Subject: [PATCH 02/13] REFACTOR: Simplify post-create script by removing redundant activation of virtual environment --- .devcontainer/post-create.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index c95080b0a..58fd46430 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -26,7 +26,7 @@ sudo apt-get install -y \ pybind11-dev export TZ=UTC -ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone +ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Install Microsoft ODBC Driver for SQL Server (required for mssql connectivity) echo "🗄️ Installing Microsoft ODBC Driver for SQL Server..." @@ -47,15 +47,11 @@ echo "🐍 Creating Python virtual environment..." python3 -m venv /workspaces/mssql-python/opt/venv source /workspaces/mssql-python/opt/venv/bin/activate -# Install dependencies in the virtual environment python -m pip install --upgrade pip -python -m pip install -r requirements.txt # Make the virtual environment globally available echo 'source /workspaces/mssql-python/opt/venv/bin/activate' >> ~/.bashrc -source /workspaces/mssql-python/opt/venv/bin/activate - # Install project dependencies echo "📚 Installing project dependencies..." pip install -r requirements.txt From 1f505849856ac1b21ef844a7107c1cf38f5a6ac2 Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:44:00 -0700 Subject: [PATCH 03/13] Update .dockerignore Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 06ca55f4a..66939767d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -26,7 +26,6 @@ coverage.xml .hypothesis # Distribution / packaging -.Python build/ develop-eggs/ dist/ From 6f79cd296a55884193015ca5c329aa8627749bda Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:44:07 -0700 Subject: [PATCH 04/13] Update .devcontainer/Dockerfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9e8185356..555d94fc7 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -# Use Python 3.11 with Debian Bullseye as the base image +# Use Python 3.10 with Debian Bullseye as the base image FROM mcr.microsoft.com/devcontainers/python:3.10-bullseye # Set environment variables From 1e4c8cc32984d9fc1ddcb9fdf074b955e983fcd0 Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:44:22 -0700 Subject: [PATCH 05/13] Update .dockerignore Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 66939767d..18f680c6b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -52,9 +52,9 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ -.tox/ .coverage .coverage.* +.coverage.* .cache nosetests.xml coverage.xml From 92b1c1f722cf847b8887e67dcedeaab846f33691 Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:44:34 -0700 Subject: [PATCH 06/13] Update .dockerignore Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 18f680c6b..75431372f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -20,7 +20,6 @@ nosetests.xml coverage.xml *.cover *.log -.git .mypy_cache .pytest_cache .hypothesis From 78d129f7fa0279a2a85fae9d46b8058533f8d86d Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:44:43 -0700 Subject: [PATCH 07/13] Update .dockerignore Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 75431372f..20c2251af 100644 --- a/.dockerignore +++ b/.dockerignore @@ -47,7 +47,6 @@ wheels/ # Installer logs pip-log.txt -pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ From b5e940a513f9916f86494cdbf122286e1e5252a1 Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:45:05 -0700 Subject: [PATCH 08/13] Update .devcontainer/devcontainer.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a285a443f..4993120b1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -38,7 +38,7 @@ "ms-vscode.test-adapter-converter", "littlefoxteam.vscode-python-test-adapter", "ms-azuretools.vscode-docker", - "ms-mssql.mssql", + "ms-mssql.mssql" ] } }, From 306ae47c1f10f4591befe1f4404b7cddb0012a7c Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:45:21 -0700 Subject: [PATCH 09/13] Update .devcontainer/devcontainer.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4993120b1..8be46461a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -72,5 +72,5 @@ }, // Mount the project directory "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/mssql-python,type=bind,consistency=cached", - "workspaceFolder": "/workspaces/mssql-python", + "workspaceFolder": "/workspaces/mssql-python" } \ No newline at end of file From 386b81be3002486e52a878de11e9df145e1d629d Mon Sep 17 00:00:00 2001 From: Saurabh Singh <1623701+saurabh500@users.noreply.github.com> Date: Sat, 19 Jul 2025 11:41:47 -0700 Subject: [PATCH 10/13] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .dockerignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 20c2251af..8c2fe6142 100644 --- a/.dockerignore +++ b/.dockerignore @@ -52,8 +52,6 @@ pip-log.txt htmlcov/ .coverage .coverage.* -.coverage.* -.cache nosetests.xml coverage.xml *.cover From f534e5c92f8bf92c6d6383b80fe7a2f904242b2a Mon Sep 17 00:00:00 2001 From: David Levy Date: Sat, 31 Jan 2026 16:54:37 -0600 Subject: [PATCH 11/13] CHORE: Upgrade to Python 3.14, fix duplicate ODBC, modernize settings --- .devcontainer/Dockerfile | 9 +++++---- .devcontainer/devcontainer.json | 18 ++++++------------ .devcontainer/post-create.sh | 26 ++++++++++---------------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 555d94fc7..d35d4a389 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,5 @@ -# Use Python 3.10 with Debian Bullseye as the base image -FROM mcr.microsoft.com/devcontainers/python:3.10-bullseye +# Use Python 3.14 with Debian Bookworm as the base image +FROM mcr.microsoft.com/devcontainers/python:3.14-bookworm # Set environment variables ENV DEBIAN_FRONTEND=noninteractive @@ -27,8 +27,9 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Install Microsoft ODBC Driver for SQL Server -RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \ - && curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \ +RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \ + && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \ + && sed -i 's/^deb /deb [signed-by=\/usr\/share\/keyrings\/microsoft-prod.gpg] /' /etc/apt/sources.list.d/mssql-release.list \ && apt-get update \ && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \ && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8be46461a..18dd19686 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,18 +10,12 @@ "vscode": { // Set *default* container specific settings.json values on container create. "settings": { - "python.defaultInterpreterPath": "/usr/local/bin/python", - "python.linting.enabled": true, - "python.linting.pylintEnabled": true, - "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", - "python.formatting.blackPath": "/usr/local/py-utils/bin/black", - "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", - "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", - "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", - "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", - "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", - "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", - "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "python.defaultInterpreterPath": "/workspaces/mssql-python/.venv/bin/python", + "python.terminal.activateEnvironment": true, + "editor.formatOnSave": true, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, "cmake.configureOnOpen": false }, // Add the IDs of extensions you want installed when the container is created. diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 58fd46430..ba0cd7302 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -28,34 +28,28 @@ sudo apt-get install -y \ export TZ=UTC ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -# Install Microsoft ODBC Driver for SQL Server (required for mssql connectivity) -echo "🗄️ Installing Microsoft ODBC Driver for SQL Server..." -curl -sSL -O https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -sudo dpkg -i packages-microsoft-prod.deb || true -rm packages-microsoft-prod.deb - -sudo apt-get update -# Install the driver -ACCEPT_EULA=Y sudo apt-get install -y msodbcsql18 -# optional: for bcp and sqlcmd -ACCEPT_EULA=Y sudo apt-get install -y mssql-tools18 -# optional: for unixODBC development headers -sudo apt-get install -y unixodbc-dev +# Note: ODBC Driver is already installed in the Dockerfile # Create a Python virtual environment echo "🐍 Creating Python virtual environment..." -python3 -m venv /workspaces/mssql-python/opt/venv -source /workspaces/mssql-python/opt/venv/bin/activate +python3 -m venv /workspaces/mssql-python/.venv +source /workspaces/mssql-python/.venv/bin/activate python -m pip install --upgrade pip # Make the virtual environment globally available -echo 'source /workspaces/mssql-python/opt/venv/bin/activate' >> ~/.bashrc +echo 'source /workspaces/mssql-python/.venv/bin/activate' >> ~/.bashrc # Install project dependencies echo "📚 Installing project dependencies..." pip install -r requirements.txt +# Build the native extension +echo "🔨 Building native extension..." +cd /workspaces/mssql-python/mssql_python/pybind +./build.sh +cd /workspaces/mssql-python + # Create useful aliases echo "⚡ Setting up aliases..." cat >> ~/.bashrc << 'EOF' From 37ecdff443259e520d3e843c1387cb17c8b3413e Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 4 Feb 2026 15:00:24 +0530 Subject: [PATCH 12/13] fix(devcontainer): add unixodbc-dev, move Python setup to post-create, ARM64 support - Add unixodbc-dev package for ODBC headers (fixes sql.h not found) - Move Python package installation from Dockerfile to post-create.sh - Add ARM64 support: use Azure SQL Edge instead of SQL Server 2025 - Make SQL Server container startup non-fatal (optional) - Fix false success reporting when build fails - Disable CMake auto-configure to prevent duplicate builds - Generate random SA password and store connection string --- .devcontainer/Dockerfile | 42 ++++------ .devcontainer/devcontainer.json | 37 ++++---- .devcontainer/post-create.sh | 144 +++++++++++++++++++------------- 3 files changed, 120 insertions(+), 103 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d35d4a389..6b684a13f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -6,14 +6,26 @@ ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONPATH=/workspaces/mssql-python ENV CMAKE_BUILD_TYPE=Debug -# Install system dependencies +# Set timezone (configurable via build arg) +ARG TZ=UTC +ENV TZ=$TZ +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ + && echo $TZ > /etc/timezone + +# Install all system dependencies in one layer RUN apt-get update && apt-get install -y \ # Build tools build-essential \ cmake \ pkg-config \ ninja-build \ - # Additional tools + python3-dev \ + pybind11-dev \ + # ODBC prerequisites (unixodbc-dev provides sql.h headers for compilation) + unixodbc-dev \ + gnupg \ + software-properties-common \ + # Utilities curl \ wget \ git \ @@ -27,9 +39,8 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Install Microsoft ODBC Driver for SQL Server -RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \ - && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \ - && sed -i 's/^deb /deb [signed-by=\/usr\/share\/keyrings\/microsoft-prod.gpg] /' /etc/apt/sources.list.d/mssql-release.list \ +RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \ + && echo "deb [arch=arm64,amd64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list \ && apt-get update \ && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \ && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \ @@ -39,32 +50,11 @@ RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /u # Add mssql-tools to PATH ENV PATH="$PATH:/opt/mssql-tools18/bin" -# Upgrade pip and install common Python development tools -RUN python -m pip install --upgrade pip setuptools wheel \ - && pip install \ - black \ - flake8 \ - mypy \ - isort \ - pre-commit \ - twine \ - build \ - wheel \ - "pybind11[global]" \ - pytest-xdist \ - pytest-mock \ - "coverage[toml]" - # Set the default user to vscode (created by the base image) USER vscode # Set the working directory WORKDIR /workspaces/mssql-python -# Add helpful aliases to .bashrc -RUN echo 'alias ll="ls -alF"' >> ~/.bashrc \ - && echo 'alias la="ls -A"' >> ~/.bashrc \ - && echo 'alias l="ls -CF"' >> ~/.bashrc - # Default command CMD ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 18dd19686..39ae36e46 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,25 +4,30 @@ "dockerfile": "Dockerfile", "context": "." }, - // Configure tool-specific properties. "customizations": { - // Configure properties specific to VS Code. "vscode": { - // Set *default* container specific settings.json values on container create. "settings": { - "python.defaultInterpreterPath": "/workspaces/mssql-python/.venv/bin/python", - "python.terminal.activateEnvironment": true, + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.terminal.activateEnvironment": false, "editor.formatOnSave": true, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, - "cmake.configureOnOpen": false + "cmake.configureOnOpen": false, + "cmake.configureOnEdit": false, + "cmake.automaticReconfigure": false, + "files.exclude": { + "**/__pycache__": true, + "**/*.pyc": true, + "**/.pytest_cache": true, + "**/build": true + } }, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-python.python", "ms-python.vscode-pylance", "ms-python.pylint", + "ms-python.black-formatter", "ms-toolsai.jupyter", "ms-vscode.cmake-tools", "ms-vscode.cpptools", @@ -36,7 +41,6 @@ ] } }, - // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {}, @@ -51,20 +55,19 @@ "userGid": "automatic" } }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. + "forwardPorts": [1433], + "portsAttributes": { + "1433": { + "label": "SQL Server", + "onAutoForward": "notify" + } + }, "postCreateCommand": "bash .devcontainer/post-create.sh", - // Use 'postStartCommand' to run commands after the container starts. - "postStartCommand": "", - // Configure tool-specific properties. "remoteUser": "vscode", - // Set container environment variables "containerEnv": { "PYTHONPATH": "/workspaces/mssql-python", "CMAKE_BUILD_TYPE": "Debug" }, - // Mount the project directory "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/mssql-python,type=bind,consistency=cached", "workspaceFolder": "/workspaces/mssql-python" -} \ No newline at end of file +} diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index ba0cd7302..ed08b4ee3 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -5,75 +5,99 @@ set -e echo "🚀 Setting up MSSQL Python Driver development environment..." -# Update package lists -echo "📦 Updating package lists..." -sudo apt-get update - -# Install system dependencies required for the project -echo "🔧 Installing system dependencies..." -sudo apt-get install -y \ - python3 \ - python3-pip \ - python3-venv \ - python3-full \ - cmake \ - curl \ - wget \ - gnupg \ - software-properties-common \ - build-essential \ - python3-dev \ - pybind11-dev - -export TZ=UTC -ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -# Note: ODBC Driver is already installed in the Dockerfile - -# Create a Python virtual environment -echo "🐍 Creating Python virtual environment..." -python3 -m venv /workspaces/mssql-python/.venv -source /workspaces/mssql-python/.venv/bin/activate - -python -m pip install --upgrade pip - -# Make the virtual environment globally available -echo 'source /workspaces/mssql-python/.venv/bin/activate' >> ~/.bashrc - -# Install project dependencies -echo "📚 Installing project dependencies..." +# Install Python packages from requirements.txt +echo "📦 Installing Python packages..." +pip install --upgrade pip setuptools wheel pip install -r requirements.txt -# Build the native extension -echo "🔨 Building native extension..." -cd /workspaces/mssql-python/mssql_python/pybind -./build.sh -cd /workspaces/mssql-python +# Create symlink for 'python' command (build.sh expects it) +echo "🔗 Creating python symlink..." +sudo ln -sf $(which python3) /usr/local/bin/python -# Create useful aliases +# Set up useful bash aliases echo "⚡ Setting up aliases..." -cat >> ~/.bashrc << 'EOF' +cat > ~/.bash_aliases << 'EOF' +# MSSQL Python Driver development aliases +alias build='cd mssql_python/pybind && ./build.sh && cd ../..' +alias test='python -m pytest -v' +EOF -# MSSQL Python Driver aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' -alias clean='find . -type f -name "*.pyc" -delete && find . -type d -name "__pycache__" -delete' +# Ensure .bash_aliases is sourced +grep -qxF 'source ~/.bash_aliases' ~/.bashrc || echo 'source ~/.bash_aliases' >> ~/.bashrc -EOF +# Verify environment +echo "" +echo "🔍 Verifying environment..." +python --version +pip --version +cmake --version +if command -v sqlcmd &> /dev/null; then + echo "✅ sqlcmd available" +else + echo "❌ sqlcmd not found" +fi -# Set up git configuration (if not already configured) -echo "🔧 Configuring git..." -if [ -z "$(git config --global user.name)" ]; then - echo "Git user name not set. You may want to configure it with:" - echo " git config --global user.name 'Your Name'" +# Build the C++ extension +echo "" +echo "🔨 Building C++ extension..." +if cd mssql_python/pybind && ./build.sh && cd ../..; then + echo "✅ C++ extension built successfully" +else + echo "❌ C++ extension build failed!" + exit 1 fi -if [ -z "$(git config --global user.email)" ]; then - echo "Git user email not set. You may want to configure it with:" - echo " git config --global user.email 'your.email@example.com'" + +# Generate random password for SQL Server +echo "" +echo "Generating SQL Server password..." +SA_PASSWORD="$(openssl rand -base64 16 | tr -dc 'A-Za-z0-9' | head -c 16)Aa1!" +echo "$SA_PASSWORD" > /tmp/.sqlserver_sa_password +chmod 600 /tmp/.sqlserver_sa_password + +# Start SQL Server container (use Azure SQL Edge for ARM64 compatibility) +# This is optional - if Docker-in-Docker fails, the devcontainer still works +echo "" +echo "Starting SQL Server container (optional)..." + +ARCH=$(uname -m) +if [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then + echo "Detected ARM64 - using Azure SQL Edge..." + docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \ + -p 1433:1433 --name sqlserver \ + -d mcr.microsoft.com/azure-sql-edge:latest && SQL_STARTED=true || SQL_STARTED=false +else + echo "Detected x86_64 - using SQL Server 2025..." + docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \ + -p 1433:1433 --name sqlserver \ + -d mcr.microsoft.com/mssql/server:2025-latest && SQL_STARTED=true || SQL_STARTED=false +fi + +if [ "$SQL_STARTED" = "true" ]; then + echo "Waiting for SQL Server to start..." + sleep 15 +else + echo "WARNING: SQL Server container failed to start (Docker issue)" + echo " You can start it manually later with:" + echo " docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver -d mcr.microsoft.com/azure-sql-edge:latest" fi -# Display information about the environment +# Set DB_CONNECTION_STRING environment variable +DB_CONNECTION_STRING="Server=localhost,1433;Database=master;User Id=sa;Password=$SA_PASSWORD;TrustServerCertificate=True" +echo "$DB_CONNECTION_STRING" > /tmp/.sqlserver_connection_string +chmod 600 /tmp/.sqlserver_connection_string +echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.bashrc +export DB_CONNECTION_STRING + +# Display completion message and next steps echo "" echo "✅ Development environment setup complete!" - +echo "" +echo "📋 Next steps:" +echo " 1. Run tests: test" +echo " 2. Start coding!" +echo "" +echo "💡 Tips:" +echo " - Use 'build' alias to rebuild C++ extension after changes" +echo " - SA password stored in: /tmp/.sqlserver_sa_password" +echo " - Connection string in: /tmp/.sqlserver_connection_string" +echo "" From 33f3611b3cb19d1d575cd98b6a58ea228db5a62a Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 4 Feb 2026 15:47:44 +0530 Subject: [PATCH 13/13] fix(devcontainer): improve shell aliases and connection string setup - Add aliases for both bash and zsh - Persist DB_CONNECTION_STRING to /etc/environment and shell rc files - Improve completion message with quick start commands --- .devcontainer/post-create.sh | 46 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index ed08b4ee3..63062828b 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -14,16 +14,17 @@ pip install -r requirements.txt echo "🔗 Creating python symlink..." sudo ln -sf $(which python3) /usr/local/bin/python -# Set up useful bash aliases +# Set up useful shell aliases (for both bash and zsh) echo "⚡ Setting up aliases..." -cat > ~/.bash_aliases << 'EOF' +cat > ~/.shell_aliases << 'EOF' # MSSQL Python Driver development aliases -alias build='cd mssql_python/pybind && ./build.sh && cd ../..' +alias build='cd /workspaces/mssql-python/mssql_python/pybind && ./build.sh && cd /workspaces/mssql-python' alias test='python -m pytest -v' EOF -# Ensure .bash_aliases is sourced -grep -qxF 'source ~/.bash_aliases' ~/.bashrc || echo 'source ~/.bash_aliases' >> ~/.bashrc +# Ensure aliases are sourced in both shells +grep -qxF 'source ~/.shell_aliases' ~/.bashrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.bashrc +grep -qxF 'source ~/.shell_aliases' ~/.zshrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.zshrc # Verify environment echo "" @@ -81,23 +82,34 @@ else echo " docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver -d mcr.microsoft.com/azure-sql-edge:latest" fi -# Set DB_CONNECTION_STRING environment variable -DB_CONNECTION_STRING="Server=localhost,1433;Database=master;User Id=sa;Password=$SA_PASSWORD;TrustServerCertificate=True" -echo "$DB_CONNECTION_STRING" > /tmp/.sqlserver_connection_string -chmod 600 /tmp/.sqlserver_connection_string +# Set DB_CONNECTION_STRING environment variable (persist across all terminals) +DB_CONNECTION_STRING="Server=localhost,1433;Database=master;UID=sa;PWD=$SA_PASSWORD;TrustServerCertificate=Yes;Encrypt=Yes" + +# Write to /etc/environment for system-wide persistence +echo "DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" | sudo tee -a /etc/environment > /dev/null + +# Also add to shell rc files for immediate availability in new terminals echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.bashrc +echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.zshrc + +# Export for current session export DB_CONNECTION_STRING # Display completion message and next steps echo "" -echo "✅ Development environment setup complete!" +echo "==============================================" +echo "🎉 Dev environment setup complete!" +echo "==============================================" +echo "" +echo "📦 What's ready:" +echo " ✅ C++ extension built" +echo " ✅ SQL Server running (localhost:1433)" +echo " ✅ DB_CONNECTION_STRING set in environment" echo "" -echo "📋 Next steps:" -echo " 1. Run tests: test" -echo " 2. Start coding!" +echo "🚀 Quick start - just type these commands:" +echo " python main.py → Test the connection" +echo " test → Run all pytest tests" +echo " build → Rebuild C++ extension" echo "" -echo "💡 Tips:" -echo " - Use 'build' alias to rebuild C++ extension after changes" -echo " - SA password stored in: /tmp/.sqlserver_sa_password" -echo " - Connection string in: /tmp/.sqlserver_connection_string" +echo "==============================================" echo ""