Skip to content

Commit e363b72

Browse files
committed
refactor: rename build_ddbc → build_backend, move platform_utils
- Rename build_ddbc/ to build_backend/ for clearer naming - Rename build_backend.py to hooks.py (PEP 517 hook module) - Move platform_utils.py from mssql_python/ to build_backend/ (it was never imported by mssql_python modules, only by build tools) - Add [project.scripts] entry: build-ddbc = build_backend.__main__:main - Update pyproject.toml build-backend path to build_backend.hooks - Update all test imports to use build_backend.platform_utils - Update setup.py import to use build_backend.platform_utils
1 parent 6bfe9fe commit e363b72

9 files changed

Lines changed: 181 additions & 182 deletions

File tree

build_backend/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
build_backend - Build system for mssql-python native extensions.
3+
4+
This package provides:
5+
1. A CLI tool: `python -m build_backend`
6+
2. A PEP 517 build backend that auto-compiles ddbc_bindings
7+
8+
Usage:
9+
python -m build_backend # Compile ddbc_bindings only
10+
python -m build_backend --arch arm64 # Specify architecture (Windows)
11+
python -m build_backend --coverage # Enable coverage (Linux)
12+
python -m build # Compile + create wheel (automatic)
13+
"""
14+
15+
from .compiler import compile_ddbc
16+
from .platform_utils import get_platform_info
17+
18+
__all__ = ["compile_ddbc", "get_platform_info"]
19+
__version__ = "1.3.0"
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
"""
2-
CLI entry point for build_ddbc.
2+
CLI entry point for build_backend.
33
44
Usage:
5-
python -m build_ddbc # Compile ddbc_bindings
6-
python -m build_ddbc --arch arm64 # Specify architecture (Windows)
7-
python -m build_ddbc --coverage # Enable coverage (Linux)
8-
python -m build_ddbc --help # Show help
5+
python -m build_backend # Compile ddbc_bindings
6+
python -m build_backend --arch arm64 # Specify architecture (Windows)
7+
python -m build_backend --coverage # Enable coverage (Linux)
8+
python -m build_backend --help # Show help
99
"""
1010

1111
import argparse
1212
import sys
1313

1414
from . import __version__
15-
from .compiler import compile_ddbc, get_platform_info
15+
from .compiler import compile_ddbc
16+
from .platform_utils import get_platform_info
1617

1718

1819
def main() -> int:
1920
"""Main entry point for the CLI."""
2021
parser = argparse.ArgumentParser(
21-
prog="python -m build_ddbc",
22+
prog="python -m build_backend",
2223
description="Compile ddbc_bindings native extension for mssql-python",
2324
formatter_class=argparse.RawDescriptionHelpFormatter,
2425
epilog="""
2526
Examples:
26-
python -m build_ddbc # Build for current platform
27-
python -m build_ddbc --arch arm64 # Build for ARM64 (Windows)
28-
python -m build_ddbc --coverage # Build with coverage (Linux)
29-
python -m build_ddbc --quiet # Build without output
27+
python -m build_backend # Build for current platform
28+
python -m build_backend --arch arm64 # Build for ARM64 (Windows)
29+
python -m build_backend --coverage # Build with coverage (Linux)
30+
python -m build_backend --quiet # Build without output
3031
""",
3132
)
3233

@@ -59,9 +60,9 @@ def main() -> int:
5960
# Show platform info
6061
if not args.quiet:
6162
arch, platform_tag = get_platform_info()
62-
print(f"[build_ddbc] Platform: {sys.platform}")
63-
print(f"[build_ddbc] Architecture: {arch}")
64-
print(f"[build_ddbc] Platform tag: {platform_tag}")
63+
print(f"[build_backend] Platform: {sys.platform}")
64+
print(f"[build_backend] Architecture: {arch}")
65+
print(f"[build_backend] Platform tag: {platform_tag}")
6566
print()
6667

6768
try:
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
from pathlib import Path
1010
from typing import Optional
1111

12-
# Import platform_utils directly without going through mssql_python.__init__
13-
# (which loads the native ddbc_bindings .so).
14-
_mssql_dir = str(Path(__file__).resolve().parent.parent / "mssql_python")
15-
sys.path.insert(0, _mssql_dir)
16-
import platform_utils as _platform_utils # noqa: E402
17-
sys.path.remove(_mssql_dir)
18-
19-
get_platform_info = _platform_utils.get_platform_info
12+
from .platform_utils import get_platform_info
2013

2114

2215
def find_pybind_dir() -> Path:
@@ -80,8 +73,8 @@ def _run_windows_build(pybind_dir: Path, arch: str, verbose: bool) -> bool:
8073
cmd = [str(build_script), arch]
8174

8275
if verbose:
83-
print(f"[build_ddbc] Running: {' '.join(cmd)}")
84-
print(f"[build_ddbc] Working directory: {pybind_dir}")
76+
print(f"[build_backend] Running: {' '.join(cmd)}")
77+
print(f"[build_backend] Working directory: {pybind_dir}")
8578

8679
result = subprocess.run(
8780
cmd,
@@ -99,7 +92,7 @@ def _run_windows_build(pybind_dir: Path, arch: str, verbose: bool) -> bool:
9992
raise RuntimeError(f"build.bat failed with exit code {result.returncode}")
10093

10194
if verbose:
102-
print("[build_ddbc] Windows build completed successfully!")
95+
print("[build_backend] Windows build completed successfully!")
10396

10497
return True
10598

@@ -118,8 +111,8 @@ def _run_unix_build(pybind_dir: Path, coverage: bool, verbose: bool) -> bool:
118111
cmd.append("--coverage")
119112

120113
if verbose:
121-
print(f"[build_ddbc] Running: {' '.join(cmd)}")
122-
print(f"[build_ddbc] Working directory: {pybind_dir}")
114+
print(f"[build_backend] Running: {' '.join(cmd)}")
115+
print(f"[build_backend] Working directory: {pybind_dir}")
123116

124117
result = subprocess.run(
125118
cmd,
@@ -137,6 +130,6 @@ def _run_unix_build(pybind_dir: Path, coverage: bool, verbose: bool) -> bool:
137130
raise RuntimeError(f"build.sh failed with exit code {result.returncode}")
138131

139132
if verbose:
140-
print("[build_ddbc] Unix build completed successfully!")
133+
print("[build_backend] Unix build completed successfully!")
141134

142135
return True
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Usage in pyproject.toml:
88
[build-system]
99
requires = ["setuptools>=61.0", "wheel", "pybind11"]
10-
build-backend = "build_ddbc.build_backend"
10+
build-backend = "build_backend.hooks"
1111
backend-path = ["."]
1212
"""
1313

