
    h                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJrJrJr  SSKJr  \S\\\	4   S\\	   4S	 j5       r\S\\	SS4   4S
 j5       rS\\	\4   S\4S jrS\S\4S jrS rS rg)    N)contextmanager)Path)Any	GeneratorIteratorUnion   )Warningspathreturnc              #   6  #    [         R                  " 5       n[        U 5      R                  5       n[        R                  " [        U5      5         Uv   [        R                  " [        U5      5        g! [        R                  " [        U5      5        f = f7f)aB  Change current working directory and returns to previous on exit.

path (str / Path): The directory to navigate to.
YIELDS (Path): The absolute path to the current working directory. This
    should be used if the block needs to perform actions within the working
    directory, to prevent mismatches with relative paths.
N)r   cwdresolveoschdirstr)r   prev_cwdcurrents      P/home/james-whalen/.local/lib/python3.13/site-packages/weasel/util/filesystem.pyworking_dirr      s^      xxzH4j  "GHHS\ 
XXs   ABA5  B5!BBc               #     #    [        [        R                  " 5       5      n U v   S n [        R                  S:  a  [
        R                  " [        U 5      US9  g[
        R                  " [        U 5      US9  g! [         a;  n[        R                  " [        R                  R                  XS95         SnAgSnAff = f7f)zExecute a block in a temporary directory and remove the directory and
its contents at the end of the with block.

YIELDS (Path): The path of the temp directory.
c                 ^    [         R                  " U[        R                  5        U " U5        g )N)r   chmodstatS_IWRITE)rmfuncr   exs      r   force_remove"make_tempdir.<locals>.force_remove,   s    
t}}%t    )      )onexc)onerror)dirmsgN)r   tempfilemkdtempsysversion_infoshutilrmtreer   PermissionErrorwarningswarnr
   W801format)dr   es      r   make_tempdirr4       s      	X A
G:w&MM#a&5MM#a&,7 :hmm**q*899:s:   &C2A; CA; :C;
C 1B;6C;C  Cc                     [        [        U 5      R                  5       5      R                  5       [        [        R                  " 5       R                  5       5      R                  5       :H  $ )zCheck whether a path is the current working directory.

path (Union[Path, str]): The directory path.
RETURNS (bool): Whether the path is the current working directory.
)r   r   r   lowerr   r   s    r   is_cwdr8   9   sG     tDz!!#$**,DHHJ4F4F4H0I0O0O0QQQr    c                 F    [        U [        5      (       a  [        U 5      $ U $ )zEnsure string is converted to a Path.

path (Any): Anything. If string, it's converted to Path.
RETURNS: Path or original argument.
)
isinstancer   r   r7   s    r   ensure_pathr;   B   s      $Dzr    c                     SSK Jn  U" U 5      $ )zTemporary helper to prevent importing cloudpathlib globally (which was
originally added due to a slow and annoying Google Cloud warning with
Pathy)r   )AnyPath)cloudpathlibr=   )r   r=   s     r   ensure_pathyr?   N   s     %4=r    c                     [         R                  R                  U 5      n[         R                  R                  U5      n[         R                  R                  X#/5      U:H  $ )z<
Check whether `child` is a path contained within `parent`.
)r   r   realpath
commonpath)parentchildparent_realpathchild_realpaths       r   is_subpath_ofrG   W   sI     gg&&v.OWW%%e,N77?@OSSr    )r   r+   r   r)   r'   r.   
contextlibr   pathlibr   typingr   r   r   r   errorsr
   r   r   r4   boolr8   r;   r?   rG    r    r   <module>rN      s    	   
   %  2 2   eCI&  8D>    " :idD 01 : :0RtSy! Rd R	c 	c 	
Tr    