1313from dbx_patch .models import ApplyPatchesResult , RemovePatchesResult , StatusResult , VerifyResult
1414from dbx_patch .utils .logger import PatchLogger
1515
16+ logger = PatchLogger ()
1617
17- def apply_all_patches (verbose : bool = True , force_refresh : bool = False ) -> ApplyPatchesResult :
18+
19+ def apply_all_patches (force_refresh : bool = False ) -> ApplyPatchesResult :
1820 """Apply all patches to enable editable install imports.
1921
2022 This function applies patches in the correct order:
@@ -25,59 +27,66 @@ def apply_all_patches(verbose: bool = True, force_refresh: bool = False) -> Appl
2527 5. Patch AutoreloadDiscoverabilityHook to allow editable imports
2628
2729 Args:
28- verbose: If True, print detailed status messages (overridden by DBX_PATCH_VERBOSE env var)
2930 force_refresh: If True, force re-detection of editable paths
3031
3132 Returns:
3233 ApplyPatchesResult with complete operation details
3334 """
34- logger = PatchLogger ()
3535 logger .debug ("apply_all_patches() called" )
36- logger .debug (f"verbose= { verbose } , force_refresh={ force_refresh } " )
36+ logger .debug (f"force_refresh={ force_refresh } " )
3737
3838 with logger .section ("DBX-Patch: Applying patches for editable install support" ):
3939 sys_path_init_result = None
4040 pth_result = None
4141 wsfs_result = None
42+ wsfs_path_finder_result = None
4243 path_hook_result = None
4344 autoreload_result = None
4445
4546 # Step 1: Patch sys_path_init to auto-process .pth files
4647 with logger .subsection ("Step 1: Patching sys_path_init..." ):
4748 from dbx_patch .patches .sys_path_init_patch import patch_sys_path_init
4849
49- sys_path_init_result = patch_sys_path_init (verbose = verbose )
50+ sys_path_init_result = patch_sys_path_init ()
5051
5152 # Step 2: Process .pth files immediately
5253 with logger .subsection ("Step 2: Processing .pth files..." ):
5354 from dbx_patch .pth_processor import process_all_pth_files
5455
55- pth_result = process_all_pth_files (force = force_refresh , verbose = verbose )
56+ pth_result = process_all_pth_files (force = force_refresh )
5657
5758 # Step 3: Patch WsfsImportHook
5859 with logger .subsection ("Step 3: Patching WsfsImportHook..." ):
5960 from dbx_patch .patches .wsfs_import_hook_patch import patch_wsfs_import_hook
6061
61- wsfs_result = patch_wsfs_import_hook (verbose = verbose )
62+ wsfs_result = patch_wsfs_import_hook ()
63+
64+ # Step 3b: Verify WsfsPathFinder
65+ with logger .subsection ("Step 3b: Verifying WsfsPathFinder..." ):
66+ from dbx_patch .patches .wsfs_path_finder_patch import patch_wsfs_path_finder
67+
68+ wsfs_path_finder_result = patch_wsfs_path_finder ()
6269
6370 # Step 4: Patch PythonPathHook
6471 with logger .subsection ("Step 4: Patching PythonPathHook..." ):
6572 from dbx_patch .patches .python_path_hook_patch import patch_python_path_hook
6673
67- path_hook_result = patch_python_path_hook (verbose = verbose )
74+ path_hook_result = patch_python_path_hook ()
6875
6976 # Step 5: Patch AutoreloadDiscoverabilityHook
7077 with logger .subsection ("Step 5: Patching AutoreloadDiscoverabilityHook..." ):
7178 from dbx_patch .patches .autoreload_hook_patch import patch_autoreload_hook
7279
73- autoreload_result = patch_autoreload_hook (verbose = verbose )
80+ autoreload_result = patch_autoreload_hook ()
7481
7582 # Collect all editable paths
7683 all_paths = set ()
7784 if pth_result :
7885 all_paths .update (pth_result .paths_extracted )
7986 if wsfs_result :
8087 all_paths .update (wsfs_result .editable_paths )
88+ if wsfs_path_finder_result and hasattr (wsfs_path_finder_result , "editable_paths" ):
89+ all_paths .update (wsfs_path_finder_result .editable_paths )
8190 if path_hook_result :
8291 all_paths .update (path_hook_result .editable_paths )
8392 if autoreload_result :
@@ -89,10 +98,11 @@ def apply_all_patches(verbose: bool = True, force_refresh: bool = False) -> Appl
8998 sys_path_init_success = sys_path_init_result is not None and sys_path_init_result .success
9099 pth_success = pth_result is not None and pth_result .total_editable_paths >= 0
91100 wsfs_success = wsfs_result is not None and wsfs_result .success
101+ wsfs_path_finder_success = wsfs_path_finder_result is not None and wsfs_path_finder_result .success
92102 path_hook_success = path_hook_result is not None and path_hook_result .success
93103 autoreload_success = autoreload_result is not None and autoreload_result .success
94104
95- overall_success = pth_success and (wsfs_success or path_hook_success or autoreload_success )
105+ overall_success = pth_success and (wsfs_success or wsfs_path_finder_success or path_hook_success or autoreload_success )
96106
97107 if overall_success :
98108 logger .success ("All patches applied successfully!" )
@@ -102,55 +112,57 @@ def apply_all_patches(verbose: bool = True, force_refresh: bool = False) -> Appl
102112 logger .warning ("Some patches could not be applied (may be OK if not in Databricks)" )
103113
104114 if all_paths :
105- logger .info (f"\n Total editable install paths found: { len (all_paths )} " )
106- logger .info ("\n Editable paths:" )
115+ logger .blank ()
116+ logger .info (f"Total editable install paths found: { len (all_paths )} " )
117+ logger .blank ()
118+ logger .info ("Editable paths:" )
107119 with logger .indent ():
108120 for path in sorted (all_paths ):
109121 logger .info (f"- { path } " )
110122 else :
111- logger .warning ("\n No editable installs detected." )
123+ logger .blank ()
124+ logger .warning ("No editable installs detected." )
112125 with logger .indent ():
113126 logger .info ("Install packages with: pip install -e /path/to/package" )
114127
115128 return ApplyPatchesResult (
116129 sys_path_init_patch = sys_path_init_result ,
117130 pth_processing = pth_result ,
118131 wsfs_hook_patch = wsfs_result ,
132+ wsfs_path_finder_patch = wsfs_path_finder_result ,
119133 python_path_hook_patch = path_hook_result ,
120134 autoreload_hook_patch = autoreload_result ,
121135 overall_success = overall_success ,
122136 editable_paths = editable_paths ,
123137 )
124138
125139
126- def verify_editable_installs (verbose : bool = True ) -> VerifyResult :
140+ def verify_editable_installs () -> VerifyResult :
127141 """Verify that editable installs are properly configured and can be imported.
128142
129- Args:
130- verbose: If True, print detailed verification results
131-
132143 Returns:
133144 VerifyResult with configuration status
134145 """
135- logger = PatchLogger (verbose = verbose )
136-
137146 with logger .section ("DBX-Patch: Verifying editable install configuration" ):
138147 from dbx_patch .patches .autoreload_hook_patch import is_patched as autoreload_patched
139148 from dbx_patch .patches .python_path_hook_patch import is_patched as path_hook_patched
140149 from dbx_patch .patches .wsfs_import_hook_patch import is_patched as wsfs_patched
150+ from dbx_patch .patches .wsfs_path_finder_patch import is_patched as wsfs_path_finder_patched
141151 from dbx_patch .pth_processor import get_editable_install_paths
142152
143153 editable_paths = get_editable_install_paths ()
144154 paths_in_sys_path = [p for p in editable_paths if p in sys .path ]
145155
146156 wsfs_patched_status = wsfs_patched ()
157+ wsfs_path_finder_patched_status = wsfs_path_finder_patched ()
147158 path_hook_patched_status = path_hook_patched ()
148159 autoreload_patched_status = autoreload_patched ()
149160 status = "ok"
150161
151162 logger .info (f"Editable paths detected: { len (editable_paths )} " )
152163 logger .info (f"Paths in sys.path: { len (paths_in_sys_path )} " )
153164 logger .info (f"WsfsImportHook patched: { wsfs_patched_status } " )
165+ logger .info (f"WsfsPathFinder patched: { wsfs_path_finder_patched_status } " )
154166 logger .info (f"PythonPathHook patched: { path_hook_patched_status } " )
155167 logger .info (f"AutoreloadHook patched: { autoreload_patched_status } " )
156168 logger .blank ()
@@ -189,41 +201,40 @@ def verify_editable_installs(verbose: bool = True) -> VerifyResult:
189201 editable_paths = sorted (editable_paths ),
190202 paths_in_sys_path = sorted (paths_in_sys_path ),
191203 wsfs_hook_patched = wsfs_patched_status ,
204+ wsfs_path_finder_patched = wsfs_path_finder_patched_status ,
192205 python_path_hook_patched = path_hook_patched_status ,
193206 autoreload_hook_patched = autoreload_patched_status ,
194207 importable_packages = [],
195208 status = status ,
196209 )
197210
198211
199- def check_patch_status (verbose : bool = True ) -> StatusResult :
212+ def check_patch_status () -> StatusResult :
200213 """Check the status of all patches without applying them.
201214
202- Args:
203- verbose: If True, print status information
204-
205215 Returns:
206216 StatusResult with current patch status
207217 """
208- logger = PatchLogger (verbose = verbose )
209-
210218 with logger .section ("DBX-Patch Status" ):
211219 from dbx_patch .patches .autoreload_hook_patch import is_patched as autoreload_patched
212220 from dbx_patch .patches .python_path_hook_patch import is_patched as path_hook_patched
213221 from dbx_patch .patches .sys_path_init_patch import is_patched as sys_path_init_patched
214222 from dbx_patch .patches .wsfs_import_hook_patch import is_patched as wsfs_patched
223+ from dbx_patch .patches .wsfs_path_finder_patch import is_patched as wsfs_path_finder_patched
215224 from dbx_patch .pth_processor import get_editable_install_paths
216225
217226 editable_paths = get_editable_install_paths ()
218227 paths_in_sys_path = sum (1 for p in editable_paths if p in sys .path )
219228
220229 sys_init_patched = sys_path_init_patched ()
221230 wsfs_hook_patched = wsfs_patched ()
231+ wsfs_path_finder_patched_status = wsfs_path_finder_patched ()
222232 path_hook_patched_status = path_hook_patched ()
223233 autoreload_patched_status = autoreload_patched ()
224234
225235 logger .info (f"sys_path_init patched: { sys_init_patched } " )
226236 logger .info (f"WsfsImportHook patched: { wsfs_hook_patched } " )
237+ logger .info (f"WsfsPathFinder patched: { wsfs_path_finder_patched_status } " )
227238 logger .info (f"PythonPathHook patched: { path_hook_patched_status } " )
228239 logger .info (f"AutoreloadHook patched: { autoreload_patched_status } " )
229240 logger .info (f"Editable paths detected: { len (editable_paths )} " )
@@ -232,36 +243,34 @@ def check_patch_status(verbose: bool = True) -> StatusResult:
232243 return StatusResult (
233244 sys_path_init_patched = sys_init_patched ,
234245 wsfs_hook_patched = wsfs_hook_patched ,
246+ wsfs_path_finder_patched = wsfs_path_finder_patched_status ,
235247 python_path_hook_patched = path_hook_patched_status ,
236248 autoreload_hook_patched = autoreload_patched_status ,
237249 editable_paths_count = len (editable_paths ),
238250 pth_files_processed = paths_in_sys_path > 0 ,
239251 )
240252
241253
242- def remove_all_patches (verbose : bool = True ) -> RemovePatchesResult :
254+ def remove_all_patches () -> RemovePatchesResult :
243255 """Remove all applied patches and restore original behavior.
244256
245- Args:
246- verbose: If True, print status messages
247-
248257 Returns:
249258 RemovePatchesResult with unpatch operation status
250259 """
251- logger = PatchLogger (verbose = verbose )
252-
253260 with logger .section ("DBX-Patch: Removing all patches" ):
254261 from dbx_patch .patches .autoreload_hook_patch import unpatch_autoreload_hook
255262 from dbx_patch .patches .python_path_hook_patch import unpatch_python_path_hook
256263 from dbx_patch .patches .sys_path_init_patch import unpatch_sys_path_init
257264 from dbx_patch .patches .wsfs_import_hook_patch import unpatch_wsfs_import_hook
265+ from dbx_patch .patches .wsfs_path_finder_patch import unpatch_wsfs_path_finder
258266
259- sys_path_init_result = unpatch_sys_path_init (verbose = verbose )
260- wsfs_result = unpatch_wsfs_import_hook (verbose = verbose )
261- path_hook_result = unpatch_python_path_hook (verbose = verbose )
262- autoreload_result = unpatch_autoreload_hook (verbose = verbose )
267+ sys_path_init_result = unpatch_sys_path_init ()
268+ wsfs_result = unpatch_wsfs_import_hook ()
269+ wsfs_path_finder_result = unpatch_wsfs_path_finder ()
270+ path_hook_result = unpatch_python_path_hook ()
271+ autoreload_result = unpatch_autoreload_hook ()
263272
264- success = sys_path_init_result or wsfs_result or path_hook_result or autoreload_result
273+ success = sys_path_init_result or wsfs_result or wsfs_path_finder_result or path_hook_result or autoreload_result
265274
266275 if success :
267276 logger .success ("Patches removed successfully" )
@@ -271,6 +280,7 @@ def remove_all_patches(verbose: bool = True) -> RemovePatchesResult:
271280 return RemovePatchesResult (
272281 sys_path_init_unpatched = sys_path_init_result ,
273282 wsfs_hook_unpatched = wsfs_result ,
283+ wsfs_path_finder_unpatched = wsfs_path_finder_result ,
274284 python_path_hook_unpatched = path_hook_result ,
275285 autoreload_hook_unpatched = autoreload_result ,
276286 success = success ,
0 commit comments