dbx_patch.base_patch
source module dbx_patch.base_patch
Base classes for DBX-Patch interface.
Provides abstract base classes and singleton metaclass for all patches.
Classes
-
SingletonMeta — Thread-safe singleton metaclass for patch classes.
-
BasePatch — Abstract base class for all Databricks runtime patches.
-
BaseVerification — Abstract base class for verification-only patches.
source class SingletonMeta()
Bases : ABCMeta
Thread-safe singleton metaclass for patch classes.
Ensures only one instance of each patch class exists, with thread-safe creation in notebook environments. Inherits from ABCMeta to support ABC.
Methods
-
reset_instance — Reset singleton instance for testing.
source classmethod SingletonMeta.reset_instance(cls: type) → None
Reset singleton instance for testing.
Parameters
-
cls : type — The class whose singleton instance should be reset
source class BasePatch(verbose: bool = True)
Abstract base class for all Databricks runtime patches.
Provides a unified interface for applying, removing, and checking patch status. All patches follow the singleton pattern to ensure consistent global state.
Initialize the patch (called only once due to singleton).
Attributes
-
_is_applied : bool — Whether the patch has been applied
-
_original_target : Any — Reference to original function/method for restoration
-
_cached_editable_paths : set[str] — Set of cached editable install paths (if applicable)
-
_logger : Any — Cached logger instance
Parameters
-
verbose : bool — Enable verbose logging
Methods
-
patch — Apply the patch to the Databricks runtime.
-
remove — Remove the patch and restore original behavior.
-
is_applied — Check if the patch is currently applied.
-
refresh_paths — Refresh cached editable install paths (optional, override if needed).
-
get_editable_paths — Get current cached editable paths (optional, override if needed).
-
reset — Reset the singleton instance for testing purposes.
source method BasePatch.patch() → PatchResult
Apply the patch to the Databricks runtime.
This method should
- Check if already applied (return early if so)
- Verify target modules/functions exist
- Apply the patch (monkey-patch, wrap, register, etc.)
- Update internal state (_is_applied, _original_target, etc.)
- Return PatchResult with operation details
Returns
-
PatchResult — PatchResult indicating success/failure and details
source method BasePatch.remove() → bool
Remove the patch and restore original behavior.
This method should
- Check if patch is applied (return early if not)
- Restore original functions/methods from _original_target
- Clean up any registered callbacks or hooks
- Reset internal state (_is_applied = False, etc.)
- Return True if successful, False otherwise
Returns
-
bool — True if patch was removed successfully, False otherwise
source method BasePatch.is_applied() → bool
Check if the patch is currently applied.
Returns
-
bool — True if patch is applied, False otherwise
source method BasePatch.refresh_paths() → int
Refresh cached editable install paths (optional, override if needed).
Returns
-
int — Number of editable paths detected
source method BasePatch.get_editable_paths() → set[str]
Get current cached editable paths (optional, override if needed).
Returns
-
set[str] — Set of editable install paths
source classmethod BasePatch.reset() → None
Reset the singleton instance for testing purposes.
source class BaseVerification(verbose: bool = True)
Abstract base class for verification-only patches.
Verification patches don't modify runtime behavior - they only check compatibility and report findings.
Initialize the verification (called only once due to singleton).
Attributes
-
_is_verified : bool — Whether verification has been performed
-
_logger : Any — Cached logger instance
Parameters
-
verbose : bool — Enable verbose logging
Methods
-
verify — Verify compatibility with Databricks runtime.
-
is_verified — Check if verification has been performed.
-
reset — Reset the singleton instance for testing purposes.
source method BaseVerification.verify() → PatchResult
Verify compatibility with Databricks runtime.
This method should
- Check if already verified (return early if so)
- Import and inspect target modules/hooks
- Verify they won't interfere with editable installs
- Update internal state (_is_verified = True)
- Return PatchResult with verification details
Returns
-
PatchResult — PatchResult indicating compatibility status
source method BaseVerification.is_verified() → bool
Check if verification has been performed.
Returns
-
bool — True if verified, False otherwise
source classmethod BaseVerification.reset() → None
Reset the singleton instance for testing purposes.