dbx_patch.patch_dbx
source module dbx_patch.patch_dbx
Main DBX-Patch Entry Point.
This module provides comprehensive methods to patch Databricks runtime for editable install support. Supports both legacy (< 18.0) and modern (>= 18.0) Databricks runtime versions.
Quick usage
from dbx_patch import patch_dbx patch_dbx()
Or for comprehensive setup with auto-patching on restart
from dbx_patch import patch_and_install patch_and_install()
Functions
-
patch_dbx — Apply all DBX patches for editable install support.
-
verify_editable_installs — Verify that editable installs are properly configured and can be imported.
-
check_patch_status — Check the status of all patches without applying them.
-
remove_all_patches — Remove all applied patches and restore original behavior.
-
patch_and_install — Apply patches AND install sitecustomize.py for automatic patching on startup.
source patch_dbx(force_refresh: bool = False) → ApplyPatchesResult
Apply all DBX patches for editable install support.
This is the main entry point that
- Processes .pth files to populate sys.path with editable install paths
- Patches sys_path_init to auto-process .pth files during initialization
- Patches WsfsImportHook to allow imports from editable paths
- Patches PythonPathHook to preserve editable paths
- Patches AutoreloadDiscoverabilityHook to allow editable imports
This method is optimized to avoid import loops and ensures patches are applied in the correct order with proper error handling.
Parameters
-
force_refresh : bool — If True, force re-detection of editable paths
Returns
-
ApplyPatchesResult — ApplyPatchesResult with complete operation details
Example
from dbx_patch import patch_dbx
patch_dbx()
# All patches applied, editable installs now work!
source verify_editable_installs() → VerifyResult
Verify that editable installs are properly configured and can be imported.
Returns
-
VerifyResult — VerifyResult with configuration status
source check_patch_status() → StatusResult
Check the status of all patches without applying them.
Returns
-
StatusResult — StatusResult with current patch status
source remove_all_patches() → RemovePatchesResult
Remove all applied patches and restore original behavior.
Returns
-
RemovePatchesResult — RemovePatchesResult with unpatch operation status
source patch_and_install(force: bool = False, restart_python: bool = True) → dict[str, Any]
Apply patches AND install sitecustomize.py for automatic patching on startup.
This is the recommended all-in-one method that
- Applies all patches immediately (via patch_dbx)
- Installs sitecustomize.py for automatic patching on future Python restarts
- Optionally restarts Python to activate sitecustomize.py
Parameters
-
force : bool — If True, overwrite existing sitecustomize.py
-
restart_python : bool — If True, automatically restart Python via dbutils
Returns
-
dict[str, Any] — Dictionary with 'patch_result' and 'install_result' keys
Example
from dbx_patch import patch_and_install
patch_and_install()
# Patches applied AND sitecustomize.py installed
# Python will restart automatically if in Databricks