Skip to content

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

  1. Processes .pth files to populate sys.path with editable install paths
  2. Patches sys_path_init to auto-process .pth files during initialization
  3. Patches WsfsImportHook to allow imports from editable paths
  4. Patches PythonPathHook to preserve editable paths
  5. 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

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

source check_patch_status()StatusResult

Check the status of all patches without applying them.

Returns

source remove_all_patches()RemovePatchesResult

Remove all applied patches and restore original behavior.

Returns

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

  1. Applies all patches immediately (via patch_dbx)
  2. Installs sitecustomize.py for automatic patching on future Python restarts
  3. 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