-
Notifications
You must be signed in to change notification settings - Fork 27
Development Setup Guide
This mssql-python module helps developers set up their development environment for the mssql-python project with automatic code formatting and linting.
For VS Code users - Everything is automated!
-
Clone the repository
git clone https://github.com/microsoft/mssql-python.git cd mssql-python
-
Open in VS Code
code .
-
Install recommended extensions
- A notification will appear: "This workspace has extension recommendations"
- Click "Install All" or "Show Recommendations"
- VS Code will automatically install all required formatters and linters
-
Start coding!
- All settings are pre-configured in
.vscode/settings.json - Save any file (
Ctrl+S) and it auto-formats automatically ✨ - Linting runs in real-time
- All settings are pre-configured in
That's it! No manual configuration needed. The repository includes:
- ✅
.vscode/extensions.json- Automatic extension recommendations - ✅
.vscode/settings.json- Pre-configured formatter and linter settings - ✅
.clang-format- C++ formatting rules - ✅
pyproject.toml&.flake8- Python linting configuration
- Quick Start
- What's Included in This PR
- Prerequisites
- VS Code Setup
- Automatic Formatting
- Linting Configuration
- CI/CD Integration
- Troubleshooting
This PR adds comprehensive auto-formatting and linting configuration to streamline development:
Purpose: Automatically recommends required VS Code extensions
What it does:
- When developers open this repository in VS Code, they see a notification
- One click installs all necessary formatters and linters
- Ensures everyone uses the same development tools
Extensions recommended:
-
Python:
ms-python.python,ms-python.vscode-pylance,ms-python.black-formatter,ms-python.pylint,ms-python.flake8,ms-python.autopep8 -
C++:
ms-vscode.cpptools,ms-vscode.cpptools-extension-pack,xaver.clang-format,mine.cpplint -
Git (optional):
github.vscode-pull-request-github,eamodio.gitlens
Developer experience:
📢 VS Code Notification:
"This workspace has extension recommendations.
Would you like to install them?"
[Install All] [Show Recommendations] [Ignore]
Purpose: Pre-configured workspace settings for consistent formatting
What it configures:
- ✅ Enables
formatOnSavefor all files - ✅ Sets Black as default Python formatter (100-char line length)
- ✅ Sets clang-format as default C++ formatter (100-char line length)
- ✅ Configures all linters (Pylint, Flake8, cpplint) with project rules
- ✅ Enables Pylance type checking with inlay hints
- ✅ Automatic import organization on save
Key settings:
{
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": true
},
"black-formatter.args": ["--line-length=100"],
"cpplint.lineLength": 100
}Purpose: C++ code formatting rules (enforced by clang-format)
Configuration:
- Style: LLVM-based with Microsoft modifications
- Line length: 100 characters
- Indent: 4 spaces, no tabs
- Comment spacing: Minimum 2 spaces before inline comments (cpplint compliant)
-
Pointer alignment: Left (
int* ptr, notint *ptr)
Purpose: Python linting and formatting configuration
Configuration:
- Black line length: 100 characters
-
Flake8 ignores:
E203,W503,E501,E722,F401,F841,W293,W291,F541,F811,E402,E711,E712,E721,F821 -
Pylint disabled rules:
fixme,no-member,too-many-arguments,invalid-name, etc.
Purpose: Automated CI/CD linting checks on every PR
What it checks:
- ✅ Blocking (must pass): Black formatting for Python files
- ℹ️ Informational (warnings only): Flake8, Pylint, clang-format, cpplint
Workflow triggers:
- Pull requests to
mainordevelopbranches - Changes to
.py,.cpp,.c,.h,.hppfiles - Changes to config files (
.flake8,pyproject.toml,.clang-format)
- Updated to allow tracking of
.vscode/extensions.jsonand.vscode/settings.json - While
.vscode/*remains ignored, these specific config files are tracked usinggit add -f - This ensures shared configuration without tracking personal VS Code preferences
🚀 Zero Manual Setup
- Clone repo → Open in VS Code → Click "Install" → Start coding
- No need to configure formatters, linters, or settings manually
- Works identically for all team members
📏 Consistent Code Style
- Everyone uses the same formatters with identical settings
- Auto-format on save prevents style debates in PRs
- CI/CD enforces formatting standards automatically
🔍 Better Code Quality
- Real-time linting feedback in Problems panel (
Ctrl+Shift+M) - Type checking with Pylance inlay hints showing types inline
- Automatic import organization keeps code clean
⚡ Faster Onboarding
- New contributors get proper tooling immediately
- Documentation explains what's configured and why
- Troubleshooting guide for common issues
🎯 CI/CD Integration
- Automated checks on every PR
- Only Black formatting is blocking (easy to fix with
Ctrl+S) - Other linting issues are informational
For VS Code users (Recommended):
- Clone the repository
- Open the project in VS Code
- When prompted, click "Install" to install recommended extensions
- Extensions and settings are automatically configured!
- Start coding - your code will auto-format on save 🎉
- Visual Studio Code (latest version)
- Python 3.8+ (Python 3.13+ recommended)
- clang-format (version 10+)
- Git (for version control)
# Check Python version
python --version
# Check clang-format
clang-format --version
# Check pip
python -m pip --versionThis repository includes .vscode/extensions.json which automatically recommends required extensions when you open the project.
What happens when you open the repo:
- VS Code detects
.vscode/extensions.json - A notification appears: "This workspace has extension recommendations. Would you like to install them?"
- Click "Install All" or "Show Recommendations"
- All necessary extensions will be installed automatically
The following extensions will be automatically recommended:
-
Python (
ms-python.python) - Core Python language support -
Pylance (
ms-python.vscode-pylance) - Fast Python language server -
Black Formatter (
ms-python.black-formatter) - Python code formatter -
autopep8 (
ms-python.autopep8) - Alternative Python formatter -
Pylint (
ms-python.pylint) - Python linter -
Flake8 (
ms-python.flake8) - Python style guide enforcement
-
C/C++ (
ms-vscode.cpptools) - Microsoft's official C++ tools -
C/C++ Extension Pack (
ms-vscode.cpptools-extension-pack) - C++ tools bundle -
Clang-Format (
xaver.clang-format) - clang-format integration -
cpplint (
mine.cpplint) - Google C++ style guide checker
-
GitHub Pull Requests (
github.vscode-pull-request-github) - GitHub PR integration -
GitLens (
eamodio.gitlens) - Advanced Git features
If you prefer to install extensions manually:
# Install all extensions at once
code --install-extension ms-python.python
code --install-extension ms-python.vscode-pylance
code --install-extension ms-python.black-formatter
code --install-extension ms-python.autopep8
code --install-extension ms-python.pylint
code --install-extension ms-python.flake8
code --install-extension ms-vscode.cpptools
code --install-extension ms-vscode.cpptools-extension-pack
code --install-extension xaver.clang-format
code --install-extension mine.cpplint
code --install-extension github.vscode-pull-request-github
code --install-extension eamodio.gitlensThis repository includes .vscode/settings.json with pre-configured settings for:
- ✅ Auto-format on save
- ✅ Correct formatter selection (Black for Python, clang-format for C++)
- ✅ Linter configurations (line length, ignore rules)
- ✅ Type checking with Pylance
- ✅ Import organization
Key settings configured:
{
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
},
"black-formatter.args": ["--line-length=100"],
"flake8.args": ["--max-line-length=100"],
"cpplint.lineLength": 100
}# Navigate to project root
cd mssql-python
# Install development dependencies
python -m pip install -r requirements.txt
# This includes:
# - black (code formatter)
# - flake8 (style checker)
# - pylint (linter)
# - autopep8 (formatter)
# - cpplint (C++ linter)
# - mypy (type checker)Once you have the extensions installed and workspace settings loaded:
✅ Python Files (.py)
- Formatter: Black (line length: 100)
-
Trigger: Automatic on save (
Ctrl+S) - Import Organization: Automatically sorts imports
-
Manual Format:
Shift+Alt+F
✅ C++ Files (.cpp, .c, .h, .hpp)
-
Formatter: clang-format (uses
.clang-formatconfig) -
Trigger: Automatic on save (
Ctrl+S) - Style Guide: Microsoft/LLVM style (100-char lines)
- Comment Spacing: Minimum 2 spaces before inline comments
-
Manual Format:
Shift+Alt+F
| File Type | Extensions | Formatter | Line Length | On Save |
|---|---|---|---|---|
| Python | .py |
Black | 100 chars | ✅ Yes |
| C++ Source |
.cpp, .c
|
clang-format | 100 chars | ✅ Yes |
| C++ Headers |
.h, .hpp
|
clang-format | 100 chars | ✅ Yes |
The project includes the following configuration files:
-
.vscode/settings.json- VS Code workspace settings (auto-format, linters) -
.vscode/extensions.json- Extension recommendations -
.clang-format- C++ formatting rules (LLVM-based, 100-char limit) -
pyproject.toml- Python tool configuration (Black, pylint) -
.flake8- Python style guide settings
Enabled Linters:
- Pylint: Code quality and error detection
- Flake8: Style guide enforcement (PEP 8)
- mypy: Static type checking (optional)
Configuration:
- Line length: 100 characters (not 79)
- Ignores:
E203,W503(conflicts with Black) - Custom rules in
pyproject.tomland.flake8
Ignored Warnings:
# Common warnings that are ignored:
- E501 (line too long) - Black handles this
- E722 (bare except) - Sometimes necessary
- F401 (unused imports) - May be intentional
- E711/E712 (comparison to None/True/False)View Linting Errors:
- Open the Problems panel:
Ctrl+Shift+M - See real-time linting feedback as you type
Enabled Linter:
- cpplint: Google C++ Style Guide checker
Configuration:
- Line length: 100 characters
- Filtered warnings:
-
-legal/copyright(no copyright headers required) -
-build/include_subdir(flexible includes) -
-build/c++11(modern C++ features allowed)
-
Run Manually:
# Check a specific file
python -m cpplint --filter=-legal/copyright,-build/include_subdir,-build/c++11 --linelength=100 mssql_python\pybind\ddbc_bindings.cpp
# Check all C++ files
python -m cpplint --filter=-legal/copyright,-build/include_subdir,-build/c++11 --linelength=100 --recursive mssql_python\pybindThis repository includes .github/workflows/lint-check.yml that automatically checks all PRs for linting issues.
What Gets Checked on Every PR:
✅ Required Checks (Must Pass):
- Black formatting for Python files
ℹ️ Informational Checks (Won't Block PR):
- Flake8 (Python style)
- Pylint (Python code quality)
- clang-format (C++ formatting)
- cpplint (C++ style)
How It Works:
- PR is created or updated
- GitHub Actions runs linting checks
- Black formatting errors will block the PR
- Other linting issues are warnings only
- Review results in the "Checks" tab of your PR
Run these commands to ensure your PR will pass:
# Format Python files
black --line-length=100 mssql_python/ tests/
# Format C++ files
Get-ChildItem -Path mssql_python\pybind -Recurse -Include *.cpp,*.h,*.hpp | ForEach-Object { clang-format -i $_.FullName }
# Check Python linting
flake8 mssql_python/ tests/ --max-line-length=100
# Check C++ linting
python -m cpplint --filter=-legal/copyright,-build/include_subdir,-build/c++11 --linelength=100 --recursive mssql_python\pybindOr Simply:
- Save all files in VS Code (
Ctrl+S) - auto-formatting will fix most issues! ✨ - Check the Problems panel (
Ctrl+Shift+M) for remaining issues - Fix any remaining errors manually
The workspace uses Pylance with type checking enabled:
-
Type Checking Mode:
basic - Inlay Hints: Enabled for function returns, variables, and parameters
- Auto-imports: Enabled for better productivity
View Type Information:
- Hover over any variable/function to see type hints
- Press
Ctrl+Spacefor IntelliSense with type information - Inlay hints show return types and parameter types inline
- Open any Python file (e.g.,
mssql_python/connection.py) - Add some messy formatting (extra spaces, wrong indentation)
- Press
Ctrl+Sto save - ✅ File should auto-format with proper spacing
Example:
# Before save (messy)
def my_function( x,y,z ):
return x+y+z
# After save (formatted)
def my_function(x, y, z):
return x + y + z- Open any C++ file (e.g.,
mssql_python/pybind/ddbc_bindings.cpp) - Add some messy formatting
- Press
Ctrl+Sto save - ✅ File should auto-format with proper indentation and spacing
Example:
// Before save
int value = 42;// Comment too close
// After save
int value = 42; // Comment with 2 spaces| Action | Shortcut |
|---|---|
| Format Document | Shift+Alt+F |
| Format Selection | Ctrl+K Ctrl+F |
| Save (triggers format) | Ctrl+S |
| Problems Panel | Ctrl+Shift+M |
| Command Palette | Ctrl+Shift+P |
| Extensions Panel | Ctrl+Shift+X |
Issue: No prompt to install recommended extensions
Solution:
- Open Extensions panel:
Ctrl+Shift+X - Click the "Show Recommended Extensions" button (filter icon with star)
- You'll see workspace recommendations at the top
- Click "Install Workspace Recommended Extensions"
Issue: Black formatter doesn't run on save
Solution:
- Check Black is installed:
python -m black --version - Verify extension is installed: Check Extensions panel for "Black Formatter"
- Check Output panel:
View→Output→ Select "Black Formatter" - Reload VS Code:
Ctrl+Shift+P→ "Developer: Reload Window"
Issue: clang-format doesn't run on save
Solutions:
-
Check clang-format installation:
clang-format --version
-
Verify extension is active:
- Open Extensions (
Ctrl+Shift+X) - Search for "Clang-Format"
- Ensure
xaver.clang-formatis enabled
- Open Extensions (
-
Check formatter setting:
- Open Command Palette (
Ctrl+Shift+P) - Run "Preferences: Open Workspace Settings (JSON)"
- Verify:
"[cpp]": { "editor.defaultFormatter": "xaver.clang-format" }
- Open Command Palette (
-
Reload VS Code:
Ctrl+Shift+P→ "Developer: Reload Window"
Issue: Changes to .vscode/settings.json not taking effect
Solutions:
- Close and reopen VS Code completely
- Check for syntax errors in
settings.json(use JSON validator) - Check VS Code Output:
View→Output→ Select "Extension Host" - Try:
Ctrl+Shift+P→ "Developer: Reload Window"
Issue: No linting errors in Problems panel
Solutions:
- Open Problems panel:
Ctrl+Shift+M - Check linters are installed:
python -m flake8 --version python -m pylint --version python -m cpplint --version
- Check Output panel for each linter:
View→Output→ Select linter - Verify extensions are installed and enabled
Understanding the hierarchy:
- User Settings - Global settings for all projects
-
Workspace Settings (
.vscode/settings.json) - Override user settings for this project - Folder Settings - Override workspace settings (if multi-root workspace)
The .vscode/settings.json in this repo will override your personal preferences only for this project.
-
Before Starting Work:
- Pull latest changes from
main - Ensure all extensions are installed
- Verify auto-format works (test with
Ctrl+S)
- Pull latest changes from
-
While Coding:
- Save frequently (
Ctrl+S) - formatting happens automatically - Check Problems panel (
Ctrl+Shift+M) for linting errors - Fix linting issues as you go
- Save frequently (
-
Before Committing:
- Save all files (formats everything)
- Review Problems panel for any remaining issues
- Run tests if applicable
- Review
git diffto see formatting changes
-
Before Creating PR:
- Ensure all files are saved and formatted
- Check CI/CD workflow status
- Fix any failing checks before requesting review
- Formatting changes will appear in diffs - this is expected
- Focus reviews on logic, not formatting (automation handles that)
- If CI fails on Black formatting, simply save files and push again
- VS Code: https://code.visualstudio.com/docs
- Black Formatter: https://black.readthedocs.io/
- clang-format: https://clang.llvm.org/docs/ClangFormat.html
- cpplint: https://github.com/cpplint/cpplint
- PEP 8: https://pep8.org/
- Pylint: https://pylint.org/
- Check existing issues in the project repository
- Ask team lead or senior developers
- Review code review feedback for formatting standards
✅ Automated Setup:
- VS Code automatically prompts to install recommended extensions
- Workspace settings are pre-configured
- Just open the project and click "Install" - you're ready to code!
✅ Auto-formatting is configured for:
- Python files (
.py) - Black formatter, 100 char lines - C++ files (
.cpp,.c,.h,.hpp) - clang-format, 100 char lines
✅ Linting is enabled for:
- Python - Pylint + Flake8
- C++ - cpplint (Google Style Guide)
✅ CI/CD checks:
- Automated linting on every PR
- Only Black formatting is blocking
- Other checks are informational
✅ Type checking is enabled:
- Python - Pylance with basic mode and inlay hints
Just save your files (Ctrl+S) and everything formats automatically! 🎉