Skip to content

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

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

  1. Check if already applied (return early if so)
  2. Verify target modules/functions exist
  3. Apply the patch (monkey-patch, wrap, register, etc.)
  4. Update internal state (_is_applied, _original_target, etc.)
  5. 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

  1. Check if patch is applied (return early if not)
  2. Restore original functions/methods from _original_target
  3. Clean up any registered callbacks or hooks
  4. Reset internal state (_is_applied = False, etc.)
  5. 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

  1. Check if already verified (return early if so)
  2. Import and inspect target modules/hooks
  3. Verify they won't interfere with editable installs
  4. Update internal state (_is_verified = True)
  5. 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.