@@ -125,16 +125,30 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
125125
"""
126126
print("[build_backend] Starting editable install...")
127127

128-
# Compile ddbc_bindings for editable installs too
129-
print("[build_backend] Compiling ddbc_bindings for editable install...")
130-
try:
131-
compile_ddbc(verbose=True)
132-
print("[build_backend] Compilation successful!")
133-
except FileNotFoundError:
134-
print("[build_backend] Build scripts not found, assuming pre-compiled binaries")
135-
except (RuntimeError, OSError) as e:
136-
print(f"[build_backend] Compilation failed: {e}")
137-
raise
128+
# Check if we should skip compilation
129+
skip_compile = False
130+
if config_settings:
131+
skip_compile = _is_truthy(config_settings.get("--skip-ddbc-compile", False))
132+
133+
if not skip_compile:
134+
arch = None
135+
coverage = False
136+
137+
if config_settings:
138+
arch = config_settings.get("--arch")
139+
coverage = _is_truthy(config_settings.get("--coverage", False))
140+
141+
print("[build_backend] Compiling ddbc_bindings for editable install...")
142+
try:
143+
compile_ddbc(arch=arch, coverage=coverage, verbose=True)
144+
print("[build_backend] Compilation successful!")
145+
except FileNotFoundError:
146+
print("[build_backend] Build scripts not found, assuming pre-compiled binaries")
147+
except (RuntimeError, OSError) as e:
148+
print(f"[build_backend] Compilation failed: {e}")
149+
raise
150+
else:
151+
print("[build_backend] Skipping ddbc compilation (--skip-ddbc-compile)")
138152

139153
# Import here and handle absence gracefully for older setuptools versions
140154
try:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Platform detection utilities for mssql-python.
33
4-
This module provides platform and architecture detection used by both
5-
the build system (setup.py, build_ddbc) and runtime code.
4+
This module provides platform and architecture detection used by
5+
the build system (setup.py, build_backend).
66
"""
77

