4848from suby .process_waiting import has_event_driven_wait , wait_for_process_exit
4949from suby .subprocess_result import SubprocessResult
5050
51- StreamCallback = Callable [[str ], Any ] # type: ignore[misc]
51+ StreamCallback = Callable [[str ], Any ] # type: ignore[misc, unused-ignore ]
5252_CUSTOM_TOKEN_POLL_TIMEOUT_SECONDS = 0.0001
5353_CANCELLATION_ERROR_TYPES : Mapping [Type [CancellationError ], Type [CancellationError ]] = {
5454 CantokConditionCancellationError : ConditionCancellationError ,
@@ -287,6 +287,8 @@ def prepare_directory(directory: Optional[Union[str, Path]]) -> Optional[str]:
287287 try :
288288 directory_stat = cwd_path .stat ()
289289 except FileNotFoundError as error :
290+ if has_file_parent (cwd_path ):
291+ raise WrongDirectoryError (f'The directory { raw_text !r} cannot be resolved because an intermediate component is not a directory.' ) from error
290292 raise WrongDirectoryError (f'The directory { raw_text !r} does not exist.' ) from error
291293 except NotADirectoryError as error :
292294 raise WrongDirectoryError (f'The directory { raw_text !r} cannot be resolved because an intermediate component is not a directory.' ) from error
@@ -303,6 +305,16 @@ def prepare_directory(directory: Optional[Union[str, Path]]) -> Optional[str]:
303305 return str (cwd_path )
304306
305307
308+ def has_file_parent (path : Path ) -> bool :
309+ for parent in path .parents :
310+ try :
311+ parent_stat = parent .stat ()
312+ except OSError :
313+ continue
314+ return not stat .S_ISDIR (parent_stat .st_mode )
315+ return False
316+
317+
306318def build_subprocess_env (
307319 env : Optional [Mapping [str , str ]],
308320 add_env : Optional [Mapping [str , str ]],
0 commit comments