88
import glob

build_ddbc/__init__.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

pyproject.toml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# =============================================================================
44
[build-system]
55
requires = ["setuptools>=64.0.0", "wheel", "pybind11"]
6-
build-backend = "build_ddbc.build_backend"
6+
build-backend = "build_backend.hooks"
77
backend-path = ["."]
88

99
# =============================================================================
@@ -48,6 +48,9 @@ Repository = "https://github.com/microsoft/mssql-python"
4848
Issues = "https://github.com/microsoft/mssql-python/issues"
4949
Changelog = "https://github.com/microsoft/mssql-python/blob/main/CHANGELOG.md"
5050

51+
[project.scripts]
52+
build-ddbc = "build_backend.__main__:main"
53+
5154
[project.optional-dependencies]
5255
dev = [
5356
"pytest",
@@ -69,23 +72,8 @@ lint = [
6972
"types-setuptools",
7073
]
7174
all = [
72-
# Dev dependencies
73-
"pytest",
74-
"pytest-cov",
75-
"coverage",
76-
"unittest-xml-reporting",
77-
"psutil",
78-
"pybind11",
79-
"setuptools",
80-
"wheel",
81-
"build",
82-
# Lint dependencies
83-
"black",
84-
"autopep8",
85-
"pylint",
86-
"cpplint",
87-
"mypy",
88-
"types-setuptools",
75+
"mssql-python[dev]",
76+
"mssql-python[lint]",
8977
]
9078

9179
# =============================================================================
@@ -98,7 +86,7 @@ include-package-data = true
9886
[tool.setuptools.packages.find]
9987
where = ["."]
10088
include = ["mssql_python*"]
101-
exclude = ["build_ddbc*", "tests*", "benchmarks*"]
89+
exclude = ["build_backend*", "tests*", "benchmarks*"]
10290

10391
[tool.setuptools.package-data]
10492
mssql_python = [

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Setup script for mssql-python.
33
44
This script handles platform-specific wheel building with correct platform tags.
5-
The native extension compilation is handled by the build_ddbc package.
5+
The native extension compilation is handled by the build_backend package.
66
77
Note: This file is still needed for:
88
1. Platform-specific package discovery (libs/windows, libs/linux, libs/macos)
99
2. Custom wheel platform tags (BinaryDistribution, CustomBdistWheel)
1010
1111
For building:
12-
python -m build_ddbc # Compile ddbc_bindings only
12+
python -m build_backend # Compile ddbc_bindings only
1313
python -m build # Compile + create wheel (recommended)
1414
pip install -e . # Editable install with auto-compile
1515
"""
@@ -20,7 +20,7 @@
2020
from setuptools.dist import Distribution
2121
from wheel.bdist_wheel import bdist_wheel
2222

23-
from mssql_python.platform_utils import get_platform_info
23+
from build_backend.platform_utils import get_platform_info
2424

2525
# =============================================================================
2626
# Platform-Specific Package Discovery

0 commit comments

Comments
 (0)